Beispiel #1
0
        public void GenerateOneBencharkInstance_JobParametersList_LengthIsCorrect()
        {
            IGenerationArgs generationArgsMock = Mock.Of <IGenerationArgs>(generationArgs =>
                                                                           generationArgs.NumberOfJobs == 10);

            BenchmarkInstance bi = BPMGeneratorMethods.GenerateOneBencharkInstance(generationArgsMock);

            bi.JobsList.Should().HaveCount(generationArgsMock.NumberOfJobs);
        }
Beispiel #2
0
 public BenchmarkProportionParameter(BenchmarkInstance benchmark)
     : base(
         $"{benchmark.Suite.Name}.{benchmark.Name}.Proportion",
         $"Sets execution proportion for benchmark {benchmark.Name} in suite {benchmark.Suite.Name}",
         "100"
         )
 {
     _benchmark = benchmark;
 }
Beispiel #3
0
        public void GenerateOneBencharkInstance_MachineCapacity_ValueIsCorrect()
        {
            IGenerationArgs generationArgsMock = Mock.Of <IGenerationArgs>(generationArgs =>
                                                                           generationArgs.MachineCapacity == 55);

            BenchmarkInstance bi = BPMGeneratorMethods.GenerateOneBencharkInstance(generationArgsMock);

            bi.MachineCapacity.Should().Be(generationArgsMock.MachineCapacity);
        }
