public void Run()
		{
			Stopwatch timer = Stopwatch.StartNew();

			const int channelCount = 10000;
			const int seedCount = 500;

			var channels = new UntypedChannel[channelCount];
			var connections = new ChannelConnection[channelCount];

			var complete = new Future<int>();

			var latch = new CountdownLatch(channelCount*seedCount, complete.Complete);

			for (int i = 0; i < channelCount; i++)
			{
				int channelNumber = i;
				channels[i] = new ChannelAdapter();
				connections[i] = channels[i].Connect(x =>
					{
						x.AddConsumerOf<AMessage>()
							.UsingConsumer(message =>
								{
									if (channelNumber < channels.Length - 1)
										channels[channelNumber + 1].Send(message);

									latch.CountDown();
								});
					});
			}

			var body = new AMessage();

			for (int i = 0; i < seedCount; i++)
			{
				channels[i].Send(body);

				for (int j = 0; j < i; j++)
					latch.CountDown();
			}

			bool completed = complete.WaitUntilCompleted(2.Minutes());

			timer.Stop();

			connections.Each(x => x.Dispose());
			

			if (!completed)
			{
				Console.WriteLine("Process did not complete");
				return;
			}

			Console.WriteLine("Processed {0} messages in with {1} channels in {2}ms", seedCount, channelCount,
			                  timer.ElapsedMilliseconds);

			Console.WriteLine("That's {0} messages per second!", ((long)seedCount*channelCount*1000)/timer.ElapsedMilliseconds);
		}
Exemple #2
0
        public void Run()
        {
            Stopwatch timer = Stopwatch.StartNew();

            const int channelCount = 10000;
            const int seedCount    = 500;

            var channels    = new UntypedChannel[channelCount];
            var connections = new ChannelConnection[channelCount];

            var complete = new Future <int>();

            var latch = new CountdownLatch(channelCount * seedCount, complete.Complete);

            for (int i = 0; i < channelCount; i++)
            {
                int channelNumber = i;
                channels[i]    = new ChannelAdapter();
                connections[i] = channels[i].Connect(x =>
                {
                    x.AddConsumerOf <AMessage>()
                    .UsingConsumer(message =>
                    {
                        if (channelNumber < channels.Length - 1)
                        {
                            channels[channelNumber + 1].Send(message);
                        }

                        latch.CountDown();
                    });
                });
            }

            var body = new AMessage();

            for (int i = 0; i < seedCount; i++)
            {
                channels[i].Send(body);

                for (int j = 0; j < i; j++)
                {
                    latch.CountDown();
                }
            }

            bool completed = complete.WaitUntilCompleted(2.Minutes());

            timer.Stop();

            connections.Each(x => x.Dispose());


            if (!completed)
            {
                Console.WriteLine("Process did not complete");
                return;
            }

            Console.WriteLine("Processed {0} messages in with {1} channels in {2}ms", seedCount, channelCount,
                              timer.ElapsedMilliseconds);

            Console.WriteLine("That's {0} messages per second!", ((long)seedCount * channelCount * 1000) / timer.ElapsedMilliseconds);
        }