Browse Source

[aiohttp] - add raw setup (no-proxy) (#9807)

Sergey Kovalev 3 months ago
parent
commit
21caa53ddd

+ 20 - 0
frameworks/Python/aiohttp/aiohttp-nginx.dockerfile

@@ -0,0 +1,20 @@
+FROM python:3.13
+
+ADD ./requirements.txt /aiohttp/requirements.txt
+
+RUN pip3 install cython==3.0.11 && \
+    pip3 install -r /aiohttp/requirements.txt
+
+RUN apt-get update && apt-get install -y nginx
+
+ADD ./ /aiohttp
+
+WORKDIR /aiohttp
+
+ENV CONNECTION=RAW
+
+EXPOSE 8080
+
+RUN chmod +x /aiohttp/nginx-entrypoint.sh
+
+ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"]

+ 1 - 7
frameworks/Python/aiohttp/aiohttp-orm.dockerfile

@@ -1,7 +1,5 @@
 FROM python:3.13
 FROM python:3.13
 
 
-RUN apt-get update && apt-get install -y nginx
-
 ADD ./requirements.txt /aiohttp/requirements.txt
 ADD ./requirements.txt /aiohttp/requirements.txt
 
 
 RUN pip3 install cython==3.0.11 && \
 RUN pip3 install cython==3.0.11 && \
@@ -15,8 +13,4 @@ ENV CONNECTION=ORM
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-RUN chmod +x /aiohttp/nginx-entrypoint.sh
-
-ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"]
-
-
+CMD python3 -O -m app.server

+ 1 - 5
frameworks/Python/aiohttp/aiohttp.dockerfile

@@ -1,7 +1,5 @@
 FROM python:3.13
 FROM python:3.13
 
 
-RUN apt-get update && apt-get install -y nginx
-
 ADD ./requirements.txt /aiohttp/requirements.txt
 ADD ./requirements.txt /aiohttp/requirements.txt
 
 
 RUN pip3 install cython==3.0.11 && \
 RUN pip3 install cython==3.0.11 && \
@@ -15,6 +13,4 @@ ENV CONNECTION=RAW
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-RUN chmod +x /aiohttp/nginx-entrypoint.sh
-
-ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"]
+CMD python3 -O -m app.server

+ 46 - 0
frameworks/Python/aiohttp/app/server.py

@@ -0,0 +1,46 @@
+import os
+import socket
+import multiprocessing
+from aiohttp import web
+from .main import create_app
+import uvloop
+
+SERVERS_COUNT = multiprocessing.cpu_count()
+BACKLOG = 2048
+SOCKET_BACKLOG = BACKLOG * SERVERS_COUNT
+
+def start_server(sock, cpu_id):
+    if hasattr(os, "sched_setaffinity"):
+        os.sched_setaffinity(0, {cpu_id})
+    uvloop.install()
+    app = create_app()
+
+    web.run_app(app, sock=sock, backlog=BACKLOG, access_log=None)
+
+
+def create_reusable_socket(host='0.0.0.0', port=8080):
+    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
+    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+
+    sock.bind((host, port))
+    sock.setblocking(False)
+    sock.set_inheritable(True)
+
+    sock.listen(SOCKET_BACKLOG)
+
+    return sock
+
+
+if __name__ == '__main__':
+    sock = create_reusable_socket()
+    workers = []
+    for cpu_id in range(SERVERS_COUNT):
+        worker = multiprocessing.Process(target=start_server, args=(sock, cpu_id))
+        worker.daemon = True
+        worker.start()
+        workers.append(worker)
+
+    for worker in workers:
+        worker.join()

+ 25 - 3
frameworks/Python/aiohttp/benchmark_config.json

@@ -17,13 +17,13 @@
       "flavor": "Python3",
       "flavor": "Python3",
       "orm": "Raw",
       "orm": "Raw",
       "platform": "asyncio",
       "platform": "asyncio",
-      "webserver": "nginx",
+      "webserver": "None",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
       "display_name": "aiohttp",
       "display_name": "aiohttp",
       "notes": "uses asyncpg for database access"
       "notes": "uses asyncpg for database access"
     },
     },
-    "gunicorn": {
+    "nginx": {
       "json_url": "/json",
       "json_url": "/json",
       "db_url": "/db",
       "db_url": "/db",
       "query_url": "/queries/",
       "query_url": "/queries/",
@@ -42,6 +42,28 @@
       "webserver": "nginx",
       "webserver": "nginx",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
+      "display_name": "aiohttp-nginx",
+      "notes": "uses nginx as proxy"
+    },
+    "gunicorn": {
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries/",
+      "fortune_url": "/fortunes",
+      "update_url": "/updates/",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "Postgres",
+      "framework": "aiohttp",
+      "language": "Python",
+      "flavor": "Python3",
+      "orm": "Raw",
+      "platform": "asyncio",
+      "webserver": "gunicorn",
+      "os": "Linux",
+      "database_os": "Linux",
       "display_name": "aiohttp-gunicorn",
       "display_name": "aiohttp-gunicorn",
       "notes": "uses gunicorn as proxy server",
       "notes": "uses gunicorn as proxy server",
       "versus": "default"
       "versus": "default"
@@ -60,7 +82,7 @@
       "flavor": "Python3",
       "flavor": "Python3",
       "orm": "Full",
       "orm": "Full",
       "platform": "asyncio",
       "platform": "asyncio",
-      "webserver": "nginx",
+      "webserver": "None",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
       "display_name": "aiohttp-orm",
       "display_name": "aiohttp-orm",

+ 19 - 2
frameworks/Python/aiohttp/config.toml

@@ -15,9 +15,26 @@ database_os = "Linux"
 os = "Linux"
 os = "Linux"
 orm = "Raw"
 orm = "Raw"
 platform = "asyncio"
 platform = "asyncio"
-webserver = "nginx"
+webserver = "None"
 versus = "None"
 versus = "None"
 
 
+[nginx]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+urls.db = "/db"
+urls.query = "/queries/"
+urls.update = "/updates/"
+urls.fortune = "/fortunes"
+approach = "Realistic"
+classification = "Micro"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = "asyncio"
+webserver = "nginx"
+versus = "default"
+
 [gunicorn]
 [gunicorn]
 urls.plaintext = "/plaintext"
 urls.plaintext = "/plaintext"
 urls.json = "/json"
 urls.json = "/json"
@@ -47,5 +64,5 @@ database_os = "Linux"
 os = "Linux"
 os = "Linux"
 orm = "Full"
 orm = "Full"
 platform = "asyncio"
 platform = "asyncio"
-webserver = "nginx"
+webserver = "None"
 versus = "default"
 versus = "default"