timing of async calls

63 views
Skip to first unread message

Reza Razavipour

unread,
Jun 4, 2014, 2:06:35 PM6/4/14
to nod...@googlegroups.com
my RESTful server has to make a ton of SOAP calls to a Web service and I want to measure how each of these SOAP call take.
How do I do that precisely?


Samuel Erdtman

unread,
Jun 5, 2014, 1:32:28 AM6/5/14
to nod...@googlegroups.com
Could you give an example on how the set of calls are made?

Then it would be easier help you with a suggestion.

Best Regards
//Samuel

greelgorke

unread,
Jun 5, 2014, 3:07:19 AM6/5/14
to nod...@googlegroups.com
simplest thing is to use http://nodejs.org/api/console.html#console_console_time_label which resolution is a milisec


On Wednesday, June 4, 2014 8:06:35 PM UTC+2, Reza Razavipour wrote:

Floby

unread,
Jun 5, 2014, 4:19:39 AM6/5/14
to nod...@googlegroups.com
var start = Date.now()

makeSoapCall(function (err) {
  var end = Date.now();
  console.log("SOAP call took %d milliseconds", end - start);
});

This should do it.

Forrest Norvell

unread,
Jun 5, 2014, 4:42:52 AM6/5/14
to nod...@googlegroups.com

Or, assuming you’re using Node 0.8 or newer (which you should be):

var start = process.hrtime();

makeSoapCall(function (err) {
  var duration = process.hrtime(start);
  console.error("SOAP call took %s milliseconds", (duration[0] * 1e9 + duration[1]) / 1e6);
});

In general, process.hrtime() will be much more accurate than new Date(). If you want aggregated metrics for your HTTP / SOAP calls over time, look at metrics-gathering agent like New Relic, AppDynamics / Nodetime, or StrongLoop’s StrongOps. You could write all the code yourself, but as someone who’s done it, it’s kind of a pain to do yourself, even if the results are much more useful than a list of request times printed to stderr / stdout.

F

Reply all
Reply to author
Forward
0 new messages