protected void TestInboxThroughput(string workQueueUriFormat, string errorQueueUriFormat, int timeoutMilliseconds, int count, bool isTransactional) { const int threadCount = 1; var padlock = new object(); var configuration = GetConfiguration(workQueueUriFormat, errorQueueUriFormat, threadCount, isTransactional); Console.WriteLine("Sending {0} messages to input queue '{1}'.", count, configuration.Inbox.WorkQueue.Uri); var sw = new Stopwatch(); using (var bus = new ServiceBus(configuration)) { for (var i = 0; i < 5; i++) { var warmup = bus.CreateTransportMessage(new SimpleCommand("warmup")); configuration.Inbox.WorkQueue.Enqueue(warmup.MessageId, configuration.Serializer.Serialize(warmup)); } var idleThreads = new List<int>(); bus.Events.ThreadWaiting += (sender, args) => { lock (padlock) { if (idleThreads.Contains(Thread.CurrentThread.ManagedThreadId)) { return; } idleThreads.Add(Thread.CurrentThread.ManagedThreadId); } }; bus.Start(); while (idleThreads.Count < threadCount) { Thread.Sleep(25); } bus.Stop(); sw.Start(); for (var i = 0; i < count; i++) { var message = bus.CreateTransportMessage(new SimpleCommand("command " + i)); configuration.Inbox.WorkQueue.Enqueue(message.MessageId, configuration.Serializer.Serialize(message)); } sw.Stop(); Console.WriteLine("Took {0} ms to send {1} messages. Starting processing.", sw.ElapsedMilliseconds, count); idleThreads.Clear(); bus.Start(); sw.Reset(); sw.Start(); while (idleThreads.Count < threadCount) { Thread.Sleep(25); } sw.Stop(); } AttemptDropQueues(workQueueUriFormat, errorQueueUriFormat); var ms = sw.ElapsedMilliseconds; Console.WriteLine("Processed {0} messages in {1} ms", count, ms); Assert.IsTrue(ms < timeoutMilliseconds, "Should be able to process at least {0} messages in {1} ms but it ook {2} ms.", count, timeoutMilliseconds, ms); }
protected void TestInboxThroughput(string queueSchemeAndHost, int count, int timeoutMilliseconds, bool useJournal) { var configuration = GetTestInboxConfiguration(queueSchemeAndHost, useJournal, 1); Console.WriteLine("Sending {0} messages to input queue '{1}'.", count, configuration.Inbox.WorkQueue.Uri); var sw = new Stopwatch(); using (var bus = new ServiceBus(configuration)) { for (var i = 0; i < 5; i++) { var warmup = bus.CreateTransportMessage(new SimpleCommand("warmup")); configuration.Inbox.WorkQueue.Enqueue(warmup.MessageId, configuration.Serializer.Serialize(warmup)); } var working = true; bus.Events.ThreadWaiting += (sender, args) => { working = false; }; bus.Start(); while (working) { Thread.Sleep(25); } bus.Stop(); sw.Start(); for (var i = 0; i < count; i++) { var message = bus.CreateTransportMessage(new SimpleCommand("command " + i)); configuration.Inbox.WorkQueue.Enqueue(message.MessageId, configuration.Serializer.Serialize(message)); } sw.Stop(); Console.WriteLine("Took {0} ms to send {1} messages. Starting processing.", sw.ElapsedMilliseconds, count); bus.Start(); sw.Reset(); sw.Start(); working = true; while (working) { Thread.Sleep(25); } sw.Stop(); } var ms = sw.ElapsedMilliseconds; Console.WriteLine("Processed {0} messages in {1} ms", count, ms); Assert.IsTrue(ms < timeoutMilliseconds, "Should be able to process at least {0} messages in {1} ms but it ook {2} ms.", count, timeoutMilliseconds, ms); }