如何提高EventProcessorHost的接收性能?

时间:2019-08-29 06:05:20

标签: c# azure-eventhub

我不知道如何提高EventHub的接收性能。现在,我正在使用eventprocessorHost接收数据,并且代码几乎是eventhub文档的演示,我已经设置了options.MaxBatchSize来改善该性能,但它不能满足性能要求。 因此,我想知道是否还有其他eventhub api可以增强性能?

namespace RecieveFrom
{    
    class Program
    {
        static void Main(string[] args)
        {
            MainAsync(args).GetAwaiter().GetResult();
        }
        private static async Task MainAsync(string[] args)
        {
            Console.WriteLine("Registering EventProcessor...");
            string _guid = Guid.NewGuid().ToString();
            string eventProcessorHostName = _guid;//lease id
            string leasename = eventProcessorHostName = _guid;//lease id
            var eventProcessorHost = new EventProcessorHost(
                eventProcessorHostName,
                EventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                EventHubConnectionString,
                StorageConnectionString,
                leasename);
            //options 
            var options = new EventProcessorOptions
            {
                InitialOffsetProvider = (partitonId) => EventPosition.FromEnqueuedTime(DateTime.UtcNow - new TimeSpan(0, 2, 0))
            };
            options.MaxBatchSize = 10000;
            options.PrefetchCount = 3000;
         eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options);
            Console.WriteLine("Receiving. Press ENTER to stop worker.");
            Console.ReadLine();
// Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
//class for data rec
        public class SimpleEventProcessor : IEventProcessor
        {
            public Task CloseAsync(PartitionContext context, Microsoft.Azure.EventHubs.Processor.CloseReason reason)
            {
                Console.WriteLine($"Processor Shutting Down. Partition '{context.PartitionId}', Reason: '{reason}'.");
                return Task.CompletedTask;
            }
           public Task OpenAsync(PartitionContext context)
            {
                Console.WriteLine($"SimpleEventProcessor initialized. Partition: '{context.PartitionId}'");
                return Task.CompletedTask;
            }
           public Task ProcessErrorAsync(PartitionContext context, Exception error)
            {
                Console.WriteLine($"Error on Partition: {context.PartitionId}, Error: {error.Message}");
                return Task.CompletedTask;
            }
//process data
            public Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
            {
                foreach (var eventData in messages)
                {
                    //get data 
                    var data = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
                }
            }
        }
    }
}```

I expect the performance to be 100,000 rows/min.

1 个答案:

答案 0 :(得分:0)

查看官方的最佳做法指南-Microsoft Docs

由于您已要求进行处理

  

我希望性能为100,000行/分钟。

也请检出this

我发现以下博客也有助于性能测试。您也可以检查它们