diff --git a/frameworks/Python/aiohttp/README.md b/frameworks/Python/aiohttp/README.md index 280e739f8a0..f323e61a7e8 100644 --- a/frameworks/Python/aiohttp/README.md +++ b/frameworks/Python/aiohttp/README.md @@ -35,7 +35,7 @@ This will switch which database engine the app uses to execute queries with test ### Server -gunicorn+uvloop on CPython +nginx+uvloop on CPython ## Test URLs diff --git a/frameworks/Python/aiohttp/aiohttp-gunicorn.dockerfile b/frameworks/Python/aiohttp/aiohttp-gunicorn.dockerfile new file mode 100644 index 00000000000..6fb96c40f5a --- /dev/null +++ b/frameworks/Python/aiohttp/aiohttp-gunicorn.dockerfile @@ -0,0 +1,14 @@ +FROM python:3.13 + +ADD ./ /aiohttp + +WORKDIR aiohttp + +RUN pip3 install cython==3.0.11 gunicorn==23.0.0 && \ + pip3 install -r /aiohttp/requirements.txt + +ENV CONNECTION=RAW + +EXPOSE 8080 + +CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py \ No newline at end of file diff --git a/frameworks/Python/aiohttp/aiohttp-orm.dockerfile b/frameworks/Python/aiohttp/aiohttp-orm.dockerfile index fe1648e3ff4..8b9a759057f 100644 --- a/frameworks/Python/aiohttp/aiohttp-orm.dockerfile +++ b/frameworks/Python/aiohttp/aiohttp-orm.dockerfile @@ -1,14 +1,22 @@ FROM python:3.13 -ADD ./ /aiohttp +RUN apt-get update && apt-get install -y nginx -WORKDIR aiohttp +ADD ./requirements.txt /aiohttp/requirements.txt RUN pip3 install cython==3.0.11 && \ pip3 install -r /aiohttp/requirements.txt +ADD ./ /aiohttp + WORKDIR /aiohttp +ENV CONNECTION=ORM + EXPOSE 8080 -CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py +RUN chmod +x /aiohttp/nginx-entrypoint.sh + +ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"] + + diff --git a/frameworks/Python/aiohttp/aiohttp.dockerfile b/frameworks/Python/aiohttp/aiohttp.dockerfile index f6dda6f5ef5..da72d75bbab 100644 --- a/frameworks/Python/aiohttp/aiohttp.dockerfile +++ b/frameworks/Python/aiohttp/aiohttp.dockerfile @@ -1,14 +1,20 @@ FROM python:3.13 -ADD ./ /aiohttp +RUN apt-get update && apt-get install -y nginx -WORKDIR aiohttp +ADD ./requirements.txt /aiohttp/requirements.txt RUN pip3 install cython==3.0.11 && \ pip3 install -r /aiohttp/requirements.txt +ADD ./ /aiohttp + +WORKDIR /aiohttp + ENV CONNECTION=RAW EXPOSE 8080 -CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py +RUN chmod +x /aiohttp/nginx-entrypoint.sh + +ENTRYPOINT ["/aiohttp/nginx-entrypoint.sh"] \ No newline at end of file diff --git a/frameworks/Python/aiohttp/app/app.py b/frameworks/Python/aiohttp/app/app.py new file mode 100644 index 00000000000..cea253aecbb --- /dev/null +++ b/frameworks/Python/aiohttp/app/app.py @@ -0,0 +1,14 @@ +import uvloop +from aiohttp import web +import argparse +from .main import create_app + + +if __name__ == '__main__': + uvloop.install() + parser = argparse.ArgumentParser() + parser.add_argument('--socket', type=str, required=True) + args = parser.parse_args() + + app = create_app() + web.run_app(app, path=args.socket) \ No newline at end of file diff --git a/frameworks/Python/aiohttp/benchmark_config.json b/frameworks/Python/aiohttp/benchmark_config.json index ab4257e12bf..b341ad5c384 100644 --- a/frameworks/Python/aiohttp/benchmark_config.json +++ b/frameworks/Python/aiohttp/benchmark_config.json @@ -17,12 +17,35 @@ "flavor": "Python3", "orm": "Raw", "platform": "asyncio", - "webserver": "gunicorn", + "webserver": "nginx", "os": "Linux", "database_os": "Linux", "display_name": "aiohttp", "notes": "uses asyncpg for database access" }, + "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": "nginx", + "os": "Linux", + "database_os": "Linux", + "display_name": "aiohttp-gunicorn", + "notes": "uses gunicorn as proxy server", + "versus": "default" + }, "orm": { "db_url": "/db", "query_url": "/queries/", @@ -37,7 +60,7 @@ "flavor": "Python3", "orm": "Full", "platform": "asyncio", - "webserver": "gunicorn", + "webserver": "nginx", "os": "Linux", "database_os": "Linux", "display_name": "aiohttp-orm", diff --git a/frameworks/Python/aiohttp/config.toml b/frameworks/Python/aiohttp/config.toml index dd9088e497d..da12a838108 100644 --- a/frameworks/Python/aiohttp/config.toml +++ b/frameworks/Python/aiohttp/config.toml @@ -15,9 +15,26 @@ database_os = "Linux" os = "Linux" orm = "Raw" platform = "asyncio" -webserver = "gunicorn" +webserver = "nginx" versus = "None" +[gunicorn] +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 = "gunicorn" +versus = "default" + [orm] urls.db = "/db" urls.query = "/queries/" @@ -30,5 +47,5 @@ database_os = "Linux" os = "Linux" orm = "Full" platform = "asyncio" -webserver = "gunicorn" +webserver = "nginx" versus = "default" diff --git a/frameworks/Python/aiohttp/nginx-entrypoint.sh b/frameworks/Python/aiohttp/nginx-entrypoint.sh new file mode 100644 index 00000000000..8cca36df363 --- /dev/null +++ b/frameworks/Python/aiohttp/nginx-entrypoint.sh @@ -0,0 +1,64 @@ +#!/bin/sh +set -e +CORES=$(nproc) +echo "$CORES cores detected, starting $CORES aiohttp workers..." + +for i in $(seq 0 $((CORES-1))); do + SOCKET="/run/aiohttp-$i.sock" + echo "Starting worker on socket $SOCKET" + python3 -O -m app.app --socket $SOCKET & +done + +echo "Waiting for all workers to be ready..." +for i in $(seq 0 $((CORES-1))); do + SOCKET="/run/aiohttp-$i.sock" + until [ -S "$SOCKET" ]; do + echo "Waiting for socket $SOCKET..." + sleep 0.2 + done + chown root:www-data "$SOCKET" + chmod 660 "$SOCKET" +done + +cat > /aiohttp/nginx.conf <> /aiohttp/nginx.conf +done + +cat >> /aiohttp/nginx.conf <