Skip to content

Instantly share code, notes, and snippets.

@ssut

ssut/aio.py Secret

Created Jul 25, 2015
Embed
What would you like to do?
import asyncio
from aiohttp import web
@asyncio.coroutine
def handle(request):
return web.Response(body=b"Hello, Python!")
@asyncio.coroutine
def init(loop):
app = web.Application(loop=loop)
app.router.add_route('GET', '/', handle)
srv = yield from loop.create_server(app.make_handler(),
'127.0.0.1', 24689)
print("Server started at http://127.0.0.1:24689")
return srv
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
loop.run_forever()
sudo ab -n 10000 -c 100 http://127.0.0.1:24689/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 24689
Document Path: /
Document Length: 14 bytes
Concurrency Level: 100
Time taken for tests: 7.877 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1440000 bytes
HTML transferred: 140000 bytes
Requests per second: 1269.59 [#/sec] (mean)
Time per request: 78.766 [ms] (mean)
Time per request: 0.788 [ms] (mean, across all concurrent requests)
Transfer rate: 178.54 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 13.8 0 75
Processing: 3 73 11.1 73 105
Waiting: 2 73 11.1 73 105
Total: 7 78 11.9 77 127
Percentage of the requests served within a certain time (ms)
50% 77
66% 81
75% 84
80% 87
90% 96
95% 101
98% 105
99% 107
100% 127 (longest request)
#!/usr/bin/python
"""WSGI server example"""
from __future__ import print_function
from gevent.pywsgi import WSGIServer
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [b"Hello Python!"]
if __name__ == '__main__':
print('Serving on 24688...')
WSGIServer(('', 24688), application, log=None).serve_forever()
sudo ab -n 10000 -c 100 http://127.0.0.1:24688/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 24688
Document Path: /
Document Length: 13 bytes
Concurrency Level: 100
Time taken for tests: 16.124 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1340000 bytes
HTML transferred: 130000 bytes
Requests per second: 620.19 [#/sec] (mean)
Time per request: 161.241 [ms] (mean)
Time per request: 1.612 [ms] (mean, across all concurrent requests)
Transfer rate: 81.16 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 79 23.4 77 252
Processing: 1 80 24.1 78 255
Waiting: 1 77 24.1 76 254
Total: 69 159 41.1 159 362
Percentage of the requests served within a certain time (ms)
50% 159
66% 171
75% 187
80% 196
90% 206
95% 216
98% 238
99% 261
100% 362 (longest request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment