public async Task PublishInParallelAsync() { QueueName = "CookedRabbit.Benchmark"; // Configured for performance. var seasoning = new RabbitSeasoning { ThrottleFastBodyLoops = false, ThrowExceptions = false, WriteErrorsToConsole = false, WriteErrorsToILogger = false, BatchBreakOnException = true }; seasoning.PoolSettings.EnableAutoScaling = true; seasoning.PoolSettings.EmptyPoolWaitTime = 0; seasoning.PoolSettings.WriteSleepNoticeToConsole = false; seasoning.PoolSettings.ConnectionPoolCount = 8; seasoning.PoolSettings.ChannelPoolCount = 32; var channelPool = await Factories.CreateRabbitChannelPoolAsync(seasoning).ConfigureAwait(false); _deliveryService = new RabbitDeliveryService(seasoning, channelPool); _topologyService = new RabbitTopologyService(seasoning, channelPool); _maintenanceService = new RabbitMaintenanceService(seasoning, channelPool); var queueNames = new List <string> { $"{QueueName}.Scaling_00", $"{QueueName}.Scaling_01", $"{QueueName}.Scaling_02", $"{QueueName}.Scaling_03", $"{QueueName}.Scaling_04", $"{QueueName}.Scaling_05", $"{QueueName}.Scaling_06", $"{QueueName}.Scaling_07", $"{QueueName}.Scaling_08", $"{QueueName}.Scaling_09", }; var envelopes = await CreateEnvelopesAsync(queueNames, MessagesToSend, MessageSizes).ConfigureAwait(false); foreach (string queueName in queueNames) { await _topologyService.QueueDeclareAsync(queueName).ConfigureAwait(false); await _maintenanceService.PurgeQueueAsync(queueName).ConfigureAwait(false); } await _deliveryService.PublishInParallelAsync(envelopes).ConfigureAwait(false); }
public static async Task PublishInParallelAsync() { // Configured for performance. var seasoning = new RabbitSeasoning { ThrottleFastBodyLoops = false, ThrowExceptions = false, WriteErrorsToConsole = false, WriteErrorsToILogger = false, BatchBreakOnException = true }; seasoning.PoolSettings.EnableAutoScaling = true; seasoning.PoolSettings.EmptyPoolWaitTime = 0; seasoning.PoolSettings.WriteSleepNoticeToConsole = false; seasoning.PoolSettings.ConnectionPoolCount = 10; seasoning.PoolSettings.ChannelPoolCount = 40; await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating RabbitChannelPool and RabbitServices...").ConfigureAwait(false); var sw = Stopwatch.StartNew(); var channelPool = await Factories.CreateRabbitChannelPoolAsync(seasoning).ConfigureAwait(false); var deliveryService = new RabbitDeliveryService(seasoning, channelPool); var topologyService = new RabbitTopologyService(seasoning, channelPool); var maintenanceService = new RabbitMaintenanceService(seasoning, channelPool); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating RabbitChannelPool and RabbitServices finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating test data...").ConfigureAwait(false); sw.Reset(); sw.Start(); var queueNames = new List <string> { $"{QueueName}.Scaling_00", $"{QueueName}.Scaling_01", $"{QueueName}.Scaling_02", $"{QueueName}.Scaling_03", $"{QueueName}.Scaling_04", $"{QueueName}.Scaling_05", $"{QueueName}.Scaling_06", $"{QueueName}.Scaling_07", $"{QueueName}.Scaling_08", $"{QueueName}.Scaling_09", }; var envelopes = await CreateEnvelopesAsync(queueNames, MessagesToSend, MessageSizes).ConfigureAwait(false); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating test data finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating and/or Purging benchmark queues...").ConfigureAwait(false); sw.Reset(); sw.Start(); foreach (string queueName in queueNames) { await topologyService.QueueDeclareAsync(queueName).ConfigureAwait(false); await maintenanceService.PurgeQueueAsync(queueName).ConfigureAwait(false); } sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Creating and/or Purging finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Publish test starting...").ConfigureAwait(false); sw.Reset(); sw.Start(); await deliveryService.PublishInParallelAsync(envelopes).ConfigureAwait(false); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Publish finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Publish rate {(MessagesToSend/1.0 / (sw.ElapsedMilliseconds / 1000.0)).ToString("0.###")} msg/s").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Purging benchmark queues...").ConfigureAwait(false); sw.Reset(); sw.Start(); foreach (string queueName in queueNames) { await topologyService.QueueDeclareAsync(queueName).ConfigureAwait(false); await maintenanceService.PurgeQueueAsync(queueName).ConfigureAwait(false); } sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Purging finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Shutting down/disposing of services...").ConfigureAwait(false); sw.Reset(); sw.Start(); deliveryService.Dispose(); topologyService.Dispose(); maintenanceService.Dispose(); sw.Stop(); await Console.Out.WriteLineAsync($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}: Shutting down/disposing of services finished. Time: {sw.ElapsedMilliseconds} ms").ConfigureAwait(false); }