Skip to content

Commit 00813fc

Browse files
committed
[aiohttp] - add raw setup (no-proxy)
1 parent 520d2bb commit 00813fc

File tree

6 files changed

+111
-16
lines changed

6 files changed

+111
-16
lines changed

Diff for: frameworks/Python/aiohttp/aiohttp-nginx.dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.13
2+
3+
ADD ./requirements.txt /aiohttp/requirements.txt
4+
5+
RUN pip3 install cython==3.0.11 && \
6+
pip3 install -r /aiohttp/requirements.txt
7+
8+
RUN apt-get update && apt-get install -y nginx
9+
10+
ADD ./ /aiohttp
11+
12+
WORKDIR /aiohttp
13+
14+
ENV CONNECTION=RAW
15+
16+
EXPOSE 8080
17+
18+
RUN chmod +x /aiohttp/nginx-entrypoint.sh
19+
20+
ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"]

Diff for: frameworks/Python/aiohttp/aiohttp-orm.dockerfile

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
FROM python:3.13
22

3-
RUN apt-get update && apt-get install -y nginx
4-
53
ADD ./requirements.txt /aiohttp/requirements.txt
64

75
RUN pip3 install cython==3.0.11 && \
@@ -15,8 +13,4 @@ ENV CONNECTION=ORM
1513

1614
EXPOSE 8080
1715

18-
RUN chmod +x /aiohttp/nginx-entrypoint.sh
19-
20-
ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"]
21-
22-
16+
CMD python3 -O -m app.server

Diff for: frameworks/Python/aiohttp/aiohttp.dockerfile

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
FROM python:3.13
22

3-
RUN apt-get update && apt-get install -y nginx
4-
53
ADD ./requirements.txt /aiohttp/requirements.txt
64

75
RUN pip3 install cython==3.0.11 && \
@@ -15,6 +13,4 @@ ENV CONNECTION=RAW
1513

1614
EXPOSE 8080
1715

18-
RUN chmod +x /aiohttp/nginx-entrypoint.sh
19-
20-
ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"]
16+
CMD python3 -O -m app.server

Diff for: frameworks/Python/aiohttp/app/server.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import socket
3+
import multiprocessing
4+
from aiohttp import web
5+
from .main import create_app
6+
import uvloop
7+
8+
SERVERS_COUNT = multiprocessing.cpu_count()
9+
BACKLOG = 2048
10+
SOCKET_BACKLOG = BACKLOG * SERVERS_COUNT
11+
12+
def start_server(sock, cpu_id):
13+
if hasattr(os, "sched_setaffinity"):
14+
os.sched_setaffinity(0, {cpu_id})
15+
uvloop.install()
16+
app = create_app()
17+
18+
web.run_app(app, sock=sock, backlog=BACKLOG, access_log=None)
19+
20+
21+
def create_reusable_socket(host='0.0.0.0', port=8080):
22+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
23+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
24+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
25+
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
26+
27+
sock.bind((host, port))
28+
sock.setblocking(False)
29+
sock.set_inheritable(True)
30+
31+
sock.listen(SOCKET_BACKLOG)
32+
33+
return sock
34+
35+
36+
if __name__ == '__main__':
37+
sock = create_reusable_socket()
38+
workers = []
39+
for cpu_id in range(SERVERS_COUNT):
40+
worker = multiprocessing.Process(target=start_server, args=(sock, cpu_id))
41+
worker.daemon = True
42+
worker.start()
43+
workers.append(worker)
44+
45+
for worker in workers:
46+
worker.join()

Diff for: frameworks/Python/aiohttp/benchmark_config.json

+24-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
"flavor": "Python3",
1818
"orm": "Raw",
1919
"platform": "asyncio",
20-
"webserver": "nginx",
20+
"webserver": "None",
2121
"os": "Linux",
2222
"database_os": "Linux",
2323
"display_name": "aiohttp",
2424
"notes": "uses asyncpg for database access"
2525
},
26-
"gunicorn": {
26+
"nginx": {
2727
"json_url": "/json",
2828
"db_url": "/db",
2929
"query_url": "/queries/",
@@ -42,6 +42,28 @@
4242
"webserver": "nginx",
4343
"os": "Linux",
4444
"database_os": "Linux",
45+
"display_name": "aiohttp-nginx",
46+
"notes": "uses nginx as proxy"
47+
},
48+
"gunicorn": {
49+
"json_url": "/json",
50+
"db_url": "/db",
51+
"query_url": "/queries/",
52+
"fortune_url": "/fortunes",
53+
"update_url": "/updates/",
54+
"plaintext_url": "/plaintext",
55+
"port": 8080,
56+
"approach": "Realistic",
57+
"classification": "Micro",
58+
"database": "Postgres",
59+
"framework": "aiohttp",
60+
"language": "Python",
61+
"flavor": "Python3",
62+
"orm": "Raw",
63+
"platform": "asyncio",
64+
"webserver": "gunicorn",
65+
"os": "Linux",
66+
"database_os": "Linux",
4567
"display_name": "aiohttp-gunicorn",
4668
"notes": "uses gunicorn as proxy server",
4769
"versus": "default"

Diff for: frameworks/Python/aiohttp/config.toml

+19-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,26 @@ database_os = "Linux"
1515
os = "Linux"
1616
orm = "Raw"
1717
platform = "asyncio"
18-
webserver = "nginx"
18+
webserver = "None"
1919
versus = "None"
2020

21+
[nginx]
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 = "nginx"
36+
versus = "default"
37+
2138
[gunicorn]
2239
urls.plaintext = "/plaintext"
2340
urls.json = "/json"
@@ -47,5 +64,5 @@ database_os = "Linux"
4764
os = "Linux"
4865
orm = "Full"
4966
platform = "asyncio"
50-
webserver = "nginx"
67+
webserver = "None"
5168
versus = "default"

0 commit comments

Comments
 (0)