From d37a1455b7eec05bf4cb0ccb727aab318186427d Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Sat, 20 Mar 2021 13:57:53 +0530 Subject: [PATCH 1/2] feat(frappe-worker): option to set gevent as gunicorn worker-class --- build/common/commands/gevent_patch.py | 2 ++ build/common/worker/docker-entrypoint.sh | 21 +++++++++++++++------ build/frappe-worker/Dockerfile | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 build/common/commands/gevent_patch.py diff --git a/build/common/commands/gevent_patch.py b/build/common/commands/gevent_patch.py new file mode 100644 index 00000000..9d7cc3c3 --- /dev/null +++ b/build/common/commands/gevent_patch.py @@ -0,0 +1,2 @@ +import gevent.monkey +gevent.monkey.patch_all() diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index 9b170c59..a3082442 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -84,17 +84,26 @@ if [ "$1" = 'start' ]; then export FRAPPE_PORT=8000 fi + if [[ -z "$WORKER_CLASS" ]]; then + export WORKER_CLASS=gthread + fi + + export LOAD_CONFIG_FILE="" + if [ "$WORKER_CLASS" = "gevent" ]; then + export LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" + fi + if [[ ! -z "$AUTO_MIGRATE" ]]; then . /home/frappe/frappe-bench/env/bin/activate \ && python /home/frappe/frappe-bench/commands/auto_migrate.py fi . /home/frappe/frappe-bench/env/bin/activate - gunicorn -b 0.0.0.0:$FRAPPE_PORT \ + gunicorn $LOAD_CONFIG_FILE -b 0.0.0.0:$FRAPPE_PORT \ --worker-tmp-dir /dev/shm \ --threads=4 \ --workers $WORKERS \ - --worker-class=gthread \ + --worker-class=$WORKER_CLASS \ --log-file=- \ -t 120 frappe.app:application --preload @@ -102,21 +111,21 @@ elif [ "$1" = 'worker' ]; then checkConfigExists checkConnection # default WORKER_TYPE=default - + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/worker.py elif [ "$1" = 'schedule' ]; then checkConfigExists checkConnection - + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/background.py elif [ "$1" = 'new' ]; then checkConfigExists checkConnection - + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/new.py exit @@ -124,7 +133,7 @@ elif [ "$1" = 'new' ]; then elif [ "$1" = 'drop' ]; then checkConfigExists checkConnection - + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/drop.py exit diff --git a/build/frappe-worker/Dockerfile b/build/frappe-worker/Dockerfile index f089ff33..3e8313e6 100644 --- a/build/frappe-worker/Dockerfile +++ b/build/frappe-worker/Dockerfile @@ -65,6 +65,8 @@ RUN mkdir -p apps logs commands sites /home/frappe/backups # Setup python environment RUN python -m venv env \ && . env/bin/activate \ + && pip3 install --upgrade pip \ + && pip3 install gevent \ && cd apps \ && git clone --depth 1 -o upstream https://github.com/frappe/frappe --branch ${GIT_BRANCH} \ && pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/frappe From 261288fa8cede7511996c3215581b9e6be4972c0 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Sat, 20 Mar 2021 15:09:08 +0530 Subject: [PATCH 2/2] docs: env variable gunicorn worker-class [skip travis] --- docs/environment-variables.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/environment-variables.md b/docs/environment-variables.md index a1c105aa..09d5654b 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -10,6 +10,7 @@ Following environment variables are set into sites volume as `common_site_config - `REDIS_QUEUE`: Redis queue host, domain name or ip address. - `REDIS_SOCKETIO`: Redis queue host, domain name or ip address. - `SOCKETIO_PORT: `: Port on which the SocketIO should start. +- `WORKER_CLASS`: Optionally set gunicorn worker-class. Supports gevent only, defaults to gthread. ### frappe-nginx and erpnext-nginx