'Why the Azure Event Hub get events so slow?
Event Hub is fast to send but slow to get. I use next code:
subscribe(cb: (event: any) => Promise<void>) {
this.consumerClient.subscribe(
this.config.partitionId,
{
processEvents: async (events: any, context: any) => {
if (events.length === 0) {
return;
}
for (const event of events) {
await cb(event.body);
}
await context.updateCheckpoint(events[events.length - 1]);
},
processError: async (err, context: any) => {
console.error(`Event Hub Subscribe Error`, { err, context });
},
},
{ startPosition: earliestEventPosition },
);
}
It takes about 1 minute to get 100 events. The await cb(event.body);
works fast.
Solution 1:[1]
The issue must be from the source side, not in Event Hub since it is sending the data at expected speed.
Here are some recommendations in the light of the performance and throughput results:
- If events do not naturally comes in batch of many events: simply stream events. Do not try to batch them unless network IO is constrained.
- If a latency of 0.1 seconds is a concern: move the call to Event Hubs away from your critical performance path.
Refer Performance and scale for Event Hubs and Azure Functions to know more on how the performance can be improved.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | UtkarshPal-MT |