Skip to content

Commit

Permalink
Use gevent as our gunicorn worker type (#119)
Browse files Browse the repository at this point in the history
* Use `gevent` as our gunicorn worker type

Load testing against dev using `gthread`, `eventlet`, and `gevent` revealed gevent to be the best choice for this application, with a ~7% reduction in errors when running at/near the CPU limit for the cluster.

* [Bot] Update version to 2.0.11

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Thomas Thorogood and github-actions[bot] authored Oct 1, 2021
1 parent b131841 commit 844577a
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 125 deletions.
1 change: 0 additions & 1 deletion docker/deployment.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ RUN echo $DEPLOYMENT_ID >> .deployment
CMD poetry run gunicorn -b 0.0.0.0:${FLASK_PORT} \
--log-level ${GUNICORN_LOG_LEVEL} \
-c "/app/husky_directory/gunicorn.conf.py" \
--preload \
"husky_directory.app:create_app()"
19 changes: 9 additions & 10 deletions husky_directory/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os
from multiprocessing import cpu_count
from gevent import monkey

from prometheus_flask_exporter.multiprocess import GunicornInternalPrometheusMetrics
monkey.patch_all()

import os # noqa: E402
from multiprocessing import cpu_count # noqa: E402
from prometheus_flask_exporter.multiprocess import ( # noqa: E402
GunicornInternalPrometheusMetrics,
)

if not os.environ.get("PROMETHEUS_MULTIPROC_DIR"):
raise EnvironmentError("PROMETHEUS_MULTIPROC_DIR environment variable must be set!")
Expand All @@ -16,20 +21,14 @@ def max_workers():
return os.environ.get("GUNICORN_MAX_WORKERS", default_max)


def max_threads():
default_max = 4
return os.environ.get("GUNICORN_MAX_THREADS", default_max)


def child_exit(server, worker):
GunicornInternalPrometheusMetrics.mark_process_dead_on_child_exit(worker.pid)


max_requests = 1000
bind = "0.0.0.0:8000"
worker_class = "gthread"
worker_class = "gevent"
workers = max_workers()
threads = max_threads()
loglevel = os.environ.get("GUNICORN_LOG_LEVEL", "DEBUG")
reload = os.environ.get("FLASK_ENV") == "development"
preload_app = os.environ.get("FLASK_ENV") != "development"
Loading

0 comments on commit 844577a

Please sign in to comment.