Exemplo n.º 1
0
        private async Task Run(string[] args)
        {
            var host  = ConfigurationManager.AppSettings["rabbit.host"];
            var user  = ConfigurationManager.AppSettings["rabbit.admuser"];
            var pwd   = ConfigurationManager.AppSettings["rabbit.admpwd"];
            var vhost = ConfigurationManager.AppSettings["rabbit.vhost"];

            LogAdapter.LogDebugFn              = (s, s1, arg3) => { };
            LogAdapter.ExtendedLogEnabled      = false;
            LogAdapter.ProtocolLevelLogEnabled = false;

            _hdrHistogram = new LongHistogram(1, 1000 * 10, 5);

            int  howManyQueues        = 10;
            bool exclusiveConnections = ConfigurationManager.AppSettings["exclusiveConnections"] == "true";
            bool useOfficialClient    = ConfigurationManager.AppSettings["useOfficialClient"] == "true";

            if (useOfficialClient)
            {
                RabbitMQ.Client.IConnection conn    = null;
                RabbitMQ.Client.IModel      channel = null;

                for (int i = 0; i < howManyQueues; i++)
                {
                    var connFac = new RabbitMQ.Client.ConnectionFactory()
                    {
                        HostName = host, UserName = user, Password = pwd, VirtualHost = vhost, AutomaticRecoveryEnabled = false
                    };

                    if (exclusiveConnections || conn == null)
                    {
                        conn    = connFac.CreateConnection();
                        channel = conn.CreateModel();
                        channel.BasicQos(0, 300, false);
                    }

                    var q = "q." + i;
                    channel.QueueDeclareNoWait(q, durable: true, exclusive: false, autoDelete: false, arguments: null);

                    channel.BasicConsume(q, false, "con_" + q, arguments: null, consumer: new Consumer(channel));
                }
            }
            else
            {
                RabbitMqNext.IConnection conn    = null;
                RabbitMqNext.IChannel    channel = null;

                for (int i = 0; i < howManyQueues; i++)
                {
                    if (exclusiveConnections || conn == null)
                    {
                        conn = await RabbitMqNext.ConnectionFactory.Connect(host, vhost, user, pwd, recoverySettings : null, connectionName : "mod_perf_server");

                        channel = await conn.CreateChannel();

                        await channel.BasicQos(0, 300, false);
                    }

                    var q = "q." + i;

                    await channel.QueueDeclare(q, passive : false, durable : true, exclusive : false, autoDelete : false, arguments : null,
                                               waitConfirmation : false);

                    // TODO: test with parallel buffer copy + serialized too
                    await channel.BasicConsume(ConsumeMode.SerializedWithBufferCopy, BuildConsumerFn(channel), q, "consumer_" + q,
                                               false, true, arguments : null, waitConfirmation : false);
                }
            }

            Console.WriteLine("Consuming..");

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Console.WriteLine("Done\r\n");
                Console.WriteLine("howManyQueues {0} exclusive Connections: {1} official client: {2} count {3}", howManyQueues, exclusiveConnections, useOfficialClient, _hdrHistogram.TotalCount);
                Console.WriteLine("\r\n");

                _hdrHistogram.OutputPercentileDistribution(Console.Out);

                Console.ReadKey();
            };

            await Task.Delay(1);

            Thread.CurrentThread.Join();
        }
