Пример #1
0
        bool RunTest <T>(int channelCount, int seedCount, Future <int> complete, Func <T> valueProvider)
        {
            var channels = new Channel <T> [channelCount];

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

            FiberFactory fiberFactory = () => new PoolFiber();

            for (int i = 0; i < channelCount; i++)
            {
                int channelNumber = i;
                channels[i] = new ConsumerChannel <T>(fiberFactory(), x =>
                {
                    if (channelNumber < channels.Length - 1)
                    {
                        channels[channelNumber + 1].Send(x);
                    }

                    latch.CountDown();
                });
            }

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

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

            return(complete.WaitUntilCompleted(24.Seconds()));
        }
Пример #2
0
        public void Run()
        {
            Stopwatch timer = Stopwatch.StartNew();

            FiberFactory fiberFactory = () => new ThreadPoolFiber();

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

            var channels = new Channel <string> [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 ConsumerChannel <string>(fiberFactory(), x =>
                {
                    if (channelNumber < channels.Length - 1)
                    {
                        channels[channelNumber + 1].Send(x);
                    }

                    latch.CountDown();
                });
            }

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

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

            bool completed = complete.WaitUntilCompleted(24.Seconds());

            timer.Stop();

            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);
        }
Пример #3
0
        bool RunTest <T1, T2>(int consumerCount, int messageCount, Future <int> complete, Func <T1> value1Provider,
                              Func <T2> value2Provider, out int totalMessageCount)
        {
            var engine = new DynamicRoutingEngine(new PoolFiber());

            int joinCount = (messageCount / 2) * (messageCount / 2) * consumerCount;

            totalMessageCount = consumerCount * messageCount + joinCount;
            var latch = new CountdownLatch(totalMessageCount, complete.Complete);

            int countA = 0;
            int countB = 0;
            int countC = 0;

            engine.Configure(x =>
            {
                for (int i = 0; i < consumerCount; i++)
                {
                    x.Receive <A>(m =>
                    {
                        Interlocked.Increment(ref countA);
                        latch.CountDown();
                    });
                    x.Receive <B>(m =>
                    {
                        Interlocked.Increment(ref countB);
                        latch.CountDown();
                    });
                }
            });

            //var visualizer = new RoutingEngineTextVisualizer();
            //visualizer.Output = s => Console.WriteLine(s);
            //visualizer.Visit(engine);

            for (int i = 0; i < messageCount; i += 2)
            {
                engine.Send(value1Provider());
                engine.Send(value2Provider());
            }

            bool waitUntilCompleted = complete.WaitUntilCompleted(30.Seconds());

            Console.WriteLine("Consumed A: " + countA);
            Console.WriteLine("Consumed B: " + countB);
            Console.WriteLine("Consumed C: " + countC);


            return(waitUntilCompleted);
        }
Пример #4
0
        public void Run()
        {
            Stopwatch timer = Stopwatch.StartNew();

            FiberFactory fiberFactory = () => new ThreadPoolFiber();

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

            var channels = new Channel<string>[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 ConsumerChannel<string>(fiberFactory(), x =>
                    {
                        if (channelNumber < channels.Length - 1)
                            channels[channelNumber + 1].Send(x);

                        latch.CountDown();
                    });
            }

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

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

            bool completed = complete.WaitUntilCompleted(24.Seconds());

            timer.Stop();

            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);
        }
Пример #5
0
        public void Should_work()
        {
            Stopwatch timer = Stopwatch.StartNew();

            FiberFactory fiberFactory = () => new ThreadPoolFiber();

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

            var channels = new Channel <string> [channelCount];

            var completed = new Future <int>();

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

            for (int i = 0; i < channelCount; i++)
            {
                int channelNumber = i;
                channels[i] = new ConsumerChannel <string>(fiberFactory(), x =>
                {
                    if (channelNumber < channels.Length - 1)
                    {
                        channels[channelNumber + 1].Send(x);
                    }

                    latch.CountDown();
                });
            }

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

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

            completed.WaitUntilCompleted(24.Seconds()).ShouldBeTrue();

            timer.Stop();

            Trace.WriteLine("Elapsed Time: " + timer.ElapsedMilliseconds + "ms");
        }
 public TestActor(Inbox inbox, CountdownLatch latch)
 {
     _latch = latch;
     inbox.Loop(loop =>
     {
         loop.Receive <TConsumer>(m =>
         {
             _latch.CountDown();
             loop.Continue();
         });
     });
 }
