Skip to content

Commit 9353e15

Browse files
committed
Simple gunicorn benchmark
1 parent 3b02927 commit 9353e15

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

benchmarks/gunicorn.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import json
2+
import os
3+
import requests
4+
import subprocess
5+
import sys
6+
import threading
7+
import time
8+
9+
from djangocms import waitUntilUp
10+
11+
if __name__ == "__main__":
12+
exe = sys.executable
13+
14+
times = []
15+
16+
p = subprocess.Popen([os.path.join(os.path.dirname(exe), "gunicorn"), "gunicorn_serve:main", "--bind", "127.0.0.1:8000", "-w", "1", "--worker-class", "aiohttp.GunicornWebWorker"], stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT, cwd=os.path.join(os.path.dirname(__file__), "../data"))
17+
try:
18+
waitUntilUp(("127.0.0.1", 8000))
19+
20+
n = 3000
21+
if len(sys.argv) > 1:
22+
n = int(sys.argv[1])
23+
24+
start = time.time()
25+
for i in range(n):
26+
times.append(time.time())
27+
if i % 100 == 0:
28+
print(i, time.time() - start)
29+
requests.get("http://localhost:8000/blog/").text
30+
times.append(time.time())
31+
elapsed = time.time() - start
32+
print("%.2fs (%.3freq/s)" % (elapsed, n / elapsed))
33+
34+
assert p.poll() is None, p.poll()
35+
36+
finally:
37+
p.terminate()
38+
39+
if len(sys.argv) > 2:
40+
json.dump(times, open(sys.argv[2], 'w'))

benchmarks/gunicorn_requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
aiohttp==3.7.3
2+
async-timeout==3.0.1
3+
attrs==20.3.0
4+
gunicorn==20.0.4
5+
multidict==5.1.0
6+
typing-extensions==3.7.4.3
7+
uvloop==0.14.0
8+
yarl==1.6.3

data/gunicorn_serve.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from aiohttp import web
2+
3+
async def hello(request):
4+
return web.Response(text="Hello, world")
5+
6+
async def main():
7+
app = web.Application()
8+
app.add_routes([web.get('/', hello)])
9+
return app

0 commit comments

Comments
 (0)