Exemplo n.º 2
0
        private async Task Run(string[] args)
        {
            //
            // client side
            // sends rpc requests, measures the roundtrip
            //

            LogAdapter.ExtendedLogEnabled      = false;
            LogAdapter.ProtocolLevelLogEnabled = false;
            LogAdapter.LogDebugFn = (s, s1, arg3) => { };

            _hdrHistogram = new LongHistogram(1, 1000 * 10, 5);

            var host  = ConfigurationManager.AppSettings["rabbit.host"];
            var user  = ConfigurationManager.AppSettings["rabbit.admuser"];
            var pwd   = ConfigurationManager.AppSettings["rabbit.admpwd"];
            var vhost = ConfigurationManager.AppSettings["rabbit.vhost"];

            var postWarmupDelay = TimeSpan.FromSeconds(5);

            int  howManyQueues        = 1;
            bool exclusiveConnections = ConfigurationManager.AppSettings["exclusiveConnections"] == "true";
            bool useOfficialClient    = ConfigurationManager.AppSettings["useOfficialClient"] == "true";

            var howManyCalls = 50000;

//			var howManyCalls = 100;
            _completionSemaphore = new CountdownEvent(howManyQueues);
            _startSync           = new ManualResetEventSlim(false);

//			if (useOfficialClient)
//			{
//				// Warm up
//				{
//					var connFac = new RabbitMQ.Client.ConnectionFactory()
//					{
//						HostName = host,
//						UserName = user,
//						Password = pwd,
//						VirtualHost = vhost,
//						AutomaticRecoveryEnabled = false
//					};
//					var conn2 = connFac.CreateConnection();
//					var channel2 = conn2.CreateModel();
//					var q = "q." + 0;
//					SendLegacyCalls(q, channel2, howManyCalls/4, isWarmUp: true);
//					channel2.Dispose();
//					conn2.Dispose();
//				}
//
//				await WarmupComplete(postWarmupDelay);
//
//				RabbitMQ.Client.IConnection conn = null;
//				RabbitMQ.Client.IModel channel = null;
//
//				for (int i = 0; i < howManyQueues; i++)
//				{
//					var connFac = new RabbitMQ.Client.ConnectionFactory()
//					{
//						HostName = host,
//						UserName = user,
//						Password = pwd,
//						VirtualHost = vhost,
//						AutomaticRecoveryEnabled = false
//					};
//
//					if (exclusiveConnections || conn == null)
//					{
//						conn = connFac.CreateConnection();
//						channel = conn.CreateModel();
//					}
//
//					var q = "q." + i;
//
//					new Thread(() =>
//					{
//						SendLegacyCalls(q, channel, howManyCalls, isWarmUp: false);
//					}) {IsBackground = true}.Start();
//
//				}
//			}
//			else
            {
                RabbitMqNext.LogAdapter.LogErrorFn = (scope, message, exc) =>
                {
                    Console.WriteLine("[Error] " + scope + " - " + message + " exception " + exc);
                };
                RabbitMqNext.LogAdapter.LogWarnFn = (scope, message, exc) =>
                {
                    Console.WriteLine("[Warn] " + scope + " - " + message + " exception " + exc);
                };
                RabbitMqNext.LogAdapter.LogDebugFn = (scope, message, exc) =>
                {
                    Console.WriteLine("[Dbg] " + scope + " - " + message + " exception " + exc);
                };

                // Warm up
//				{
//					var conn2 =
//						await
//							RabbitMqNext.ConnectionFactory.Connect(host, vhost, user, pwd, recoverySettings: null,
//								connectionName: "perf_client");
//
//					var channel2 = await conn2.CreateChannel();
//					var q = "q." + 0;
//					await Task.Delay(1); // Thread switch
//					await SendModernCalls(q, channel2, howManyCalls/4, isWarmUp: true);
//					await Task.Delay(1); // Thread switch
//					channel2.Dispose();
//					conn2.Dispose();
//				}
//
//				await WarmupComplete(postWarmupDelay);

                Console.WriteLine("Will initiate...");

                RabbitMqNext.IConnection conn    = null;
                RabbitMqNext.IChannel    channel = null;

                for (int i = 0; i < howManyQueues; i++)
                {
                    if (exclusiveConnections || conn == null)
                    {
                        conn =
                            await
                            RabbitMqNext.ConnectionFactory.Connect(host, vhost, user, pwd, recoverySettings : null,
                                                                   connectionName : "perf_client");

                        channel = await conn.CreateChannel();
                    }

                    var q = "q." + i;

                    new Thread(async() =>
                    {
                        await SendModernCalls(q, channel, howManyCalls, isWarmUp: false);
                    })
                    {
                        IsBackground = true
                    }.Start();
                }
            }

            _startSync.Set();

            Console.WriteLine("Waiting completion");

            await Task.Delay(1);             // switch

            _completionSemaphore.Wait();

            Console.WriteLine("Done\r\n");
            Console.WriteLine("howManyQueues {0} exclusive Connections: {1} official client: {2} count {3}", howManyQueues,
                              exclusiveConnections, useOfficialClient, _hdrHistogram.TotalCount);
            Console.WriteLine("\r\n");

            _hdrHistogram.OutputPercentileDistribution(Console.Out);

            Console.ReadKey();
        }
