REST API measuring server response time (performance).

I have developed several nodejs nodes based on holiday APIs, I want to test the performance of the APIs. Can any tool easily count the time of each API call?

Or how to implement the measurement of the time it takes the REST API to respond to requests.

+6
source share
3 answers

Here is an example of how to make event injection an accurate time measurement using express.js.

Add this in front of your routes:

app.all('*', function(req, res, next) { var start = process.hrtime(); // event triggers when express is done sending response res.on('finish', function() { var hrtime = process.hrtime(start); var elapsed = parseFloat(hrtime[0] + (hrtime[1] / 1000000).toFixed(3), 10); console.log(elapsed + 'ms'); }); next(); }); 

It will save the start time of each request and call finish after sending a response to the client.
Thanks for user419127, pointing to the "finish" event

+3
source

How about a performance measurement tool like Apache JMeter . You can easily use it to simulate the (heavy) load on your server, and then to measure response time and other performance indicators. It provides several graphical representations for this.

This blog post shows how you can tune the HTTP performance test for the Web API. I do this in order to test my RESTful web services.

0
source

Just use console.time('timerName'); console.timeEnd('timerName') in Node. "timerName" is obviously configurable.

Example:

console.time('getCustomers'); console.timeEnd('getCustomers')

Output:

getCustomers: 58ms

0
source

Source: https://habr.com/ru/post/949566/


All Articles