public TestResult Run() { Console.WriteLine("Performance benchmark starting.\n"); Console.WriteLine($"for journal plugin {JournalPlugin}\n"); var actorSystemId = Guid.NewGuid(); using (var system = ActorSystem.Create($"persistent-benchmark-{actorSystemId}", Criteria.Config)) { var actors = new IActorRef[Criteria.ActorCount]; for (int i = 0; i < Criteria.ActorCount; i++) { var pid = actorSystemId + "-" + i; actors[i] = system.ActorOf(Props.Create(() => new PerformanceActor(pid))); } Task.WaitAll( actors .Select(a => a.Ask <CreatedResponse>(CreateCommand.Instance)) .Cast <Task>() .ToArray() ); Console.WriteLine($"All {Criteria.ActorCount} actors have been initialized."); var stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < Criteria.MessagesPerActor; i++) { for (int j = 0; j < Criteria.ActorCount; j++) { actors[j].Tell(new StoreValueCommand(1)); } } var finished = new Task[Criteria.ActorCount]; for (int i = 0; i < Criteria.ActorCount; i++) { finished[i] = actors[i].Ask <StateResponse>(FinishCommand.Instance); } Task.WaitAll(finished); var elapsed = stopwatch.ElapsedMilliseconds; foreach (Task <StateResponse> task in finished) { if (!task.IsCompleted || task.Result.State != Criteria.MessagesPerActor) { throw new IllegalStateException("Actor's state was invalid"); } } return(TestResult.From(Criteria, elapsed)); } }
private static void Main(string[] args) { using (var system = ActorSystem.Create("persistent-benchmark", Config.WithFallback(ConfigurationFactory.Default()))) { Console.WriteLine("Performance benchmark starting..."); var stopwatch = new Stopwatch(); var actors = new IActorRef[ActorCount]; for (var i = 0; i < ActorCount; i++) { var pid = "a-" + i; actors[i] = system.ActorOf(Props.Create(() => new PerformanceTestActor(pid))); } stopwatch.Start(); Task.WaitAll(actors.Select(a => a.Ask <Done>(Init.Instance)).Cast <Task>().ToArray()); stopwatch.Stop(); Console.WriteLine($"Initialized {ActorCount} eventsourced actors in {stopwatch.ElapsedMilliseconds / 1000.0} sec..."); stopwatch.Start(); for (var i = 0; i < MessagesPerActor; i++) { for (var j = 0; j < ActorCount; j++) { actors[j].Tell(new Store(1)); } } var finished = new Task[ActorCount]; for (var i = 0; i < ActorCount; i++) { finished[i] = actors[i].Ask <Finished>(Finish.Instance); } Task.WaitAll(finished); stopwatch.Stop(); var elapsed = stopwatch.ElapsedMilliseconds; Console.WriteLine($"{ActorCount} actors stored {MessagesPerActor} events each in {elapsed / 1000.0} sec. Average: {ActorCount * MessagesPerActor * 1000.0 / elapsed} events/sec"); if (finished.Cast <Task <Finished> >().Any(task => !task.IsCompleted || task.Result.State != MessagesPerActor)) { throw new IllegalStateException("Actor's state was invalid"); } } Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }
static void Main(string[] args) { using (var system = ActorSystem.Create("persistent-benchmark", config.WithFallback(ConfigurationFactory.Default()))) { Console.WriteLine("Performance benchmark starting..."); var actors = new IActorRef[ActorCount]; for (int i = 0; i < ActorCount; i++) { var pid = "a-" + i; actors[i] = system.ActorOf(ReceiverActor.Props(pid, ThreadLocalRandom.Current.Next(5, 20)), pid); } Task.WaitAll(actors.Select(a => a.Ask <Done>(Init.Instance)).Cast <Task>().ToArray()); Console.WriteLine("All actors have been initialized..."); var stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < MessagesPerActor; i++) { for (int j = 0; j < ActorCount; j++) { actors[j].Tell(new Message("hi")); } } var finished = new Task[ActorCount]; for (int i = 0; i < ActorCount; i++) { finished[i] = actors[i].Ask <Finished>(Finish.Instance); } Task.WaitAll(finished); var elapsed = stopwatch.ElapsedMilliseconds; Console.WriteLine($"{ActorCount} actors stored {MessagesPerActor} events each in {elapsed / 1000.0} sec. Average: {ActorCount * MessagesPerActor * 1000.0 / elapsed} events/sec"); foreach (Task <Finished> task in finished) { if (!task.IsCompleted || task.Result.State != MessagesPerActor) { throw new IllegalStateException("Actor's state was invalid"); } } } Console.ReadLine(); }