private static async Task Main()
        {
            const int messageCount = 1000000;
            const int batchSize    = 100;

            int[] clientCounts = { 8, 16, 32 };
            var   tps          = new[] { 50, 100, 200, 400, 800 };

            foreach (var t in tps)
            {
                var d = new ThreadPoolDispatcher {
                    Throughput = t
                };

                foreach (var clientCount in clientCounts)
                {
                    var sys = new ActorSystem();
                    Console.WriteLine("Starting test  " + clientCount);
                    var pingActors = new PID[clientCount];
                    var pongActors = new PID[clientCount];

                    for (var i = 0; i < clientCount; i++)
                    {
                        pingActors[i] = sys.Root.Spawn(
                            PingActor
                            .Props(messageCount, batchSize)
                            .WithDispatcher(d)
                            );
                        pongActors[i] = sys.Root.Spawn(
                            PongActor
                            .Props
                            .WithDispatcher(d)
                            );
                    }

                    Console.WriteLine("Actors created");

                    var tasks = new Task[clientCount];
                    var sw    = Stopwatch.StartNew();

                    for (var i = 0; i < clientCount; i++)
                    {
                        var pingActor = pingActors[i];
                        var pongActor = pongActors[i];

                        tasks[i] = sys.Root.RequestAsync <bool>(pingActor, new PingActor.Start(pongActor));
                    }

                    Console.WriteLine("Waiting for actors");
                    await Task.WhenAll(tasks);

                    sw.Stop();

                    var totalMessages = messageCount * 2 * clientCount;
                    var x             = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d);
                    Console.WriteLine();
                    Console.WriteLine($"{clientCount}\t\t{sw.ElapsedMilliseconds}\t\t{x:n0}");
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Is Server GC {GCSettings.IsServerGC}");

            const int messageCount = 1000000;
            const int batchSize    = 100;

            int[] clientCounts = new int[] { 1, 2, 4, 8, 16 };

            Console.WriteLine("Clients\t\tElapsed\t\tMsg/sec");

            var config = ConfigurationFactory.ParseString(@"
                akka.suppress-json-serializer-warning = on
                akka.actor.serialize-messages = on
            ");

            foreach (var clientCount in clientCounts)
            {
                var clients = new IActorRef[clientCount];
                var echos   = new IActorRef[clientCount];

                using (var sys = ActorSystem.Create("main", config))
                {
                    for (var i = 0; i < clientCount; i++)
                    {
                        clients[i] = sys.ActorOf(PingActor.Props(messageCount, batchSize));
                        echos[i]   = sys.ActorOf(PongActor.Props);
                    }

                    var tasks = new Task[clientCount];
                    var sw    = Stopwatch.StartNew();
                    for (var i = 0; i < clientCount; i++)
                    {
                        var client = clients[i];
                        var echo   = echos[i];

                        tasks[i] = client.Ask <bool>(new Start(echo));
                    }
                    Task.WaitAll(tasks);
                    sw.Stop();

                    var totalMessages = messageCount * 2 * clientCount;
                    var x             = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d);
                    Console.WriteLine($"{clientCount}\t\t{sw.ElapsedMilliseconds}\t\t{x}");
                }

                Thread.Sleep(2000);
            }

            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Is Server GC {GCSettings.IsServerGC}");

            const int messageCount = 1000000;
            const int batchSize    = 100;

            int[] clientCounts = new int[] { 1, 2, 4, 8, 16 };

            Console.WriteLine("Clients\t\tElapsed\t\tMsg/sec");

            foreach (var clientCount in clientCounts)
            {
                var clients = new PID[clientCount];
                var echos   = new PID[clientCount];

                for (var i = 0; i < clientCount; i++)
                {
                    clients[i] = Actor.Spawn(PingActor.Props(messageCount, batchSize));
                    echos[i]   = Actor.Spawn(PongActor.Props);
                }

                var tasks = new Task[clientCount];
                var sw    = Stopwatch.StartNew();
                for (var i = 0; i < clientCount; i++)
                {
                    var client = clients[i];
                    var echo   = echos[i];

                    tasks[i] = client.RequestAsync <bool>(new PingActor.Start(echo));
                }
                Task.WaitAll(tasks);
                sw.Stop();

                var totalMessages = messageCount * 2 * clientCount;
                var x             = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d);
                Console.WriteLine($"{clientCount}\t\t{sw.ElapsedMilliseconds}\t\t{x}");

                Thread.Sleep(2000);
            }

            Console.ReadLine();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Is Server GC {GCSettings.IsServerGC}");

            string serializer = args.FirstOrDefault(arg => arg.StartsWith("--serializer="))?.Replace("--serializer=", "");

            const int messageCount = 1000000;
            const int batchSize    = 100;

            int[] clientCounts = new int[] { 1, 2, 4, 8, 16 };

            Console.WriteLine("Clients\t\tElapsed\t\tMsg/sec");

            var config = ConfigurationFactory.ParseString(@"akka.suppress-json-serializer-warning=on");

            if (!string.IsNullOrEmpty(serializer))
            {
                Console.WriteLine($"Used {serializer} serializer");
                config = config.WithFallback(ConfigurationFactory.ParseString(@"
                    akka.actor.serialize-messages = on
                    akka.actor.serializers.protobuf = ""LocalPingPong.Serializers.ProtobufSerializer, LocalPingPong""
                    akka.actor.serializers.msgpack = ""LocalPingPong.Serializers.MsgPackSerializer, LocalPingPong""
                    akka.actor.serializers.hyperion = ""LocalPingPong.Serializers.HyperionSerializer, LocalPingPong""
                "));

                if (serializer.Equals("protobuf"))
                {
                    config = config.WithFallback(ConfigurationFactory.ParseString(@"akka.actor.serialization-bindings.""LocalPingPong.Msg, LocalPingPong"" = protobuf"));
                }
                else if (serializer.Equals("hyperion"))
                {
                    config = config.WithFallback(ConfigurationFactory.ParseString(@"akka.actor.serialization-bindings.""LocalPingPong.Msg, LocalPingPong"" = hyperion"));
                }
                else if (serializer.Equals("msgpack"))
                {
                    config = config.WithFallback(ConfigurationFactory.ParseString(@"akka.actor.serialization-bindings.""LocalPingPong.Msg, LocalPingPong"" = msgpack"));
                }
            }

            foreach (var clientCount in clientCounts)
            {
                var clients = new IActorRef[clientCount];
                var echos   = new IActorRef[clientCount];

                using (var sys = ActorSystem.Create("main", config))
                {
                    for (var i = 0; i < clientCount; i++)
                    {
                        clients[i] = sys.ActorOf(PingActor.Props(messageCount, batchSize));
                        echos[i]   = sys.ActorOf(PongActor.Props);
                    }

                    var tasks = new Task[clientCount];
                    var sw    = Stopwatch.StartNew();
                    for (var i = 0; i < clientCount; i++)
                    {
                        var client = clients[i];
                        var echo   = echos[i];

                        tasks[i] = client.Ask <bool>(new Start(echo));
                    }
                    Task.WaitAll(tasks);
                    sw.Stop();

                    var totalMessages = messageCount * 2 * clientCount;
                    var x             = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d);
                    Console.WriteLine($"{clientCount}\t\t{sw.ElapsedMilliseconds}\t\t{x}");
                }

                Thread.Sleep(2000);
            }

            Console.ReadLine();
        }