Browse Source

[Python] Bump granian to 0.2.0 (#7828)

Giovanni Barillari 2 years ago
parent
commit
cebf831870

+ 11 - 4
frameworks/Python/granian/README.md

@@ -12,15 +12,22 @@ Also note that there is additional information provided in the [Python README](.
 
 
 ## Test Paths & Source
 ## Test Paths & Source
 
 
-Granian includes two different implementations:
+Granian includes three different implementations:
 
 
-- ASGI implementation in the [app\_asgi.py](app_asgi.py)
-- RSGI implementation in the [app\_rsgi.py](app_rsgi.py)
+- ASGI implementation in [app\_asgi.py](app_asgi.py)
+- RSGI implementation in [app\_rsgi.py](app_rsgi.py)
+- WSGI implementation in [app\_wsgi.py](app_wsgi.py)
 
 
-Both implementations includes the following tests:
+ASGI and RSGI implementations includes the following tests:
 
 
 * JSON Serialization: "/json"
 * JSON Serialization: "/json"
 * Plaintext: "/plaintext"
 * Plaintext: "/plaintext"
+* Single Database Query: "/db"
+* Multiple Database Queries: "queries?queries=#"
+* Fortunes: "/fortunes"
+* Database Updates: "updates?queries=#"
+
+while WSGI implementation only include JSON Serialization and Plaintext tests.
 
 
 *Replace # with an actual number.*
 *Replace # with an actual number.*
 
 

+ 33 - 0
frameworks/Python/granian/app_wsgi.py

@@ -0,0 +1,33 @@
+import orjson
+
+
+JSON_HEADERS = [('content-type', 'application/json')]
+PLAINTEXT_HEADERS = [('content-type', 'text/plain; charset=utf-8')]
+
+json_dumps = orjson.dumps
+
+
+def route_json(environ, proto):
+    proto('200 OK', JSON_HEADERS)
+    return [json_dumps({'message': 'Hello, world!'})]
+
+
+def route_plaintext(environ, proto):
+    proto('200 OK', PLAINTEXT_HEADERS)
+    return [b'Hello, world!']
+
+
+def handle_404(environ, proto):
+    proto('404 NOT FOUND', PLAINTEXT_HEADERS)
+    return [b"not found"]
+
+
+routes = {
+    '/json': route_json,
+    '/plaintext': route_plaintext
+}
+
+
+def main(environ, proto):
+    handler = routes.get(environ["PATH_INFO"], handle_404)
+    return handler(environ, proto)

+ 18 - 0
frameworks/Python/granian/benchmark_config.json

@@ -44,6 +44,24 @@
       "display_name": "granian [rsgi]",
       "display_name": "granian [rsgi]",
       "notes": "",
       "notes": "",
       "versus": "uvicorn"
       "versus": "uvicorn"
+    },
+    "wsgi": {
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "Postgres",
+      "framework": "granian",
+      "language": "Python",
+      "orm": "Raw",
+      "platform": "None",
+      "webserver": "granian",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "granian [wsgi]",
+      "notes": "",
+      "versus": "uvicorn"
     }
     }
   }]
   }]
 }
 }

+ 13 - 0
frameworks/Python/granian/config.toml

@@ -34,3 +34,16 @@ orm = "Raw"
 platform = "None"
 platform = "None"
 webserver = "granian"
 webserver = "granian"
 versus = "uvicorn"
 versus = "uvicorn"
+
+[wsgi]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Platform"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = "None"
+webserver = "granian"
+versus = "uvicorn"

+ 11 - 0
frameworks/Python/granian/granian-wsgi.dockerfile

@@ -0,0 +1,11 @@
+FROM python:3.10-slim
+
+ADD ./ /granian
+
+WORKDIR /granian
+
+RUN pip install -r /granian/requirements.txt
+
+EXPOSE 8080
+
+CMD python run.py wsgi

+ 1 - 1
frameworks/Python/granian/requirements.txt

@@ -1,4 +1,4 @@
 asyncpg==0.27.0
 asyncpg==0.27.0
-granian==0.1.2
+granian==0.2.0
 jinja2==3.1.2
 jinja2==3.1.2
 orjson==3.8.1
 orjson==3.8.1

+ 2 - 0
frameworks/Python/granian/run.py

@@ -12,6 +12,8 @@ if __name__ == '__main__':
         address="0.0.0.0",
         address="0.0.0.0",
         port=8080,
         port=8080,
         workers=multiprocessing.cpu_count(),
         workers=multiprocessing.cpu_count(),
+        threading_mode="runtime",
+        threads=2,
         backlog=2048,
         backlog=2048,
         interface=interface,
         interface=interface,
         websockets=False
         websockets=False