ソースを参照

[Python] Add Emmett using socketify.py ASGI (#7765)

* Added a benchmark test for the socketify.py Python/PyPy web framework

* removed alpine docker

* updated readme.md

* No need to manually add Date header anymore on Socketify.py

* updated socketify.py benchmark to use object factories to increase performance

* add object factory to app-python3.py in socketify

* [Python] Update socketify.py with ASGI and SSGI, add Falcon ASGI SSGI with socketify.py

* fix merge erros

* remove \n from plaintext in socketify.py-wsgi plaintext

* [Python] add Emmett socketify ASGI server
Ciro Spaciari 2 年 前
コミット
2d67defbb1

+ 45 - 0
frameworks/Python/emmett/app-socketify-asgi.py

@@ -0,0 +1,45 @@
+import os
+import multiprocessing
+import logging
+from socketify import ASGI
+from emmett import App
+from emmett.tools import service
+
+app = App(__name__)
+
+
+app.config.handle_static = False
+
[email protected]()
[email protected]
+async def json():
+    return {'message': 'Hello, World!'}
+
[email protected](output='bytes')
+async def plaintext():
+    return b'Hello, World!'
+
+
+
+_is_travis = os.environ.get('TRAVIS') == 'true'
+
+workers = int(multiprocessing.cpu_count())
+if _is_travis:
+    workers = 2
+
+def run_app():
+    ASGI(app).listen(8080, lambda config: logging.info(f"Listening on port http://localhost:{config.port} now\n")).run()
+
+
+def create_fork():
+    n = os.fork()
+    # n greater than 0 means parent process
+    if not n > 0:
+        run_app()
+
+
+# fork limiting the cpu count - 1
+for i in range(1, workers):
+    create_fork()
+
+run_app()  # run app on the main process too :)

+ 38 - 0
frameworks/Python/emmett/benchmark_config.json

@@ -22,6 +22,44 @@
       "display_name": "Emmett",
       "notes": "CPython 3.7",
       "versus": "uvicorn"
+    },
+    "socketify-asgi": {
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "Postgres",
+      "framework": "Emmett",
+      "language": "Python",
+      "flavor": "Python3",
+      "orm": "Full",
+      "platform": "None",
+      "webserver": "Socketify.py",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Emmett [Socketify.py ASGI]",
+      "notes": "CPython 3.7",
+      "versus": "uvicorn"
+    },
+    "socketify-asgi-pypy": {
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "Postgres",
+      "framework": "Emmett",
+      "language": "Python",
+      "flavor": "PyPy3",
+      "orm": "Full",
+      "platform": "None",
+      "webserver": "Socketify.py",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Emmett [Socketify.py ASGI PyPy3]",
+      "notes": "",
+      "versus": "uvicorn"
     }
   }]
 }

+ 26 - 0
frameworks/Python/emmett/config.toml

@@ -17,3 +17,29 @@ orm = "Full"
 platform = "None"
 webserver = "None"
 versus = "uvicorn"
+
+[socketify-asgi]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Fullstack"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Full"
+platform = "None"
+webserver = "Socketify.py"
+versus = "uvicorn"
+
+[socketify-asgi-pypy]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Fullstack"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Full"
+platform = "None"
+webserver = "Socketify.py"
+versus = "uvicorn"

+ 14 - 0
frameworks/Python/emmett/emmett-socketify-asgi-pypy.dockerfile

@@ -0,0 +1,14 @@
+FROM pypy:3.9-bullseye
+
+RUN mkdir -p /usr/src/app
+WORKDIR /usr/src/app
+COPY requirements-socketify.txt /usr/src/app
+RUN apt-get update; apt-get install libuv1 -y
+RUN pip install --no-cache-dir -r /usr/src/app/requirements-socketify.txt
+
+COPY ./ /app
+WORKDIR /app
+
+EXPOSE 8080
+
+CMD python ./app-socketify-asgi.py

+ 14 - 0
frameworks/Python/emmett/emmett-socketify-asgi.dockerfile

@@ -0,0 +1,14 @@
+FROM python:3.10-bullseye
+
+RUN mkdir -p /usr/src/app
+WORKDIR /usr/src/app
+COPY requirements-socketify.txt /usr/src/app
+RUN apt-get update; apt-get install libuv1 -y
+RUN pip install --no-cache-dir -r /usr/src/app/requirements-socketify.txt
+
+COPY ./ /app
+WORKDIR /app
+
+EXPOSE 8080
+
+CMD python ./app-socketify-asgi.py

+ 2 - 0
frameworks/Python/emmett/requirements-socketify.txt

@@ -0,0 +1,2 @@
+emmett==2.2.0
+git+https://github.com/cirospaciari/socketify.py.git@main#socketify