Пример #1
0
        public void RunTest(int startupWaitMultiplier)
        {
            var startupWaitTime = this.ThreadSleepTimes.GetFixedStartupTime(startupWaitMultiplier);

            Thread.Sleep(startupWaitTime);
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                this.ConnectMqtt();

                stopWatch.Stop();
                this.LogMetric(LoggerConstants.ConnectAndSubscribe, stopWatch.Elapsed.GetMilliseconds());
                stopWatch.Reset();
            }
            catch (Exception exception)
            {
                this.LogException(exception);
                return;
            }

            this.TestLimits.StartTest();
            while (!this.TestLimits.IsTimeUp())
            {
                stopWatch.Start();
                var message = new ThroughputTimeMessage {
                    MessageNumber = this.TestLimits.NumberOfMessagesSent, MessageSendtTime = DateTimeOffset.Now
                };
                var serializedMessage = JsonConvert.SerializeObject(message);
                this.PublishMqtt("ServerUserOnlineTopic", serializedMessage);
                this.TestLimits.MessagesSent();

                stopWatch.Stop();

                publishTime += stopWatch.Elapsed;
                var sleepTime = this.ThreadSleepTimes.GetRandomSleepTime();
                if (stopWatch.Elapsed < sleepTime)
                {
                    Thread.Sleep(sleepTime - stopWatch.Elapsed);
                }

                stopWatch.Reset();
            }

            this.TestLimits.EndTest();

            try
            {
                this.DisconectMqtt();
            }
            catch (Exception exception)
            {
                this.LogException(exception);
            }

            this.LogMetric(LoggerConstants.PublishTime, publishTime.GetMilliseconds() / this.TestLimits.NumberOfMessagesSent);
            this.LogMetric(LoggerConstants.Sent, this.TestLimits.NumberOfMessagesSent);
        }
        public void RunTest(int startupWaitMultiplier)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            this.ConnectMqtt();
            this.SubscribeMqtt(this.ClientId.ToString());

            stopWatch.Stop();
            this.LogMetric(LoggerConstants.ConnectAndSubscribe, stopWatch.Elapsed.GetMilliseconds());
            stopWatch.Reset();

            this.TestLimits.StartTest();
            while (!this.TestLimits.AreMaxMessagesSendt() && !this.TestLimits.IsTimeUp())
            {
                stopWatch.Start();
                var message = new ThroughputTimeMessage {
                    MessageNumber = this.TestLimits.NumberOfMessagesSent, MessageSendtTime = DateTimeOffset.Now
                };
                var serializedMessage = JsonConvert.SerializeObject(message);
                this.PublishMqtt(this.ClientId.ToString(), serializedMessage);
                this.TestLimits.MessagesSent();
                stopWatch.Stop();
                publishTime += stopWatch.Elapsed;

                var sleepTime = this.ThreadSleepTimes.GetRandomSleepTime();
                if (stopWatch.Elapsed < sleepTime)
                {
                    Thread.Sleep(sleepTime - stopWatch.Elapsed);
                }

                stopWatch.Reset();
            }

            while (!this.TestLimits.AreAllSendtMessagesRecieved() && !this.TestLimits.IsTimeUp())
            {
                Thread.Sleep(this.ThreadSleepTimes.GetRandomSleepTime());
            }

            this.TestLimits.EndTest();

            this.DisconectMqtt();

            this.LogMetric(LoggerConstants.MessagesNotArrived, (this.TestLimits.NumberOfMessagesSent - this.TestLimits.NumberOfMessagesRecieved));
            this.LogMetric(LoggerConstants.Received, this.TestLimits.NumberOfMessagesRecieved);

            this.LogMetric(LoggerConstants.PublishTime, publishTime.GetMilliseconds() / this.TestLimits.NumberOfMessagesSent);
            this.LogMetric(LoggerConstants.Max, maxTime.GetMilliseconds());
            this.LogMetric(LoggerConstants.Average, totalTime.GetMilliseconds() / this.TestLimits.NumberOfMessagesRecieved);
            this.LogMetric(LoggerConstants.Sent, this.TestLimits.NumberOfMessagesSent);
            this.LogMetric(LoggerConstants.MessagesPrSecond, this.TestLimits.NumberOfMessagesRecieved / (this.TestLimits.ActualTestTime().GetMilliseconds() / 1000));
        }
Пример #3
0
        public void RunTest(int startupWaitMultiplier)
        {
            var startupWaitTime = this.ThreadSleepTimes.GetFixedStartupTime(startupWaitMultiplier);

            Thread.Sleep(startupWaitTime);
            var stopWatch = new Stopwatch();

            try
            {
                stopWatch.Reset();
                stopWatch.Start();
                this.ConnectMqtt();
                stopWatch.Stop();
                this.LogMetric(LoggerConstants.Connect, stopWatch.Elapsed.GetMilliseconds());
            }
            catch (Exception exception)
            {
                this.LogException(exception);
                return;
            }

            try
            {
                stopWatch.Reset();
                stopWatch.Start();
                this.SubscribeMqtt(this.ClientId.ToString());
                stopWatch.Stop();
                this.LogMetric(LoggerConstants.Subscribe, stopWatch.Elapsed.GetMilliseconds());
            }
            catch (Exception exception)
            {
                this.LogException(exception);
                return;
            }

            stopWatch.Reset();
            var loggingInterval         = new TimeSpan(0, 10, 0);
            var elapsedTimeSinceLogging = new TimeSpan();

            this.TestLimits.StartTest();
            while (!this.TestLimits.IsTimeUp())
            {
                stopWatch.Start();
                var message = new ThroughputTimeMessage {
                    MessageNumber = this.TestLimits.NumberOfMessagesSent, MessageSendtTime = DateTimeOffset.Now
                };
                var serializedMessage = JsonConvert.SerializeObject(message);
                this.PublishMqtt(this.ClientId.ToString(), serializedMessage);
                this.TestLimits.MessagesSent();

                stopWatch.Stop();

                publishTime += stopWatch.Elapsed;
                var sleepTime = this.ThreadSleepTimes.GetRandomSleepTime();
                if (stopWatch.Elapsed < sleepTime)
                {
                    elapsedTimeSinceLogging += sleepTime;
                    Thread.Sleep(sleepTime - stopWatch.Elapsed);
                }
                else
                {
                    elapsedTimeSinceLogging += stopWatch.Elapsed;
                }

                if (elapsedTimeSinceLogging > loggingInterval)
                {
                    PeriodicLogging();
                    elapsedTimeSinceLogging = new TimeSpan();
                }

                stopWatch.Reset();
            }

            this.TestLimits.EndTest();

            try
            {
                this.DisconectMqtt();
            }
            catch (Exception exception)
            {
                this.LogException(exception);
            }

            this.LogMetric(LoggerConstants.PublishTime, publishTime.GetMilliseconds() / this.TestLimits.NumberOfMessagesSent);
            this.LogMetric(LoggerConstants.Sent, this.TestLimits.NumberOfMessagesSent);
            this.LogMetric(LoggerConstants.Max, maxTime.GetMilliseconds());
            this.LogMetric(LoggerConstants.Received, this.TestLimits.NumberOfMessagesRecieved);
            if (this.TestLimits.NumberOfMessagesRecieved > 0)
            {
                this.LogMetric(LoggerConstants.Average, totalTime.GetMilliseconds() / this.TestLimits.NumberOfMessagesRecieved);
                this.LogMetric(LoggerConstants.MessagesPrSecond, this.TestLimits.NumberOfMessagesRecieved / this.TestLimits.ActualTestTime().TotalSeconds);
            }
        }