Beispiel #4
0
        public void GenerateOneBencharkInstance_NumberOfJobs_ValueIsCorrect()
        {
            IGenerationArgs generationArgsMock = Mock.Of <IGenerationArgs>(generationArgs =>
                                                                           generationArgs.NumberOfJobs == 10);

            BenchmarkInstance bi = BPMGeneratorMethods.GenerateOneBencharkInstance(generationArgsMock);

            bi.NumberOfJobs.Should().Be(generationArgsMock.NumberOfJobs);
        }
 public BenchmarkSelectedParameter(BenchmarkInstance benchmark)
     : base(
         $"{benchmark.Suite.Name}.{benchmark.Name}.Selected",
         $"Selecting benchmark {benchmark.Name} in suite {benchmark.Suite.Name}",
         "true"
         )
 {
     _benchmark = benchmark;
 }
 public BenchmarkProportionParameter(BenchmarkInstance benchmark)
     : base(
         string.Format("{0}.{1}.Proportion", benchmark.Suite.Name, benchmark.Name),
         string.Format("Sets execution proportion for benchmark {0} in suite {1}", benchmark.Name, benchmark.Suite.Name),
         "100"
         )
 {
     _benchmark = benchmark;
 }
 public BenchmarkSelectedParameter(BenchmarkInstance benchmark)
     : base(
         string.Format("{0}.{1}.Selected", benchmark.Suite.Name, benchmark.Name),
         string.Format("Selecting benchmark {0} in suite {1}", benchmark.Name, benchmark.Suite.Name),
         "true"
         )
 {
     _benchmark = benchmark;
 }
        public void BenchmarkInstance_NewObjectMachineCapacity_IsCorrect()
        {
            List <JobParameters> list = new List <JobParameters>();
            var jobParametersMock     = It.IsAny <JobParameters>();

            list.Add(jobParametersMock);

            var benchmark = new BenchmarkInstance(5, 10, "Test", list);

            benchmark.MachineCapacity.Should().Be(10);
        }
        public void BenchmarkInstance_NewObjectNumberOfJobs_IsCorrect()
        {
            List <JobParameters> list = new List <JobParameters>();
            var jobParametersMock     = It.IsAny <JobParameters>();

            list.Add(jobParametersMock);

            var benchmark = new BenchmarkInstance(5, 10, "Test", list);

            benchmark.NumberOfJobs.Should().Be(5);
        }
        public void BenchmarkInstance_NewObjectJobsList_ContaintTwoObjects()
        {
            List <JobParameters> list = new List <JobParameters>();
            var jobParametersMock     = It.IsAny <JobParameters>();

            list.Add(jobParametersMock);
            list.Add(jobParametersMock);

            var benchmark = new BenchmarkInstance(5, 10, "Test", list);

            benchmark.JobsList.Should().HaveCount(2);
        }
        private void StopBenchmarkingThreads()
        {
            lock (SyncRoot)
            {
                _runningBenchmark = null;

                if (_tasks != null)
                {
                    for (int index = 0; index < _tasks.Length; index++)
                    {
                        //_tasks[index].Abort();
                        _tasks[index] = null;
                    }
                    _tasks = null;
                }
            }
        }
        private void StartBenchmarkingThreads(BenchmarkInstance benchmark)
        {
            lock (SyncRoot)
            {
                _runningBenchmark = benchmark;

                _tasks = new Task[Process.NumberOfThreads];
                for (int index = 0; index < Process.NumberOfThreads; index++)
                {
                    _tasks[index] = Task.Run(() => PerformBenchmarking(_controlTaskCancellation.Token));
                    //_tasks[index].Name = string.Format("Benchmarking Thread #{0}/{1}", index, Process.NumberOfThreads);
                    //_tasks[index].Priority = ThreadPriority.Highest;
                    //_tasks[index].Start();
                }

                //Task.WaitAll(_tasks);
            }
        }
        private void Execute(CancellationToken token)
        {
            int lastExecutedTicks           = System.Environment.TickCount;
            int benchmarkCount              = _activeBenchmarks.Count;
            BenchmarkInstance onlyBenchmark = benchmarkCount == 1
                ? _activeBenchmarks[0]
                : null;

            try
            {
                while (_running && !token.IsCancellationRequested)
                {
                    if (_configuration.MeasurementType == MeasurementType.Nominal)
                    {
                        double ticksToNextTransaction = _ticksPerTransaction
                                                        - (System.Environment.TickCount - lastExecutedTicks);

                        // Wait to ensure nominal transaction rate
                        if (ticksToNextTransaction > 0)
                        {
                            Thread.Sleep((int)ticksToNextTransaction);
                        }
                    }

                    var benchmark = onlyBenchmark ?? ChooseBenchmarkProportionally();

                    if (benchmark != null)
                    {
                        ExecuteBenchmark(benchmark);
                        lastExecutedTicks = System.Environment.TickCount;
                        _aggregator.IncrementCounter(1, lastExecutedTicks);
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // Ignore the exception...
            }
        }
        protected void ExecuteBenchmark(BenchmarkInstance benchmark)
        {
            try
            {
                benchmark.Execute();
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ReportError(ex.Message);

                if (!Process.IsForceContinue)
                {
                    throw ex;
                }
            }
        }
        private void ExecuteBenchmark(BenchmarkInstance benchmark)
        {
            try
            {
                benchmark.Execute();
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _results.NotifyError(ex);

                if (!_configuration.ForceContinue)
                {
                    throw;
                }
            }
        }
        private void PerformBenchmarking(CancellationToken token)
        {
            BenchmarkInstance benchmark = _runningBenchmark;
            int lastExecutedTicks       = System.Environment.TickCount;
            int endTicks = System.Environment.TickCount + Process.Duration;

            try
            {
                int currentTicks = System.Environment.TickCount;

                while (_running && benchmark == _runningBenchmark && endTicks > currentTicks)
                {
                    if (Process.MeasurementType == MeasurementType.Nominal)
                    {
                        double ticksToNextTransaction = _ticksPerTransaction
                                                        - (currentTicks - lastExecutedTicks);

                        // Wait to ensure nominal transaction rate
                        if (ticksToNextTransaction > 0)
                        {
                            Thread.Sleep((int)ticksToNextTransaction);
                        }
                    }

                    lastExecutedTicks = currentTicks;
                    ExecuteBenchmark(benchmark);
                    currentTicks = System.Environment.TickCount;
                    IncrementCounter(1, lastExecutedTicks);

                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // Ignore the exception...
            }
        }
        private void PerformBenchmarking(CancellationToken token)
        {
            System.Random     randomGenerator   = new System.Random();
            int               lastExecutedTicks = System.Environment.TickCount;
            int               numberOfTests     = Benchmarks.Count;
            BenchmarkInstance firstBenchmark    = Benchmarks.Count == 1 ? Benchmarks[0] : null;

            NotifyResultUpdate(ExecutionState.Starting);

            try
            {
                while (_running)
                {
                    if (Process.MeasurementType == MeasurementType.Nominal)
                    {
                        double ticksToNextTransaction = _ticksPerTransaction
                                                        - (System.Environment.TickCount - lastExecutedTicks);

                        // Wait to ensure nominal transaction rate
                        if (ticksToNextTransaction > 0)
                        {
                            Thread.Sleep((int)ticksToNextTransaction);
                        }
                    }

                    if (numberOfTests == 1)
                    {
                        ExecuteBenchmark(firstBenchmark);
                        lastExecutedTicks = System.Environment.TickCount;
                        IncrementCounter(1, lastExecutedTicks);
                    }
                    else if (numberOfTests == 0)
                    {
                        Thread.Sleep(500);
                    }
                    else
                    {
                        double selector = randomGenerator.NextDouble();
                        for (int index = 0; index < Benchmarks.Count; index++)
                        {
                            var benchmark = Benchmarks[index];
                            if (benchmark.IsTriggered(selector))
                            {
                                lastExecutedTicks = System.Environment.TickCount;
                                ExecuteBenchmark(benchmark);
                                IncrementCounter(1, lastExecutedTicks);
                                break;
                            }
                        }
                    }

                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // Ignore the exception...
            }
            finally
            {
                NotifyResultUpdate(ExecutionState.Completed);
            }
        }