File tree Expand file tree Collapse file tree 9 files changed +157
-12
lines changed
frameworks/Python/aiohttp Expand file tree Collapse file tree 9 files changed +157
-12
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ This will switch which database engine the app uses to execute queries with test
3535
3636### Server
3737
38- gunicorn +uvloop on CPython
38+ nginx +uvloop on CPython
3939
4040## Test URLs
4141
Original file line number Diff line number Diff line change 1+ FROM python:3.13
2+
3+ ADD ./ /aiohttp
4+
5+ WORKDIR aiohttp
6+
7+ RUN pip3 install cython==3.0.11 gunicorn==23.0.0 && \
8+ pip3 install -r /aiohttp/requirements.txt
9+
10+ ENV CONNECTION=RAW
11+
12+ EXPOSE 8080
13+
14+ CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py
Original file line number Diff line number Diff line change 11FROM python:3.13
22
3- ADD ./ /aiohttp
3+ RUN apt-get update && apt-get install -y nginx
44
5- WORKDIR aiohttp
5+ ADD ./requirements.txt / aiohttp/requirements.txt
66
77RUN pip3 install cython==3.0.11 && \
88 pip3 install -r /aiohttp/requirements.txt
99
10+ ADD ./ /aiohttp
11+
1012WORKDIR /aiohttp
1113
14+ ENV CONNECTION=ORM
15+
1216EXPOSE 8080
1317
14- CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py
18+ RUN chmod +x /aiohttp/nginx-entrypoint.sh
19+
20+ ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh" ]
21+
22+
Original file line number Diff line number Diff line change 11FROM python:3.13
22
3- ADD ./ /aiohttp
3+ RUN apt-get update && apt-get install -y nginx
44
5- WORKDIR aiohttp
5+ ADD ./requirements.txt / aiohttp/requirements.txt
66
77RUN pip3 install cython==3.0.11 && \
88 pip3 install -r /aiohttp/requirements.txt
99
10+ ADD ./ /aiohttp
11+
12+ WORKDIR /aiohttp
13+
1014ENV CONNECTION=RAW
1115
1216EXPOSE 8080
1317
14- CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py
18+ RUN chmod +x /aiohttp/nginx-entrypoint.sh
19+
20+ ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh" ]
Original file line number Diff line number Diff line change 1+ import uvloop
2+ from aiohttp import web
3+ import argparse
4+ from .main import create_app
5+
6+
7+ if __name__ == '__main__' :
8+ uvloop .install ()
9+ parser = argparse .ArgumentParser ()
10+ parser .add_argument ('--socket' , type = str , required = True )
11+ args = parser .parse_args ()
12+
13+ app = create_app ()
14+ web .run_app (app , path = args .socket )
Original file line number Diff line number Diff line change 1717 "flavor" : " Python3" ,
1818 "orm" : " Raw" ,
1919 "platform" : " asyncio" ,
20- "webserver" : " gunicorn " ,
20+ "webserver" : " nginx " ,
2121 "os" : " Linux" ,
2222 "database_os" : " Linux" ,
2323 "display_name" : " aiohttp" ,
2424 "notes" : " uses asyncpg for database access"
2525 },
26+ "gunicorn" : {
27+ "json_url" : " /json" ,
28+ "db_url" : " /db" ,
29+ "query_url" : " /queries/" ,
30+ "fortune_url" : " /fortunes" ,
31+ "update_url" : " /updates/" ,
32+ "plaintext_url" : " /plaintext" ,
33+ "port" : 8080 ,
34+ "approach" : " Realistic" ,
35+ "classification" : " Micro" ,
36+ "database" : " Postgres" ,
37+ "framework" : " aiohttp" ,
38+ "language" : " Python" ,
39+ "flavor" : " Python3" ,
40+ "orm" : " Raw" ,
41+ "platform" : " asyncio" ,
42+ "webserver" : " nginx" ,
43+ "os" : " Linux" ,
44+ "database_os" : " Linux" ,
45+ "display_name" : " aiohttp-gunicorn" ,
46+ "notes" : " uses gunicorn as proxy server" ,
47+ "versus" : " default"
48+ },
2649 "orm" : {
2750 "db_url" : " /db" ,
2851 "query_url" : " /queries/" ,
3760 "flavor" : " Python3" ,
3861 "orm" : " Full" ,
3962 "platform" : " asyncio" ,
40- "webserver" : " gunicorn " ,
63+ "webserver" : " nginx " ,
4164 "os" : " Linux" ,
4265 "database_os" : " Linux" ,
4366 "display_name" : " aiohttp-orm" ,
Original file line number Diff line number Diff line change @@ -15,9 +15,26 @@ database_os = "Linux"
1515os = " Linux"
1616orm = " Raw"
1717platform = " asyncio"
18- webserver = " gunicorn "
18+ webserver = " nginx "
1919versus = " None"
2020
21+ [gunicorn ]
22+ urls.plaintext = " /plaintext"
23+ urls.json = " /json"
24+ urls.db = " /db"
25+ urls.query = " /queries/"
26+ urls.update = " /updates/"
27+ urls.fortune = " /fortunes"
28+ approach = " Realistic"
29+ classification = " Micro"
30+ database = " Postgres"
31+ database_os = " Linux"
32+ os = " Linux"
33+ orm = " Raw"
34+ platform = " asyncio"
35+ webserver = " gunicorn"
36+ versus = " default"
37+
2138[orm ]
2239urls.db = " /db"
2340urls.query = " /queries/"
@@ -30,5 +47,5 @@ database_os = "Linux"
3047os = " Linux"
3148orm = " Full"
3249platform = " asyncio"
33- webserver = " gunicorn "
50+ webserver = " nginx "
3451versus = " default"
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ set -e
3+ CORES=$( nproc)
4+ echo " $CORES cores detected, starting $CORES aiohttp workers..."
5+
6+ for i in $( seq 0 $(( CORES- 1 )) ) ; do
7+ SOCKET=" /run/aiohttp-$i .sock"
8+ echo " Starting worker on socket $SOCKET "
9+ python3 -O -m app.app --socket $SOCKET &
10+ done
11+
12+ echo " Waiting for all workers to be ready..."
13+ for i in $( seq 0 $(( CORES- 1 )) ) ; do
14+ SOCKET=" /run/aiohttp-$i .sock"
15+ until [ -S " $SOCKET " ]; do
16+ echo " Waiting for socket $SOCKET ..."
17+ sleep 0.2
18+ done
19+ chown root:www-data " $SOCKET "
20+ chmod 660 " $SOCKET "
21+ done
22+
23+ cat > /aiohttp/nginx.conf << EOF
24+ user www-data;
25+ worker_processes auto;
26+
27+ events {
28+ worker_connections 65535;
29+ }
30+
31+ http {
32+ keepalive_requests 10000000;
33+
34+ upstream aiohttp {
35+ least_conn;
36+ EOF
37+
38+ for i in $( seq 0 $(( CORES- 1 )) ) ; do
39+ echo " server unix:/run/aiohttp-$i .sock fail_timeout=0;" >> /aiohttp/nginx.conf
40+ done
41+
42+ cat >> /aiohttp/nginx.conf << EOF
43+ keepalive 32;
44+ }
45+
46+ server {
47+ listen 8080 reuseport;
48+
49+ access_log off;
50+ error_log stderr error;
51+
52+ location / {
53+ proxy_pass http://aiohttp;
54+ proxy_http_version 1.1;
55+ proxy_set_header Connection "";
56+ proxy_redirect off;
57+ proxy_buffering off;
58+ }
59+ }
60+ }
61+ EOF
62+
63+ echo " Starting Nginx..."
64+ nginx -c /aiohttp/nginx.conf -g " daemon off;"
Original file line number Diff line number Diff line change 11aiohttp == 3.11.16
22asyncpg == 0.30.0
3- gunicorn == 23.0.0
43jinja2 == 3.1.6
54SQLAlchemy == 2.0.40
65orjson == 3.10.16
You can’t perform that action at this time.
0 commit comments