private void Display()
        {
            Cursor = Cursors.WaitCursor;

            var distribution = new PoissonDistribution().GetNormalizedValues(_threadCount);

            // Get the time delta between each sample point.
            var delta = TimeSpan.FromTicks(_duration.Ticks / (distribution.Count() - 1));

            _barSeries.DataPoints.Clear();

            for (int i = 0; i < distribution.Count(); i++)
            {
                var time      = TimeSpan.FromSeconds(delta.TotalSeconds * i);
                var dataPoint = new CategoricalDataPoint(distribution.ElementAt(i), time.ToString(@"hh\:mm\:ss"));
                _barSeries.DataPoints.Add(dataPoint);
            }

            Cursor = Cursors.Default;
        }
Ejemplo n.º 2
0
        private void StartPoissonHandler(LoadTesterMetadataDetail metadataDetail)
        {
            var plan = metadataDetail.Plan as LoadTesterExecutionPlan;

            var duration = TimeSpan.FromMinutes(plan.DurationTime);


            var distribution = new PoissonDistribution().GetNormalizedValues(plan.ThreadCount);

            if (distribution.Count() == 0)
            {
                TraceFactory.Logger.Debug("NO TASKS TO RUN");
                SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Completed);
                return;
            }

            // Get the time delta between each sample point.
            var delta = TimeSpan.FromTicks(duration.Ticks / (distribution.Count() - 1));

            TraceFactory.Logger.Debug("Time Delta {0}".FormatWith(delta));

            // Change the plan to support the Poisson settings.  This will create
            // each Task with a shorter execution time and will only create a
            // DurationBased execution engine.
            plan.DurationTime = (int)delta.TotalMinutes;
            plan.Mode         = ExecutionMode.Duration;

            foreach (int threadCount in distribution)
            {
                // Create all the threads that will be used.
                for (int i = 0; i < threadCount; i++)
                {
                    // There is now ramp up delay with a Poisson thread
                    _threads.Add(new LoadTestThread(metadataDetail, TimeSpan.Zero));
                }

                // Start each thread for this segment
                TraceFactory.Logger.Debug("Created {0} Tasks, now starting them...".FormatWith(threadCount));
                foreach (var thread in _threads)
                {
                    thread.Task.Start();
                }

                TraceFactory.Logger.Debug("{0} Tasks started, waiting for them to complete".FormatWith(threadCount));

                // Wait for all the current threads to complete.
                Task.WaitAll(_threads.Select(x => x.Task).ToArray());

                // Clean up the completed threads
                TraceFactory.Logger.Debug("{0} Tasks completed, disposing and clearing list".FormatWith(threadCount));
                foreach (var thread in _threads)
                {
                    thread.Dispose();
                }

                _threads.Clear();
            }

            TraceFactory.Logger.Debug("ALL TASKS COMPLETE");
            SessionProxyBackendConnection.ChangeResourceState(RuntimeState.Completed);
        }