pulsar-client-node icon indicating copy to clipboard operation
pulsar-client-node copied to clipboard

Improve Timing of Promise "then"

Open k2la opened this issue 5 years ago • 0 comments

Currently, To measure latency of sending messages, asynchronous processing using Nodejs Promise like following code:

    const results = [];
    for (let mi = 0; mi < numOfMessages; mi += 1) {
      const startSendTimeMilliSeconds = performance.now();
      results.push(producer.send({
        data: message,
      }).then(() => {
        // add latency
        histogram.recordValue((performance.now() - startSendTimeMilliSeconds));
      }));
    }
    await Promise.all(results); // wait until all messages are sent.

https://github.com/apache/pulsar-client-node/blob/master/perf/perf_producer.js#L88-L98

This code creates histogram about latency of sending messages. However, all then() of Promise in results start after await Promise.all(results). So, We cannot get accurate histogram.

k2la avatar Mar 14 '19 06:03 k2la