From 7963e2fad5d29d8e84de7c0becc35da76686e3d9 Mon Sep 17 00:00:00 2001 From: MOIS3Y Date: Thu, 31 Aug 2023 20:53:10 +0900 Subject: [PATCH] Modify: replace gunicorn to gunicorn async add gunicorn config file --- entrypoint.sh | 2 +- logs_collector/gunicorn.conf.py | 48 +++++++++++++++++++++++++++++++++ poetry.lock | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 5 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 logs_collector/gunicorn.conf.py diff --git a/entrypoint.sh b/entrypoint.sh index af4255e..fa14713 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,4 +3,4 @@ python manage.py migrate --no-input python manage.py collectstatic --no-input -gunicorn logs_collector.wsgi:application --bind 0.0.0.0:8000 +gunicorn logs_collector.wsgi:application diff --git a/logs_collector/gunicorn.conf.py b/logs_collector/gunicorn.conf.py new file mode 100644 index 0000000..5b9e279 --- /dev/null +++ b/logs_collector/gunicorn.conf.py @@ -0,0 +1,48 @@ +import environ +import gunicorn + +from logs_collector.settings import BASE_DIR + +# █▀▀ █░█ █▄░█ █ █▀▀ █▀█ █▀█ █▄░█ █▀▀ █▀█ █▄░█ █▀▀ █ █▀▀ ▀ +# █▄█ █▄█ █░▀█ █ █▄▄ █▄█ █▀▄ █░▀█ █▄▄ █▄█ █░▀█ █▀░ █ █▄█ ▄ +# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +# https://docs.gunicorn.org/en/stable/settings.html +# https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py + +# hide web server name: +gunicorn.SERVER = 'undisclosed' + +env = environ.Env( + # set casting, default value: + GUNICORN_BIND=(str, '0.0.0.0:8000'), + GUNICORN_BACKLOG=(int, 2048), + + GUNICORN_WORKERS=(int, 2), + GUNICORN_WORKER_CLASS=(str, 'gthread'), + GUNICORN_WORKER_CONNECTIONS=(int, 1000), + GUNICORN_THREADS=(int, 1), + GUNICORN_TIMEOUT=(int, 30), + GUNICORN_KEEPALIVE=(int, 2), + + GUNICORN_LOGLEVEL=(str, 'info'), +) + +environ.Env.read_env(BASE_DIR / '.env') + +# Server socket: +bind = env('GUNICORN_BIND') +backlog = env('GUNICORN_BACKLOG') + +# Worker processes: +workers = env('GUNICORN_WORKERS') +worker_class = env('GUNICORN_WORKER_CLASS') +worker_connections = env('GUNICORN_WORKER_CONNECTIONS') +threads = env('GUNICORN_THREADS') +timeout = env('GUNICORN_TIMEOUT') +keepalive = env('GUNICORN_KEEPALIVE') + +# Logging: +loglevel = env('GUNICORN_LOGLEVEL') +errorlog = '-' +accesslog = '-' +access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' # noqa:E501 diff --git a/poetry.lock b/poetry.lock index 5419608..22d8133 100644 --- a/poetry.lock +++ b/poetry.lock @@ -727,4 +727,4 @@ brotli = ["Brotli"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "39c4da284ce6727245ff8e62ae325111cccd55175f38bc34045cbf2ef153d871" +content-hash = "e67fb8ed8bd9086956f4c789fd42d8b0ebe140579bc2aa2f1c303bd1def9b2f7" diff --git a/pyproject.toml b/pyproject.toml index a2c8734..599cd7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ django-filter = "23.2" drf-spectacular = "0.26.4" django-two-factor-auth = {extras = ["phonenumberslite"], version = "1.15.3"} whitenoise = "6.5.0" -gunicorn = "21.2.0" +gunicorn = {extras = ["gthread"], version = "21.2.0"} [tool.poetry.group.dev.dependencies] flake8 = "^6.0.0" diff --git a/requirements.txt b/requirements.txt index 88888db..188d9ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -46,7 +46,7 @@ djangorestframework==3.14.0 ; python_version >= "3.10" and python_version < "4.0 drf-spectacular==0.26.4 ; python_version >= "3.10" and python_version < "4.0" \ --hash=sha256:8f5a8f87353d1bb8dcb3f3909b7109b2dcbe1d91f3e069409cf322963e140bd6 \ --hash=sha256:afeccc6533dcdb4e78afbfcc49f3c5e9c369aeb62f965e4d1a43b165449c147a -gunicorn==21.2.0 ; python_version >= "3.10" and python_version < "4.0" \ +gunicorn[gthread]==21.2.0 ; python_version >= "3.10" and python_version < "4.0" \ --hash=sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0 \ --hash=sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033 inflection==0.5.1 ; python_version >= "3.10" and python_version < "4.0" \