public static HttpClient CreateBenchMarkClient(this IHttpClientFactory httpClientFactory,
                                                       BenchMarkType benchMarkType)
        {
            switch (benchMarkType.CloudProvider)
            {
            case CloudProvider.Azure when benchMarkType.HostEnvironment == HostEnvironment.Windows &&
                benchMarkType.Runtime == Runtime.Csharp:
                return(httpClientFactory.CreateClient("AzureWindowsCsharpClient"));

            case CloudProvider.Azure when benchMarkType.HostEnvironment == HostEnvironment.Linux &&
                benchMarkType.Runtime == Runtime.Csharp:
                return(httpClientFactory.CreateClient("AzureLinuxCsharpClient"));

            case CloudProvider.Azure when benchMarkType.HostEnvironment == HostEnvironment.Windows &&
                benchMarkType.Runtime == Runtime.Nodejs:
                return(httpClientFactory.CreateClient("AzureWindowsNodejsClient"));

            case CloudProvider.Azure when benchMarkType.HostEnvironment == HostEnvironment.Linux &&
                benchMarkType.Runtime == Runtime.Nodejs:
                return(httpClientFactory.CreateClient("AzureLinuxNodejsClient"));

            default:
                throw new ArgumentOutOfRangeException(nameof(benchMarkType));
            }
        }
Beispiel #2
0
 public static IEnumerable <BenchMarkResult> ConvertToResultObject(
     IEnumerable <BenchMarkResponse> benchMarkResponses,
     BenchMarkType benchMarkType, bool isColdRequest)
 {
     return(benchMarkResponses.Select(benchMarkResponse => new BenchMarkResult
     {
         CloudProvider = (int)benchMarkType.CloudProvider,
         HostingEnvironment = (int)benchMarkType.HostEnvironment,
         Runtime = (int)benchMarkType.Runtime,
         Success = benchMarkResponse.Success,
         RequestDuration = Convert.ToInt32(benchMarkResponse.Duration),
         IsColdRequest = isColdRequest
     }).ToList());
 }
        public async Task <BenchMarkResponse> RunBenchMark(BenchMarkType benchMarkType)
        {
            var  client = _httpClientFactory.CreateBenchMarkClient(benchMarkType);
            long result = 0;

            try
            {
                var stopWatch = Stopwatch.StartNew();
                var response  = await client.GetAsync($"api/Trigger?name=BenchMark");

                result = stopWatch.ElapsedMilliseconds;

                return(response.IsSuccessStatusCode
                    ? new BenchMarkResponse(true, result)
                    : new BenchMarkResponse(false, result));
            }
            catch (Exception e)
            {
                return(new BenchMarkResponse(false, result));
            }
        }