Răsfoiți Sursa

Update Python - Quart framework (#5527)

* Upgrade Quart requirements

This upgrades to the latest versions. For benchmarking this should be
useful as Hypercorn has improved since 0.5.3.

* Minor updates to Quart app file

The DB should be initialised in the before_serving i.e. before any
request is received, rather than the before_first_request (on first
request). This is now possible with Hypercorn and Uvicorn (likely
wasn't when code was first written).

Also routes should be async (or they are wrapped in threads with a
performance hit).

* Upgrade Quart-Uvicorn requirements

This upgrades to the latest versions. For benchmarking this should be
useful as Uvicorn has improved.

* Disconnect from DB in Quart app

May not affect benchmarks, unless there are cleanup issues.
Phil Jones 5 ani în urmă
părinte
comite
1426bba6b6

+ 8 - 3
frameworks/Python/quart/app.py

@@ -11,7 +11,7 @@ GET_WORLD = "select randomnumber from world where id = $1"
 UPDATE_WORLD = "update world set randomNumber = $2 where id = $1"
 UPDATE_WORLD = "update world set randomNumber = $2 where id = $1"
 
 
 
 
[email protected]_first_request
[email protected]_serving
 async def connect_to_db():
 async def connect_to_db():
     app.db = await asyncpg.create_pool(
     app.db = await asyncpg.create_pool(
         user=os.getenv("PGUSER", "benchmarkdbuser"),
         user=os.getenv("PGUSER", "benchmarkdbuser"),
@@ -22,9 +22,14 @@ async def connect_to_db():
     )
     )
 
 
 
 
[email protected]_serving
+async def disconnect_from_db():
+    await app.db.close()
+
+
 @app.route("/json")
 @app.route("/json")
-def json():
-    return jsonify(message="Hello, World!")
+async def json():
+    return {"message": "Hello, World!"}
 
 
 
 
 @app.route("/plaintext")
 @app.route("/plaintext")

+ 1 - 2
frameworks/Python/quart/quart-uvicorn.dockerfile

@@ -1,4 +1,4 @@
-FROM python:3.7-stretch
+FROM python:3.8
 
 
 ADD ./ /quart
 ADD ./ /quart
 
 
@@ -8,4 +8,3 @@ RUN pip3 install -r /quart/requirements.txt
 RUN pip3 install -r /quart/requirements-uvicorn.txt
 RUN pip3 install -r /quart/requirements-uvicorn.txt
 
 
 CMD gunicorn app:app -k uvicorn.workers.UvicornWorker -c gunicorn_conf.py
 CMD gunicorn app:app -k uvicorn.workers.UvicornWorker -c gunicorn_conf.py
-

+ 1 - 1
frameworks/Python/quart/quart.dockerfile

@@ -1,4 +1,4 @@
-FROM python:3.7-stretch
+FROM python:3.8
 
 
 ADD ./ /quart
 ADD ./ /quart
 
 

+ 4 - 7
frameworks/Python/quart/requirements-uvicorn.txt

@@ -1,7 +1,4 @@
-Click==7.0
-gunicorn==19.9.0
-h11==0.8.1
-httptools==0.0.13
-uvicorn==0.4.6
-uvloop==0.12.1
-websockets==7.0
+gunicorn==20.0.4
+httptools==0.1.1
+uvicorn==0.11.3
+websockets==8.1

+ 12 - 12
frameworks/Python/quart/requirements.txt

@@ -1,19 +1,19 @@
 aiofiles==0.4.0
 aiofiles==0.4.0
-asyncpg==0.18.3
+asyncpg==0.20.1
 blinker==1.4
 blinker==1.4
 Click==7.0
 Click==7.0
-h11==0.8.1
-h2==3.1.0
+h11==0.9.0
+h2==3.2.0
 hpack==3.0.0
 hpack==3.0.0
-Hypercorn==0.5.3
+Hypercorn==0.9.2
 hyperframe==5.2.0
 hyperframe==5.2.0
 itsdangerous==1.1.0
 itsdangerous==1.1.0
-Jinja2==2.10.1
+Jinja2==2.11.1
 MarkupSafe==1.1.1
 MarkupSafe==1.1.1
-multidict==4.5.2
-pytoml==0.1.20
-Quart==0.8.1
-sortedcontainers==2.1.0
-typing-extensions==3.7.2
-uvloop==0.12.1
-wsproto==0.13.0
+priority==1.3.0
+Quart==0.11.3
+toml==0.10.0
+typing-extensions==3.7.4.1
+uvloop==0.14.0
+Werkzeug==1.0.0
+wsproto==0.15.0