static void MqInProcessTest()
        {
            var config = new MqConfig
            {
                Ip   = "127.0.0.1",
                Port = 2828
            };


            Console.WriteLine("FrameBufferSize: {0}; SendAndReceiveBufferSize: {1}\r\n", config.FrameBufferSize,
                              config.SendAndReceiveBufferSize);

            var smallMessage = new MqMessage
            {
                new MqFrame(SequentialBytes(50), MqFrameType.More, config),
                new MqFrame(SequentialBytes(50), MqFrameType.More, config),
                new MqFrame(SequentialBytes(50), MqFrameType.More, config),
                new MqFrame(SequentialBytes(50), MqFrameType.Last, config)
            };

            MqInProcessPerformanceTests(1000000, 5, smallMessage, config);

            var medimumMessage = new MqMessage
            {
                new MqFrame(SequentialBytes(500), MqFrameType.More, config),
                new MqFrame(SequentialBytes(500), MqFrameType.More, config),
                new MqFrame(SequentialBytes(500), MqFrameType.More, config),
                new MqFrame(SequentialBytes(500), MqFrameType.Last, config)
            };

            MqInProcessPerformanceTests(100000, 5, medimumMessage, config);

            var largeMessage = new MqMessage();

            for (int i = 0; i < 20; i++)
            {
                largeMessage.Add(new MqFrame(SequentialBytes(3000), MqFrameType.More, config));
            }

            MqInProcessPerformanceTests(10000, 5, largeMessage, config);

            Console.WriteLine("Performance complete");

            Console.ReadLine();
        }
Example #2
0
        public MqMessage GenerateRandomMessage(int frames = -1, int frameLength = -1)
        {
            var frameCount = frames == -1 ? _random.Next(8, 16) : frames;
            var message = new MqMessage();
            for (int i = 0; i < frameCount; i++)
            {
                MqFrame frame;

                if (frameLength == -1)
                {
                    frame = new MqFrame(Utilities.SequentialBytes(_random.Next(50, 1024 * 16 - 3)),
                        (i + 1 < frameCount) ? MqFrameType.More : MqFrameType.Last, Config);
                }
                else
                {
                    frame = new MqFrame(Utilities.SequentialBytes(frameLength),
                        (i + 1 < frameCount) ? MqFrameType.More : MqFrameType.Last, Config);
                }
                message.Add(frame);
            }

            return message;
        }
        private static void StartClient(int totalLoops, int totalMessages, int totalFrames, int frameSize)
        {
            var cl = new MqClient <SimpleMqSession, MqConfig>(new MqConfig()
            {
                Ip   = "127.0.0.1",
                Port = 2828
            });

            var stopwatch     = new Stopwatch();
            var messageReader = new MqMessageReader();
            var messageSize   = totalFrames * frameSize;
            var message       = new MqMessage();

            double[] totalValues = { 0, 0, 0 };

            for (int i = 0; i < totalFrames; i++)
            {
                message.Add(new MqFrame(SequentialBytes(frameSize), MqFrameType.More, (MqConfig)cl.Config));
            }

            cl.IncomingMessage += (sender, args) =>
            {
                MqMessage msg;
                while (args.Messages.Count > 0)
                {
                    msg = args.Messages.Dequeue();

                    messageReader.Message = msg;
                    var result = messageReader.ReadString();

                    if (result == "COMPLETE")
                    {
                        if (totalLoops-- > 0)
                        {
                            stopwatch.Stop();

                            var messagesPerSecond =
                                (int)((double)totalMessages / stopwatch.ElapsedMilliseconds * 1000);
                            var msgSizeNoHeader = messageSize;
                            var mbps            = totalMessages * (double)(msgSizeNoHeader) / stopwatch.ElapsedMilliseconds / 1000;
                            Console.WriteLine("| {0,10:N0} | {1,9:N0} | {2,12:N0} | {3,10:N0} | {4,8:N2} |",
                                              totalMessages,
                                              msgSizeNoHeader, stopwatch.ElapsedMilliseconds, messagesPerSecond, mbps);

                            totalValues[0] += stopwatch.ElapsedMilliseconds;
                            totalValues[1] += messagesPerSecond;
                            totalValues[2] += mbps;
                        }

                        if (totalLoops == 0)
                        {
                            Console.WriteLine("|            |  AVERAGES | {0,12:N0} | {1,10:N0} | {2,8:N2} |",
                                              totalValues[0] / totalLoops,
                                              totalValues[1] / totalLoops, totalValues[2] / totalLoops);
                            Console.WriteLine();
                            Console.WriteLine("Test complete");
                        }


                        cl.Close();
                    }
                    else if (result == "START")
                    {
                        if (totalLoops > 0)
                        {
                            stopwatch.Restart();
                            for (var i = 0; i < totalMessages; i++)
                            {
                                cl.Send(message);
                            }
                        }
                    }
                }
            };

            cl.Connect();
        }