private static void Hello10000MultiThreading(ILog log, IHelloService helloClient, int totalCalls, int threadCount) { log.DebugFormat("Hello10000MultiThreading, TotalCalls[{0}], ThreadCount[{1}], start ...", totalCalls, threadCount); var taskList = new Task[threadCount]; var watch = Stopwatch.StartNew(); for (int i = 0; i < threadCount; i++) { var task = Task.Factory.StartNew(() => { for (var j = 0; j < totalCalls / threadCount; j++) { helloClient.Hello10000(new Hello10000Request() { Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff") }); } }, TaskCreationOptions.PreferFairness); taskList[i] = task; } Task.WaitAll(taskList); watch.Stop(); log.DebugFormat("Hello10000MultiThreading, TotalCalls[{0}], ThreadCount[{1}], end with cost [{2}] ms." + "{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}", totalCalls, threadCount, watch.ElapsedMilliseconds, Environment.NewLine, string.Format(" Concurrency level: {0} threads", threadCount), Environment.NewLine, string.Format(" Complete requests: {0}", totalCalls), Environment.NewLine, string.Format("Time taken for tests: {0} seconds", (decimal)watch.ElapsedMilliseconds / 1000m), Environment.NewLine, string.Format(" Time per request: {0:#####0.000} ms (avg)", (decimal)watch.ElapsedMilliseconds / (decimal)totalCalls), Environment.NewLine, string.Format(" Requests per second: {0} [#/sec] (avg)", (int)((decimal)totalCalls / ((decimal)watch.ElapsedMilliseconds / 1000m))) ); }
private static void Hello10000(ILog log, IHelloService helloClient) { log.DebugFormat("Hello10000, start ..."); var watch = Stopwatch.StartNew(); for (var i = 0; i < 10000; i++) { helloClient.Hello10000(new Hello10000Request() { Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff") }); } watch.Stop(); log.DebugFormat("Hello10000, end with cost {0} ms.", watch.ElapsedMilliseconds); }
public TestModule(IHelloService helloService, ICalcService calcService) { _helloService = helloService; _calcService = calcService; Get("/empty", x => { return(string.Empty); }); Get("/time", x => { return(DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff")); }); Get("/hello", x => { var response = _helloService.Hello(new HelloRequest() { Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff") }); return(response == null ? string.Empty : response.Text); }); Get("/hello10000", x => { var response = _helloService.Hello10000(new Hello10000Request() { Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff") }); return(response == null ? string.Empty : response.Text); }); Get("/add", x => { var response = _calcService.Add(new AddRequest() { X = 1, Y = 2 }); return(string.Format("Result = {0}, Time = {1}", response.Result.ToString(), DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff"))); }); }