pulsar-client-node
pulsar-client-node copied to clipboard
Improve Timing of Promise "then"
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.