【问题标题】:Why the Azure Event Hub get events so slow?为什么 Azure 事件中心获取事件的速度如此之慢?
【发布时间】:2023-02-16 15:32:33
【问题描述】:

事件中心发送速度快但获取速度慢。我使用下一个代码:

    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 },
        );
    }

获取 100 个事件大约需要 1 分钟。 await cb(event.body); 工作很快。

【问题讨论】:

标签: node.js azure express azure-eventhub


【解决方案1】:

问题必须来自源端,而不是事件中心,因为它以预期的速度发送数据。

以下是根据性能和吞吐量结果提出的一些建议:

  • 如果事件不是自然而然地出现在许多事件的批次中:简单地 流事件。不要尝试对它们进行批处理,除非网络 IO 是 约束。
  • 如果 0.1 秒的延迟是一个问题:将调用移至 Event 远离关键性能路径的集线器。

请参考Performance and scale for Event Hubs and Azure Functions 了解更多关于如何提高性能的信息。

【讨论】:

    【解决方案2】:

    您可以在订阅选项中使用“maxBatchSize”和“maxWaitTimeInSeconds”:

    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,
                 maxBatchSize: 50,
                 maxWaitTimeInSeconds: 1
            }
        );
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 1970-01-01
      • 2019-08-17
      • 2021-12-31
      • 2021-11-21
      • 2022-10-16
      • 2022-11-04
      • 2012-03-02
      • 1970-01-01
      相关资源
      最近更新 更多