Пример #1
0
        public async Task <List <BenchMarkResult> > RunBenchMarksAsync(IEnumerable <BenchMarkType> benchMarkTypes, int coldCalls = 5, int warmCalls = 10, int delayBetweenCalls = 30)
        {
            var results = new List <BenchMarkResult>();

            foreach (var benchMarkType in benchMarkTypes)
            {
                var tasksCold = new List <Task <BenchMarkResponse> >();
                var tasksWarm = new List <Task <BenchMarkResponse> >();

                for (int i = 0; i < coldCalls; i++)
                {
                    tasksCold.Add(_benchMarkService.RunBenchMarkAsync(benchMarkType.ClientName));
                }

                await Task.WhenAll(tasksCold);

                await Task.Delay(TimeSpan.FromSeconds(delayBetweenCalls));

                for (int i = 0; i < warmCalls; i++)
                {
                    tasksWarm.Add(_benchMarkService.RunBenchMarkAsync(benchMarkType.ClientName));
                }

                await Task.WhenAll(tasksWarm);

                results.AddRange(ResultConverter.ConvertToResultObject(tasksCold.Select(t => t.Result), benchMarkType, true));
                results.AddRange(ResultConverter.ConvertToResultObject(tasksWarm.Select(t => t.Result), benchMarkType, false));
            }
            return(results);
        }
Пример #2
0
        public async Task Run([TimerTrigger("0 0 */1 * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.UtcNow}");

            var benchMarkTypes = BenchMarkTypeGenerator.Generate();

            foreach (var benchMarkType in benchMarkTypes)
            {
                var tasksCold = new List <Task <BenchMarkResponse> >();
                var tasksWarm = new List <Task <BenchMarkResponse> >();

                for (int i = 0; i < 5; i++)
                {
                    tasksCold.Add(_benchMarkService.RunBenchMark(benchMarkType));
                }

                await Task.WhenAll(tasksCold);

                await Task.Delay(TimeSpan.FromSeconds(30));

                for (int i = 0; i < 10; i++)
                {
                    tasksWarm.Add(_benchMarkService.RunBenchMark(benchMarkType));
                }

                await Task.WhenAll(tasksWarm);

                var resultsCold =
                    ResultConverter.ConvertToResultObject(tasksCold.Select(t => t.Result), benchMarkType, true);

                var resultWarm =
                    ResultConverter.ConvertToResultObject(tasksWarm.Select(t => t.Result), benchMarkType, false);


                using (var dbContext =
                           BenchMarkDbContextFactory.Create(Environment.GetEnvironmentVariable("BenchMarkDatabase")))
                {
                    foreach (var result in resultsCold)
                    {
                        dbContext.BenchMarkResult.Add(result);
                    }

                    foreach (var result in resultWarm)
                    {
                        dbContext.BenchMarkResult.Add(result);
                    }


                    await dbContext.SaveChangesAsync();
                }
            }
        }