Пример #7
0
        public void Run(PipelineRunner instance, int iterationCount)
        {
            var complete = new ManualResetEvent(false);

            var latch = new CountdownLatch(10, () => complete.Set());

            for (int i = 0; i < 10; i++)
            {
                ThreadPool.QueueUserWorkItem(x =>
                {
                    for (int j = 0; j < iterationCount / 10; j++)
                    {
                        instance.SendMessage();
                    }

                    latch.CountDown();
                });
            }

            complete.WaitOne(5.Minutes());
        }
Пример #8
0
        public void Should_perform_admirably()
        {
            var random = new Random();

            _count = 50000;

            _updateValues = Enumerable.Range(0, _count)
                            .Select(x => random.Next(1, 1000))
                            .Select(x => x > 960 ? 1000 : x)
                            .Select(x => new UpdateValue(x, random.Next(1, 500000) / 100m))
                            .ToList();

            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
                x.AddConsumerOf <UpdateValue>()
                .UsingInstance()
                .Of <TestInstance>()
                .DistributedBy(msg => msg.Id)
                .PersistUsingNHibernate()
                .UsingSessionProvider(m => SessionFactory.OpenSession())
                .OnChannel(m => m.UpdateValueChannel)
                .CreateNewInstanceBy(m => new TestInstance(m.Id));
            }))
            {
                var complete = new Future <int>();
                var latch    = new CountdownLatch(_count, complete.Complete);

                _stopwatch = Stopwatch.StartNew();
                UpdateValue.SetReceivedCallback(x => latch.CountDown());

                _updateValues.Each(input.Send);

                complete.WaitUntilCompleted(2.Minutes()).ShouldBeTrue();

                _stopwatch.Stop();
            }
        }
Пример #9
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);
        }
Пример #10
0
        public void Should_perform_admirably()
        {
            var random = new Random();

            _count = 50000;

            _updateValues = Enumerable.Range(0, _count)
                .Select(x => random.Next(1, 1000))
                .Select(x => x > 960 ? 1000 : x)
                .Select(x => new UpdateValue(x, random.Next(1, 500000)/100m))
                .ToList();

            var input = new ChannelAdapter();
            using (input.Connect(x =>
                {
                    x.AddConsumerOf<UpdateValue>()
                        .UsingInstance()
                        .Of<TestInstance>()
                        .DistributedBy(msg => msg.Id)
                        .PersistUsingNHibernate()
                        .UsingSessionProvider(m => SessionFactory.OpenSession())
                        .OnChannel(m => m.UpdateValueChannel)
                        .CreateNewInstanceBy(m => new TestInstance(m.Id));
                }))
            {
                var complete = new Future<int>();
                var latch = new CountdownLatch(_count, complete.Complete);

                _stopwatch = Stopwatch.StartNew();
                UpdateValue.SetReceivedCallback(x => latch.CountDown());

                _updateValues.Each(input.Send);

                complete.WaitUntilCompleted(2.Minutes()).ShouldBeTrue();

                _stopwatch.Stop();
            }
        }
Пример #11
0
        public void Run()
        {
            Stopwatch timer = Stopwatch.StartNew();

            const int actorCount = 20;
            const int pingCount  = 4000;

            var actors = new ActorRef[actorCount + 1];

            var complete = new Future <int>();

            var latch = new CountdownLatch(actorCount * pingCount, complete.Complete);

            for (int i = actorCount; i >= 0; i--)
            {
                actors[i] = AnonymousActor.New(inbox =>
                {
                    var pong = new Pong();

                    var server = actors[(i + 1)];

                    inbox.Loop(loop =>
                    {
                        loop.Receive <Request <Ping> >(request =>
                        {
                            request.Respond(pong);
                            loop.Continue();
                        });
                    });


                    if (i < actorCount)
                    {
                        var ping  = new Ping();
                        int count = 0;

                        Action loop = null;
                        loop        = () =>
                        {
                            server.Request(ping, inbox)
                            .Receive <Response <Pong> >(response =>
                            {
                                latch.CountDown();
                                count++;
                                if (count < pingCount)
                                {
                                    loop();
                                }
                            });
                        };

                        loop();
                    }
                });
            }

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

            timer.Stop();

            for (int i = 0; i < actorCount; i++)
            {
                actors[i].Exit();
                actors[i] = null;
            }

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

            Console.WriteLine("Processed {0} messages in with {1} actors in {2}ms", pingCount, actorCount, timer.ElapsedMilliseconds);

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