Created
May 16, 2012 14:16
-
-
Save ahall/2710678 to your computer and use it in GitHub Desktop.
Async vs Sync for servicestack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code first | |
using System; | |
using ServiceStack.WebHost.Endpoints; | |
using System.Threading; | |
using ServiceStack.ServiceInterface; | |
using System.Threading.Tasks; | |
namespace ServiceStackBench | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
string listeningOn = "http://127.0.0.1:53211/"; | |
var appHost = new AppHost(); | |
appHost.Init(); | |
appHost.Start(listeningOn); | |
Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, listeningOn); | |
Thread.Sleep(Timeout.Infinite); | |
Console.ReadLine(); | |
} | |
} | |
public class AsyncDto | |
{ | |
} | |
public class AsyncDtoResponse | |
{ | |
public string Message { get; set; } | |
} | |
public class SyncDto | |
{ | |
} | |
public class SyncDtoResponse | |
{ | |
public string Message { get; set; } | |
} | |
public class AsyncService : RestServiceBase<AsyncDto> | |
{ | |
public override object OnGet(AsyncDto request) | |
{ | |
return Task.Factory.StartNew<AsyncDtoResponse>(() => | |
{ | |
return new AsyncDtoResponse { Message = "This was async!" }; | |
}); | |
} | |
} | |
public class SyncService : RestServiceBase<SyncDto> | |
{ | |
public override object OnGet(SyncDto request) | |
{ | |
return new AsyncDtoResponse { Message = "This was sync!" }; | |
} | |
} | |
public class AppHost : AppHostHttpListenerBase | |
{ | |
public AppHost() : base("ServiceStackBench", typeof(SyncService).Assembly) | |
{ | |
} | |
public override void Configure(Funq.Container container) | |
{ | |
Routes.Add<SyncDto>("/sync") | |
.Add<AsyncDto>("/async"); | |
} | |
} | |
} | |
// Results sync | |
ahall@jetsam:~$ ab -c 5 -n 2000 "http://127.0.0.1:53211/sync?format=json" | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 200 requests | |
Completed 400 requests | |
Completed 600 requests | |
Completed 800 requests | |
Completed 1000 requests | |
Completed 1200 requests | |
Completed 1400 requests | |
Completed 1600 requests | |
Completed 1800 requests | |
Completed 2000 requests | |
Finished 2000 requests | |
Server Software: Mono-HTTPAPI/1.0 | |
Server Hostname: 127.0.0.1 | |
Server Port: 53211 | |
Document Path: /sync?format=json | |
Document Length: 28 bytes | |
Concurrency Level: 5 | |
Time taken for tests: 1.086 seconds | |
Complete requests: 2000 | |
Failed requests: 0 | |
Write errors: 0 | |
Total transferred: 438000 bytes | |
HTML transferred: 56000 bytes | |
Requests per second: 1842.34 [#/sec] (mean) | |
Time per request: 2.714 [ms] (mean) | |
Time per request: 0.543 [ms] (mean, across all concurrent requests) | |
Transfer rate: 394.02 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 0 0.1 0 2 | |
Processing: 1 3 1.3 2 11 | |
Waiting: 0 2 1.3 2 11 | |
Total: 1 3 1.3 2 12 | |
Percentage of the requests served within a certain time (ms) | |
50% 2 | |
66% 3 | |
75% 3 | |
80% 3 | |
90% 4 | |
95% 5 | |
98% 7 | |
99% 9 | |
100% 12 (longest request) | |
// Results async | |
ahall@jetsam:~$ ab -c 5 -n 2000 "http://127.0.0.1:53211/async?format=json" | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 200 requests | |
Completed 400 requests | |
Completed 600 requests | |
Completed 800 requests | |
Completed 1000 requests | |
Completed 1200 requests | |
Completed 1400 requests | |
Completed 1600 requests | |
Completed 1800 requests | |
Completed 2000 requests | |
Finished 2000 requests | |
Server Software: Mono-HTTPAPI/1.0 | |
Server Hostname: 127.0.0.1 | |
Server Port: 53211 | |
Document Path: /async?format=json | |
Document Length: 153 bytes | |
Concurrency Level: 5 | |
Time taken for tests: 1.679 seconds | |
Complete requests: 2000 | |
Failed requests: 0 | |
Write errors: 0 | |
Total transferred: 688000 bytes | |
HTML transferred: 306000 bytes | |
Requests per second: 1191.28 [#/sec] (mean) | |
Time per request: 4.197 [ms] (mean) | |
Time per request: 0.839 [ms] (mean, across all concurrent requests) | |
Transfer rate: 400.20 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 0 0.0 0 0 | |
Processing: 1 4 24.9 2 500 | |
Waiting: 1 4 24.9 2 500 | |
Total: 1 4 24.9 2 500 | |
Percentage of the requests served within a certain time (ms) | |
50% 2 | |
66% 2 | |
75% 2 | |
80% 3 | |
90% 4 | |
95% 4 | |
98% 5 | |
99% 6 | |
100% 500 (longest request) | |
// Async with 200 ms timeout | |
ahall@jetsam:~$ ab -c 5 -n 2000 "http://127.0.0.1:53211/async?format=json" | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 200 requests | |
Completed 400 requests | |
Completed 600 requests | |
Completed 800 requests | |
Completed 1000 requests | |
Completed 1200 requests | |
Completed 1400 requests | |
Completed 1600 requests | |
Completed 1800 requests | |
Completed 2000 requests | |
Finished 2000 requests | |
Server Software: Mono-HTTPAPI/1.0 | |
Server Hostname: 127.0.0.1 | |
Server Port: 53211 | |
Document Path: /async?format=json | |
Document Length: 150 bytes | |
Concurrency Level: 5 | |
Time taken for tests: 82.372 seconds | |
Complete requests: 2000 | |
Failed requests: 1990 | |
(Connect: 0, Receive: 0, Length: 1990, Exceptions: 0) | |
Write errors: 0 | |
Total transferred: 686890 bytes | |
HTML transferred: 304890 bytes | |
Requests per second: 24.28 [#/sec] (mean) | |
Time per request: 205.929 [ms] (mean) | |
Time per request: 41.186 [ms] (mean, across all concurrent requests) | |
Transfer rate: 8.14 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 0 0.1 0 3 | |
Processing: 201 206 41.3 201 1097 | |
Waiting: 201 206 41.2 201 1097 | |
Total: 201 206 41.3 201 1097 | |
Percentage of the requests served within a certain time (ms) | |
50% 201 | |
66% 201 | |
75% 201 | |
80% 202 | |
90% 203 | |
95% 204 | |
98% 265 | |
99% 300 | |
100% 1097 (longest request) | |
// Sync with 200 ms timeout | |
ahall@jetsam:~$ ab -c 5 -n 2000 "http://127.0.0.1:53211/sync?format=json" | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 200 requests | |
Completed 400 requests | |
Completed 600 requests | |
Completed 800 requests | |
Completed 1000 requests | |
Completed 1200 requests | |
Completed 1400 requests | |
Completed 1600 requests | |
Completed 1800 requests | |
Completed 2000 requests | |
Finished 2000 requests | |
Server Software: Mono-HTTPAPI/1.0 | |
Server Hostname: 127.0.0.1 | |
Server Port: 53211 | |
Document Path: /sync?format=json | |
Document Length: 28 bytes | |
Concurrency Level: 5 | |
Time taken for tests: 84.087 seconds | |
Complete requests: 2000 | |
Failed requests: 0 | |
Write errors: 0 | |
Total transferred: 438000 bytes | |
HTML transferred: 56000 bytes | |
Requests per second: 23.78 [#/sec] (mean) | |
Time per request: 210.217 [ms] (mean) | |
Time per request: 42.043 [ms] (mean, across all concurrent requests) | |
Transfer rate: 5.09 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 0 0.1 0 3 | |
Processing: 201 210 37.2 201 929 | |
Waiting: 201 210 37.2 201 929 | |
Total: 201 210 37.2 201 929 | |
Percentage of the requests served within a certain time (ms) | |
50% 201 | |
66% 201 | |
75% 202 | |
80% 203 | |
90% 230 | |
95% 262 | |
98% 294 | |
99% 306 | |
100% 929 (longest request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment