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); }
public void Run() { Stopwatch timer = Stopwatch.StartNew(); const int actorCount = 20; const int pingCount = 4000; var actors = new ActorInstance[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); }
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(); } }
public void Start() { //TODO: With Shelving this feels like it needs to become before 'host' start _log.Debug("Calling BeforeStartingServices"); _beforeStartingServices(this); _log.Info("BeforeStart complete"); int unstartedCount = Services.Count(x => x.State != ServiceState.Started); bool completed; long startedServices = 0; using (var startedLatch = new ManualResetEvent(false)) { var countDown = new CountdownLatch(unstartedCount, () => startedLatch.Set()); Action<ServiceStarted> action = msg => { countDown.CountDown(); Interlocked.Increment(ref startedServices); }; ServiceStartedAction += action; _log.Debug("Start is now starting any subordinate services"); foreach (IServiceController serviceController in Services) { _log.InfoFormat("Starting subordinate service '{0}'", serviceController.Name); serviceController.ControllerChannel.Send(new StartService()); } completed = startedLatch.WaitOne(30.Seconds()); ServiceStartedAction -= action; } if (!completed && (HostedServiceCount == 1 || startedServices == 0)) { var qCount = _exceptions.ReadLock(q => q.Count); Exception ex = null; if (qCount > 0) { var kvp = _exceptions.WriteLock(s => s.Dequeue()); ex = kvp.Value; } throw new Exception("One or more services failed to start in a timely manner.", ex); } int serviceExCount = _exceptions.ReadLock(q => q.Select(x => x.Key).Distinct().Count()); if (serviceExCount >= HostedServiceCount) { throw new Exception("All services have errored out.", _exceptions.ReadLock(q => q.Dequeue()).Value); } //TODO: This feels like it should be after 'host' stop _log.Debug("Calling BeforeStart"); _beforeStart(this); _log.Info("BeforeStart complete"); }