swap uvicorn out for hypercorn

uvicorn is subjectively nicer to play with for local dev work, but
hypercorn is required in order to do HTTP/2 which is fairly
performance-important.

Signed-off-by: Kevin Morris <kevr@0cost.org>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Co-authored-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
This commit is contained in:
Kevin Morris 2020-12-23 12:53:28 -08:00 committed by Eli Schwartz
parent bab74dd307
commit 19652d6cbe
No known key found for this signature in database
GPG key ID: CEB167EFB5722BD6
3 changed files with 13 additions and 6 deletions

View file

@ -11,7 +11,7 @@ before_script:
base-devel git gpgme protobuf pyalpm python-mysql-connector base-devel git gpgme protobuf pyalpm python-mysql-connector
python-pygit2 python-srcinfo python-bleach python-markdown python-pygit2 python-srcinfo python-bleach python-markdown
python-sqlalchemy python-alembic python-pytest python-werkzeug python-sqlalchemy python-alembic python-pytest python-werkzeug
python-pytest-tap python-fastapi uvicorn nginx python-authlib python-pytest-tap python-fastapi hypercorn nginx python-authlib
python-itsdangerous python-httpx python-itsdangerous python-httpx
test: test:

View file

@ -48,7 +48,8 @@ read the instructions below.
4) Install Python modules and dependencies: 4) Install Python modules and dependencies:
# pacman -S python-mysql-connector python-pygit2 python-srcinfo python-sqlalchemy \ # pacman -S python-mysql-connector python-pygit2 python-srcinfo python-sqlalchemy \
python-bleach python-markdown python-alembic python-bleach python-markdown python-alembic python-jinja \
python-itsdangerous python-authlib python-httpx hypercorn
# python3 setup.py install # python3 setup.py install
5) Create a new MySQL database and a user and import the aurweb SQL schema: 5) Create a new MySQL database and a user and import the aurweb SQL schema:

View file

@ -24,6 +24,7 @@ import aurweb.schema
children = [] children = []
temporary_dir = None temporary_dir = None
verbosity = 0 verbosity = 0
asgi_backend = ''
class ProcessExceptions(Exception): class ProcessExceptions(Exception):
@ -31,6 +32,7 @@ class ProcessExceptions(Exception):
Compound exception used by stop() to list all the errors that happened when Compound exception used by stop() to list all the errors that happened when
terminating child processes. terminating child processes.
""" """
def __init__(self, message, exceptions): def __init__(self, message, exceptions):
self.message = message self.message = message
self.exceptions = exceptions self.exceptions = exceptions
@ -110,10 +112,11 @@ def start():
# FastAPI # FastAPI
host, port = aurweb.config.get("fastapi", "bind_address").rsplit(":", 1) host, port = aurweb.config.get("fastapi", "bind_address").rsplit(":", 1)
spawn_child(["python", "-m", "uvicorn", if asgi_backend == "hypercorn":
"--host", host, portargs = ["-b", f"{host}:{port}"]
"--port", port, elif asgi_backend == "uvicorn":
"aurweb.asgi:app"]) portargs = ["--host", host, "--port", port]
spawn_child(["python", "-m", asgi_backend] + portargs + ["aurweb.asgi:app"])
# nginx # nginx
spawn_child(["nginx", "-p", temporary_dir, "-c", generate_nginx_config()]) spawn_child(["nginx", "-p", temporary_dir, "-c", generate_nginx_config()])
@ -158,8 +161,11 @@ if __name__ == '__main__':
description='Start aurweb\'s test server.') description='Start aurweb\'s test server.')
parser.add_argument('-v', '--verbose', action='count', default=0, parser.add_argument('-v', '--verbose', action='count', default=0,
help='increase verbosity') help='increase verbosity')
parser.add_argument('-b', '--backend', choices=['hypercorn', 'uvicorn'], default='hypercorn',
help='asgi backend used to launch the python server')
args = parser.parse_args() args = parser.parse_args()
verbosity = args.verbose verbosity = args.verbose
asgi_backend = args.backend
with tempfile.TemporaryDirectory(prefix="aurweb-") as tmpdirname: with tempfile.TemporaryDirectory(prefix="aurweb-") as tmpdirname:
temporary_dir = tmpdirname temporary_dir = tmpdirname
start() start()