apache / apache/pulsar-client-node
Improve Timing of Promise "then"
- Dominant language
- C++
- Stars
- 164
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
Currently, To measure latency of sending messages, asynchronous processing using Nodejs [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with perf/perf_producer.js around lines 88-98 and review how producer.send() promises and Promise.all() are used. Verify when each then() callback runs relative to Promise.all(), then make the latency histogram reflect the actual message-send timing and confirm the performance script still completes correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100