Exemplo n.º 1
0
        public void TestPubSub()
        {
            uint loopSize = 100;

            Console.WriteLine("Testing PubSub benchmark..., {0} times", loopSize);
            NetMQMessageBus busAlarm = new NetMQMessageBus();
            NetMQMessageBus busEt    = new NetMQMessageBus();

            busAlarm.Start(Path.Combine(xmlPath, "AlarmService.xml"));
            busEt.Start(Path.Combine(xmlPath, "EtService.xml"));
            MsgHandler handler = new MsgHandler {
                Received = 0, Name = "H2(ET)"
            };

            long start = DateTime.Now.Ticks;

            busEt.Subscriber("alarm", "你好", handler.OnMessageReceived);
            // alarm publish to et
            new Thread(new MsgPublisher {
                bus = busAlarm, Topic = "你好", LoopSize = loopSize
            }.DoWork).Start();
            while (handler.Received != loopSize)
            {
                Thread.Sleep(10);
            }
            double elapsed = (DateTime.Now.Ticks - start) / 10000000.0; //s
            double speed   = loopSize / elapsed;

            // 15479
            Console.WriteLine("DONE, loops = {0},Speed = {1:#0.00} msg/s", handler.Received, speed);
            busAlarm.Stop();
            busEt.Stop();
        }
Exemplo n.º 2
0
        public void TestOpenClose()
        {
            NetMQMessageBus busAlarm = new NetMQMessageBus();
            NetMQMessageBus busEt    = new NetMQMessageBus();
            uint            loopSize = 10;
            uint            sendloop = 1;

            Console.WriteLine("Testing start/stop benchmark..., {0} times", loopSize);
            for (uint i = 0; i < loopSize; i++)
            {
                busAlarm.Start(Path.Combine(xmlPath, "AlarmService.xml"));
                busEt.Start(Path.Combine(xmlPath, "EtService.xml"));
                MsgHandler h2 = new MsgHandler {
                    Received = 0, Name = "H2(ET)"
                };
                busEt.Pull(h2.OnMessageReceived);
                new Thread(new MsgPusher {
                    Name = "et", bus = busAlarm, LoopSize = sendloop
                }.DoWork).Start();

                while (h2.Received != sendloop)
                {
                    Thread.Sleep(10);
                }
                busAlarm.Stop();
                busEt.Stop();
            }
            Console.WriteLine("Done!");
        }
Exemplo n.º 3
0
        public void TestPushPull()
        {
            uint loopSize = 10000;

            Console.WriteLine("Testing pull/push benchmark..., {0} times", loopSize);
            NetMQMessageBus busAlarm = new NetMQMessageBus();
            NetMQMessageBus busEt    = new NetMQMessageBus();

            busAlarm.Start(Path.Combine(xmlPath, "AlarmService.xml"));
            busEt.Start(Path.Combine(xmlPath, "EtService.xml"));
            MsgHandler h2 = new MsgHandler {
                Received = 0, Name = "H2(ET)"
            };

            long start = DateTime.Now.Ticks;

            busEt.Pull(h2.OnMessageReceived);
            new Thread(new MsgPusher {
                Name = "et", bus = busAlarm, LoopSize = loopSize
            }.DoWork).Start();

            while (h2.Received != loopSize)
            {
                Thread.Sleep(10);
            }
            double elapsed = (DateTime.Now.Ticks - start) / 10000000.0; //s
            double speed   = loopSize / elapsed;

            // 15479
            Console.WriteLine("DONE, loops = {0},Speed = {1:#0.00} msg/s", h2.Received, speed);
            busAlarm.Stop();
            busEt.Stop();
        }
Exemplo n.º 4
0
        public void TestReqResp()
        {
            uint loopSize = 100;

            Console.WriteLine("Testing Req/Resp benchmark..., {0} times", loopSize);
            NetMQMessageBus busAlarm = new NetMQMessageBus();
            NetMQMessageBus busEt    = new NetMQMessageBus();

            busAlarm.Start(Path.Combine(xmlPath, "AlarmService.xml"));
            busEt.Start(Path.Combine(xmlPath, "EtService.xml"));
            MsgResponser h2 = new MsgResponser {
                Received = 0, Name = "H2(ET)"
            };

            long start = DateTime.Now.Ticks;

            busEt.Response(h2.OnMessageReceived);
            string resp = null;

            for (int i = 0; i < loopSize; i++)
            {
                resp = busAlarm.Request("et", newMessage(string.Format("ABC {0}", i)).ToJson(), 2000);
            }
            double elapsed = (DateTime.Now.Ticks - start) / 10000000.0; //s
            double speed   = loopSize / elapsed;

            // 15479
            Console.WriteLine("DONE, loops = {0},Speed = {1:#0.00} msg/s", h2.Received, speed);
            busAlarm.Stop();
            busEt.Stop();
        }