Ejemplo n.º 1
0
        private static void Hello(ILog log, HelloClient helloClient)
        {
            var request = new ActorMessageEnvelope <HelloRequest>()
            {
                Message = new HelloRequest()
                {
                    Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff")
                },
            };

            log.DebugFormat("Hello, say hello to server with MessageID[{0}].",
                            request.MessageID);

            var response = helloClient.SayHello(request);

            log.DebugFormat("Hello, receive hello response from server with MessageID[{0}] and CorrelationID[{1}].",
                            response.MessageID, response.CorrelationID);
        }
Ejemplo n.º 2
0
        private static void Hello10000(ILog log, HelloClient helloClient)
        {
            log.DebugFormat("Hello10000, start ...");
            var watch = Stopwatch.StartNew();

            for (var i = 0; i < 10000; i++)
            {
                var request = new ActorMessageEnvelope <Hello10000Request>()
                {
                    Message = new Hello10000Request()
                    {
                        Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff")
                    },
                };
                helloClient.SayHello10000(request);
            }
            watch.Stop();
            log.DebugFormat("Hello10000, end with cost {0} ms.", watch.ElapsedMilliseconds);
        }
Ejemplo n.º 3
0
        private static void Hello10000MultiThreading(ILog log, HelloClient helloClient, int totalCalls, int threadCount)
        {
            log.DebugFormat("Hello10000MultiThreading, TotalCalls[{0}], ThreadCount[{1}], start ...", totalCalls, threadCount);

            var taskList = new Task[threadCount];
            var watch    = Stopwatch.StartNew();

            for (int i = 0; i < threadCount; i++)
            {
                var task = Task.Factory.StartNew(() =>
                {
                    for (var j = 0; j < totalCalls / threadCount; j++)
                    {
                        var request = new ActorMessageEnvelope <Hello10000Request>()
                        {
                            Message = new Hello10000Request()
                            {
                                Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff")
                            },
                        };
                        helloClient.SayHello10000(request);
                    }
                },
                                                 TaskCreationOptions.PreferFairness);
                taskList[i] = task;
            }
            Task.WaitAll(taskList);
            watch.Stop();

            log.DebugFormat("Hello10000MultiThreading, TotalCalls[{0}], ThreadCount[{1}] end with cost [{2}] ms."
                            + "{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}",
                            totalCalls, threadCount, watch.ElapsedMilliseconds,
                            Environment.NewLine, string.Format("   Concurrency level: {0} threads", threadCount),
                            Environment.NewLine, string.Format("   Complete requests: {0}", totalCalls),
                            Environment.NewLine, string.Format("Time taken for tests: {0} seconds", (decimal)watch.ElapsedMilliseconds / 1000m),
                            Environment.NewLine, string.Format("    Time per request: {0:#####0.000} ms (avg)", (decimal)watch.ElapsedMilliseconds / (decimal)totalCalls),
                            Environment.NewLine, string.Format(" Requests per second: {0} [#/sec] (avg)", (int)((decimal)totalCalls / ((decimal)watch.ElapsedMilliseconds / 1000m)))
                            );
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var localActor = new RpcActor();

            var helloClient = new HelloClient(localActor);
            var calcClient  = new CalcClient(localActor);
            var orderClient = new OrderClient(localActor);

            localActor.RegisterRpcService(helloClient);
            localActor.RegisterRpcService(calcClient);
            localActor.RegisterRpcService(orderClient);

            localActor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant().Trim();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else if (text == "reconnect")
                    {
                        localActor.Shutdown();
                        localActor.Bootup();
                    }
                    else if (Regex.Match(text, @"^hello(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"^hello(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            Hello(helloClient);
                        }
                    }
                    else if (Regex.Match(text, @"^add(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"^add(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            Add(calcClient);
                        }
                    }
                    else if (Regex.Match(text, @"^order(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"order(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            PlaceOrder(orderClient);
                        }
                    }
                    else if (Regex.Match(text, @"^hello(\d+)x(\d+)$").Success)
                    {
                        var match       = Regex.Match(text, @"^hello(\d+)x(\d+)$");
                        int totalCalls  = int.Parse(match.Groups[1].Value);
                        int threadCount = int.Parse(match.Groups[2].Value);
                        Hello10000MultiThreading(helloClient, totalCalls, threadCount);
                    }
                    else if (Regex.Match(text, @"^add(\d+)x(\d+)$").Success)
                    {
                        var match       = Regex.Match(text, @"^add(\d+)x(\d+)$");
                        int totalCalls  = int.Parse(match.Groups[1].Value);
                        int threadCount = int.Parse(match.Groups[2].Value);
                        Add10000MultiThreading(calcClient, totalCalls, threadCount);
                    }
                    else
                    {
                        _log.WarnFormat("Cannot parse the operation for input [{0}].", text);
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message, ex);
                }
            }

            localActor.Shutdown();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            ILog log = Logger.Get <Program>();

            var actor = new RpcActor();

            var helloClient = new HelloClient(actor);
            var calcClient  = new CalcClient(actor);
            var orderClient = new OrderClient(actor);

            actor.RegisterRpcService(helloClient);
            actor.RegisterRpcService(calcClient);
            actor.RegisterRpcService(orderClient);

            actor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else if (text == "reconnect")
                    {
                        actor.Shutdown();
                        actor.Bootup();
                    }
                    else if (text == "hello")
                    {
                        Hello(log, helloClient);
                    }
                    else if (text == "hello10000")
                    {
                        Hello10000(log, helloClient);
                    }
                    #region hello10000
                    else if (text == "hello10000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 1);
                    }
                    else if (text == "hello10000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 2);
                    }
                    else if (text == "hello10000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 4);
                    }
                    else if (text == "hello10000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 8);
                    }
                    else if (text == "hello10000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 16);
                    }
                    else if (text == "hello10000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 32);
                    }
                    #endregion
                    #region hello20000
                    else if (text == "hello20000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 1);
                    }
                    else if (text == "hello20000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 2);
                    }
                    else if (text == "hello20000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 4);
                    }
                    else if (text == "hello20000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 8);
                    }
                    else if (text == "hello20000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 16);
                    }
                    else if (text == "hello20000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 32);
                    }
                    #endregion
                    #region hello100000
                    else if (text == "hello100000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 1);
                    }
                    else if (text == "hello100000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 2);
                    }
                    else if (text == "hello100000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 4);
                    }
                    else if (text == "hello100000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 8);
                    }
                    else if (text == "hello100000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 16);
                    }
                    else if (text == "hello100000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 32);
                    }
                    #endregion
                    #region hello300000
                    else if (text == "hello300000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 1);
                    }
                    else if (text == "hello300000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 2);
                    }
                    else if (text == "hello300000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 4);
                    }
                    else if (text == "hello300000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 8);
                    }
                    else if (text == "hello300000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 16);
                    }
                    else if (text == "hello300000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 32);
                    }
                    #endregion
                    #region hello1500000
                    else if (text == "hello1500000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 1);
                    }
                    else if (text == "hello1500000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 2);
                    }
                    else if (text == "hello1500000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 4);
                    }
                    else if (text == "hello1500000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 8);
                    }
                    else if (text == "hello1500000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 16);
                    }
                    else if (text == "hello1500000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 32);
                    }
                    #endregion
                    #region add10000
                    else if (text == "add10000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 1);
                    }
                    else if (text == "add10000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 2);
                    }
                    else if (text == "add10000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 4);
                    }
                    else if (text == "add10000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 8);
                    }
                    else if (text == "add10000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 16);
                    }
                    else if (text == "add10000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 32);
                    }
                    #endregion
                    #region add20000
                    else if (text == "add20000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 1);
                    }
                    else if (text == "add20000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 2);
                    }
                    else if (text == "add20000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 4);
                    }
                    else if (text == "add20000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 8);
                    }
                    else if (text == "add20000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 16);
                    }
                    else if (text == "add20000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 32);
                    }
                    #endregion
                    #region add100000
                    else if (text == "add100000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 1);
                    }
                    else if (text == "add100000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 2);
                    }
                    else if (text == "add100000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 4);
                    }
                    else if (text == "add100000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 8);
                    }
                    else if (text == "add100000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 16);
                    }
                    else if (text == "add100000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 32);
                    }
                    #endregion
                    #region add300000
                    else if (text == "add300000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 1);
                    }
                    else if (text == "add300000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 2);
                    }
                    else if (text == "add300000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 4);
                    }
                    else if (text == "add300000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 8);
                    }
                    else if (text == "add300000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 16);
                    }
                    else if (text == "add300000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 32);
                    }
                    #endregion
                    #region add1500000
                    else if (text == "add1500000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 1);
                    }
                    else if (text == "add1500000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 2);
                    }
                    else if (text == "add1500000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 4);
                    }
                    else if (text == "add1500000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 8);
                    }
                    else if (text == "add1500000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 16);
                    }
                    else if (text == "add1500000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 32);
                    }
                    #endregion
                    else
                    {
                        int times = 0;
                        if (int.TryParse(text, out times))
                        {
                            for (int i = 0; i < times; i++)
                            {
                                PlaceOrder(log, orderClient);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
            }

            actor.Shutdown();
        }