Exemplo n.º 3
0
        private async Task Run(string[] args)
        {
            var host  = ConfigurationManager.AppSettings["rabbit.host"];
            var user  = ConfigurationManager.AppSettings["rabbit.admuser"];
            var pwd   = ConfigurationManager.AppSettings["rabbit.admpwd"];
            var vhost = ConfigurationManager.AppSettings["rabbit.vhost"];

            LogAdapter.LogDebugFn              = (s, s1, arg3) => { };
            LogAdapter.ExtendedLogEnabled      = false;
            LogAdapter.ProtocolLevelLogEnabled = false;


            int  howManyQueues        = 1;
            bool exclusiveConnections = ConfigurationManager.AppSettings["exclusiveConnections"] == "true";
            bool useOfficialClient    = ConfigurationManager.AppSettings["useOfficialClient"] == "true";

//			if (useOfficialClient)
//			{
//				RabbitMQ.Client.IConnection conn = null;
//				RabbitMQ.Client.IModel channel = null;
//
//				for (int i = 0; i < howManyQueues; i++)
//				{
//					var connFac = new RabbitMQ.Client.ConnectionFactory { HostName = host, UserName = user, Password = pwd, VirtualHost = vhost, AutomaticRecoveryEnabled = false };
//
//					if (exclusiveConnections || conn == null)
//					{
//						conn = connFac.CreateConnection();
//						channel = conn.CreateModel();
//					}
//
//					var q = "q." + i;
//					channel.QueueDeclareNoWait(q, durable: true, exclusive: false, autoDelete: false, arguments: null);
//
//					channel.BasicConsume(q, false, "con_" + q, arguments: null, consumer: new Consumer(channel));
//				}
//			}
//			else
            {
                RabbitMqNext.LogAdapter.LogErrorFn = (scope, message, exc) =>
                {
                    Console.WriteLine("[Error] " + scope + " - " + message + " exception " + exc);
                };
                RabbitMqNext.LogAdapter.LogWarnFn = (scope, message, exc) =>
                {
                    Console.WriteLine("[Warn] " + scope + " - " + message + " exception " + exc);
                };
                RabbitMqNext.LogAdapter.LogDebugFn = (scope, message, exc) =>
                {
                    Console.WriteLine("[Dbg] " + scope + " - " + message + " exception " + exc);
                };

                RabbitMqNext.IConnection conn    = null;
                RabbitMqNext.IChannel    channel = null;

                for (int i = 0; i < howManyQueues; i++)
                {
                    if (exclusiveConnections || conn == null)
                    {
                        conn = await RabbitMqNext.ConnectionFactory.Connect(host, vhost, user, pwd, recoverySettings : null, connectionName : "mod_perf_server");

                        channel = await conn.CreateChannel();
                    }

                    var q = "q." + i;

                    await channel.QueueDeclare(q, passive : false, durable : true, exclusive : false, autoDelete : false, arguments : null,
                                               waitConfirmation : false);

                    await channel.ExchangeDeclare("exctemp", "direct", durable : true, autoDelete : false, arguments : null, waitConfirmation : true);

                    for (int j = 0; j < 1000; j++)
                    {
                        await channel.QueueBind(q, "exctemp", "routing_" + j, arguments : null, waitConfirmation : (j % 2 == 0));
                    }

                    // TODO: test with parallel buffer copy + serialized too
                    await channel.BasicConsume(ConsumeMode.ParallelWithBufferCopy, BuildConsumerFn(channel), q, "consumer_" + q,
                                               false, true, arguments : null, waitConfirmation : false);
                }
            }

            Console.WriteLine("Ready");

            await Task.Delay(1);

            Thread.CurrentThread.Join();
        }
