Exemple #1
0
        public static void CreateServerAndClient <T, I>(ActorServerProxyOptions options, out IActorServerProxy server, out I client)
            where T : new()
        {
            server = ActorServerProxy.Create <T>("tcp://*:0", options);
            int port = server.BindEndPoint.Port;

            client = ActorClientProxy.CreateActor <I>("tcp://localhost:" + port).Result;
        }
Exemple #2
0
        public async void If_Enabled_IActorSession_should_get_accessible_from_ActorSession_Current()
        {
            var opts = new ActorServerProxyOptions(actorSessionInjectionEnabled: true);

            Utils.CreateServerAndClient <MessageActor, IMessageActor>(opts, out server, out client);

            var client2 = ActorClientProxy.CreateActor <IMessageActor>("tcp://localhost:" + server.BindEndPoint.Port).Result;

            await client.PassDataForContext(1);

            await client.PassDataForContext(1);

            await client2.PassDataForContext(2);

            await client.PassDataForContext(1);

            await client2.PassDataForContext(2);
        }
Exemple #3
0
        public void If_Enabled_StressTest_IActorSession_should_get_accessible_from_ActorSession_Current()
        {
            var opts = new ActorServerProxyOptions(actorSessionInjectionEnabled: true);

            IMessageActor[] clients = new IMessageActor[20];

            Utils.CreateServerAndClient <MessageActor, IMessageActor>(opts, out server, out clients[0]);

            for (int i = 1; i < 20; ++i)
            {
                clients[i] = ActorClientProxy.CreateActor <IMessageActor>("tcp://localhost:" + server.BindEndPoint.Port).Result;
            }

            var tasks = new List <Task>();

            for (int i = 0; i < 100; ++i)
            {
                int idx = i % 20;
                tasks.Add(clients[idx].StressTestSession(idx));
            }

            Task.WaitAll(tasks.ToArray());
        }
Exemple #4
0
        private static async void Start(uint timesToRun)
        {
            const int  repeatFactor = 500;
            const long repeat       = 3000L * repeatFactor;

            var processorCount = Environment.ProcessorCount;

            if (processorCount == 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Failed to read processor count..");
                return;
            }
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Warning: Debugger is attached. This has a major performance impact on this benchmark");
                Console.ResetColor();
            }

            var serverProxyOptions = new ActorServerProxyOptions(actorSessionInjectionEnabled: false);

            int workerThreads;
            int completionPortThreads;

            ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);

            Console.WriteLine("Worker threads:         {0}", workerThreads);
            Console.WriteLine("OSVersion:              {0}", Environment.OSVersion);
            Console.WriteLine("ProcessorCount:         {0}", processorCount);
            Console.WriteLine("ClockSpeed:             {0} MHZ", CpuSpeed());
            Console.WriteLine("Actor Count:            {0}", processorCount * 2);
            Console.WriteLine("Messages sent/received: {0}  ({0:0e0})", GetTotalMessagesReceived(repeat));
            Console.WriteLine();

            //Warm up
            Console.Write("Local     first start time: ");
            await Benchmark(1, 1, 1, PrintStats.StartTimeOnly, -1, -1,
                            (idx, wfs) => Tuple.Create((IActorServerProxy)null, new Destination(wfs)),
                            (idx, d) => d,
                            (idx, wfs, dest, r, latch) => new PingPongActor(wfs, dest, r, latch));

            Console.WriteLine(" ms");
            Console.Write("Remote    first start time: ");
            await Benchmark(1, 1, 1, PrintStats.StartTimeOnly, -1, -1,
                            (idx, wfs) =>
            {
                var dest = new Destination(wfs);
                return(Tuple.Create(ActorServerProxy.Create("tcp://localhost:" + (54000 + idx), dest), dest));
            },
                            (idx, d) => ActorClientProxy.CreateActor <IDestination>("tcp://localhost:" + (54000 + idx)).Result,
                            (idx, wfs, dest, r, latch) => new PingPongActor(wfs, dest, r, latch));

            Console.WriteLine(" ms");
            Console.WriteLine();

            Console.WriteLine("            Local actor                        Remote actor");
            Console.WriteLine("Throughput, Msgs/sec, Start [ms], Total [ms],  Msgs/sec, Start [ms], Total [ms]");
            for (var i = 0; i < timesToRun; i++)
            {
                var redCountLocalActor        = 0;
                var redCountRemoteActor       = 0;
                var bestThroughputLocalActor  = 0L;
                var bestThroughputRemoteActor = 0L;
                foreach (var throughput in GetThroughputSettings())
                {
                    var result1 = await Benchmark(throughput, processorCount, repeat, PrintStats.LineStart | PrintStats.Stats, bestThroughputLocalActor, redCountLocalActor,
                                                  (idx, wfs) => Tuple.Create((IActorServerProxy)null, new Destination(wfs)),
                                                  (idx, d) => d,
                                                  (idx, wfs, dest, r, latch) => new PingPongActor(wfs, dest, r, latch));

                    bestThroughputLocalActor = result1.Item2;
                    redCountLocalActor       = result1.Item3;
                    Console.Write(",  ");

                    var result2 = await Benchmark(throughput, processorCount, repeat, PrintStats.Stats, bestThroughputRemoteActor, redCountRemoteActor,
                                                  (idx, wfs) =>
                    {
                        var dest = new Destination(wfs);
                        return(Tuple.Create(ActorServerProxy.Create("tcp://localhost:" + (54000 + idx), dest, serverProxyOptions), dest));
                    },
                                                  (idx, d) => ActorClientProxy.CreateActor <IDestination>("tcp://localhost:" + (54000 + idx)).Result,
                                                  (idx, wfs, dest, r, latch) => new PingPongActor(wfs, dest, r, latch));

                    bestThroughputRemoteActor = result2.Item2;
                    redCountRemoteActor       = result2.Item3;
                    Console.WriteLine();
                }
            }

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("Done..");
        }