Monday, 23 April, 2018 UTC


Summary

  • When your backend code is calling external APIs you may want to measure particular request time to identify bottlenecks.
  • The most straight forward, but incorrect, way to measure how long request takes is to use JavaScript object: – – However, this won’t give you the actual time that request takes.
  • Above request call is async, and you start measuring time at the time when request was queued, not actually sent.
  • In order to determine how much time elapsed since sending request, you can use the parameter: – – You can also compare results returned by both methods: – – When I run it, I got the following results: – – The actual time elapsed: 72 – – Time elapsed since…
  • Depending on your server side code, this difference might be even larger, and give you incorrect hints while you are profiling your application.
Jacob Jedryszek is a Software Engineer who started and shipped Azure Mobile app, and helped Microsoft to build and ship the Azure Management Portal. He is also a speaker at conferences around the World.
@NodejsFramework: Properly Measuring HTTP Request Time with Node: #node #nodejs…
When your backend code is calling external APIs you may want to measure particular request time to identify bottlenecks.
object:
var request = require(‘request’); let start_time = new Date().getTime(); request.get(‘https://google.com’, function (err, response) { console.log(‘Time elapsed:’, new Date().getTime() – start_time); });
However, this won’t give you the actual time that request takes. Above request call is async, and you start measuring time at the time when request was queued, not actually sent.
parameter:
var request = require(‘request’); request.get({ url: ‘http://www.google.com’, time: true }, function (err, response) { console.log(‘The actual time elapsed:’, response.elapsedTime); });
You can also compare results returned by both methods:
When I run it, I got the following results:
The difference is almost 2x. Depending on your server side code, this difference might be even larger, and give you incorrect hints while you are profiling your application.
Properly measuring HTTP request time with node.js