Exemplo n.º 4
0
        private async Task Run(string[] args)
        {
            //
            // client side
            // publishes on different connections
            //

            LogAdapter.ExtendedLogEnabled      = false;
            LogAdapter.ProtocolLevelLogEnabled = false;
            LogAdapter.LogDebugFn = (s, s1, arg3) => { };

            var host  = ConfigurationManager.AppSettings["rabbit.host"];
            var user  = ConfigurationManager.AppSettings["rabbit.admuser"];
            var pwd   = ConfigurationManager.AppSettings["rabbit.admpwd"];
            var vhost = ConfigurationManager.AppSettings["rabbit.vhost"];

            var postWarmupDelay = TimeSpan.FromSeconds(5);

            int  howManyQueues        = 10;
            bool exclusiveConnections = ConfigurationManager.AppSettings["exclusiveConnections"] == "true";
            bool useOfficialClient    = ConfigurationManager.AppSettings["useOfficialClient"] == "true";

            var howManyCalls = 100000;

            _completionSemaphore = new SemaphoreSlim(0, howManyQueues);
            _startSync           = new ManualResetEventSlim(false);

            if (useOfficialClient)
            {
                // Warm up
//				{
//					var connFac = new RabbitMQ.Client.ConnectionFactory() { HostName = host, UserName = user, Password = pwd, VirtualHost = vhost, AutomaticRecoveryEnabled = false };
//					var conn2 = connFac.CreateConnection();
//					var channel2 = conn2.CreateModel();
//					var q = "q." + 0;
//					PublishLegacy(q, channel2, howManyCalls / 4, isWarmUp: true);
//					channel2.Dispose();
//					conn2.Dispose();
//				}
//
//				await WarmupComplete(postWarmupDelay);

                RabbitMQ.Client.IConnection conn    = null;
                RabbitMQ.Client.IModel      channel = null;

                for (int i = 0; i < howManyQueues; i++)
                {
                    var connFac = new RabbitMQ.Client.ConnectionFactory()
                    {
                        HostName = host, UserName = user, Password = pwd, VirtualHost = vhost, AutomaticRecoveryEnabled = false
                    };

                    if (exclusiveConnections || conn == null)
                    {
                        conn    = connFac.CreateConnection();
                        channel = conn.CreateModel();
                    }

                    var q = "q." + i;

                    new Thread(() =>
                    {
                        PublishLegacy(q, channel, howManyCalls, isWarmUp: false);
                    })
                    {
                        IsBackground = true
                    }.Start();
                }
            }
            else
            {
                // Warm up
//				{
//					var conn2 = await RabbitMqNext.ConnectionFactory.Connect(host, vhost, user, pwd, recoverySettings: null, connectionName: "perf_client");
//					var channel2 = await conn2.CreateChannel();
//					var q = "q." + 0;
//					await Task.Delay(1); // Thread switch
//					PublishModern(q, channel2, howManyCalls / 4, isWarmUp: true);
//					await Task.Delay(1); // Thread switch
//					channel2.Dispose();
//					conn2.Dispose();
//				}
//
//				await WarmupComplete(postWarmupDelay);

                RabbitMqNext.IConnection conn    = null;
                RabbitMqNext.IChannel    channel = null;

                for (int i = 0; i < howManyQueues; i++)
                {
                    if (exclusiveConnections || conn == null)
                    {
                        conn = await RabbitMqNext.ConnectionFactory.Connect(host, vhost, user, pwd, recoverySettings : null, connectionName : "perf_client");

                        channel = await conn.CreateChannel();
                    }

                    var q = "q." + i;

                    new Thread(() =>
                    {
                        PublishModern(q, channel, howManyCalls, isWarmUp: false);
                    })
                    {
                        IsBackground = true
                    }.Start();
                }
            }

            _startSync.Set();

            Console.WriteLine("Waiting for publishing to complete");

            for (int i = 0; i < howManyQueues; i++)
            {
                _completionSemaphore.Wait();
            }

            Console.WriteLine("Done\r\n");

            Console.ReadKey();
        }