Skip to content

Instantly share code, notes, and snippets.

@menghan
Created August 27, 2013 10:39
Show Gist options
  • Select an option

  • Save menghan/6352011 to your computer and use it in GitHub Desktop.

Select an option

Save menghan/6352011 to your computer and use it in GitHub Desktop.
import time
import gevent
request_times = []
def calc_response_time(func):
def _(env, start_response):
t = time.time()
r = func(env, start_response)
request_times.append(time.time() - t)
return r
return _
@calc_response_time
def _real(env, start_response):
response = 'pong'
start_response('200 OK', [('Content-Type', 'text/plain'), ('Content-Length', str(len(response)))])
return [response]
def application(env, start_response):
return _real(env, start_response)
def print_request_times():
global request_times
while True:
if request_times:
print '%.6fms' % (1000.0 * sum(request_times) / len(request_times)), len(request_times)
request_times = []
gevent.sleep(1)
gevent.spawn(print_request_times)
(gunicorn)menghan@khand9:~$ gunicorn --worker-class gevent --workers 1 application
2013-08-27 18:36:46 [25021] [INFO] Starting gunicorn 17.5
2013-08-27 18:36:46 [25021] [INFO] Listening at: http://127.0.0.1:8000 (25021)
2013-08-27 18:36:46 [25021] [INFO] Using worker: gevent
2013-08-27 18:36:46 [25034] [INFO] Booting worker with pid: 25034
0.023057ms 1216
0.022374ms 1344
0.022169ms 1472
0.022160ms 968
(gunicorn)menghan@khand9:~$ ab -n 5000 -c 64 http://127.0.0.1:8000/
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 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software: gunicorn/17.5
Server Hostname: 127.0.0.1
Server Port: 8000
Document Path: /
Document Length: 4 bytes
Concurrency Level: 64
Time taken for tests: 3.565 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 735000 bytes
HTML transferred: 20000 bytes
Requests per second: 1402.47 [#/sec] (mean)
Time per request: 45.634 [ms] (mean)
Time per request: 0.713 [ms] (mean, across all concurrent requests)
Transfer rate: 201.33 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 3
Processing: 3 45 4.2 44 52
Waiting: 3 45 4.2 44 52
Total: 6 45 4.0 44 52
Percentage of the requests served within a certain time (ms)
50% 44
66% 49
75% 49
80% 49
90% 49
95% 49
98% 51
99% 52
100% 52 (longest request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment