Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST API measuring server-side response times (performance).

I developed some rest APIs based nodejs, I want to test the performance of the APIs. Is any tool can easily count the time of each API call?

Or how to implement measuring of time required for REST API to response on requests.

like image 667
ldlchina Avatar asked Jul 16 '13 13:07

ldlchina


People also ask

How do I monitor REST API performance?

In this section, you can learn how to monitor your API by using CloudWatch metrics, CloudWatch Logs, Kinesis Data Firehose, and AWS X-Ray. By combining CloudWatch execution logs and CloudWatch metrics, you can log errors and execution traces, and monitor your API's performance.

What is a good response time for a rest API?

Generally, APIs that are considered high-performing have an average response time between 0.1 and one second. At this speed, end users will likely not experience any interruption. At around one to two seconds, users begin to notice some delay.


1 Answers

Here is example of how to make event injection with precise time measuring using express.js.

Add this before 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 start time of each request, and will trigger finish after response is sent to client.
Thanks for user419127 pointing to 'finish' event

like image 118
moka Avatar answered Sep 28 '22 18:09

moka