From 3b823142a2cbc5604a1837fddcf8db38479e02bc Mon Sep 17 00:00:00 2001 From: Forrest Collman Date: Wed, 10 Apr 2024 15:44:57 -0700 Subject: [PATCH 1/4] adding second uwsgi config --- run.py | 12 ++---- run2.py | 12 ++++++ uwsgi_read.ini | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 run2.py create mode 100644 uwsgi_read.ini diff --git a/run.py b/run.py index 61c2939ff..76602e44f 100644 --- a/run.py +++ b/run.py @@ -2,14 +2,10 @@ from pychunkedgraph.app import create_app application = create_app() - +print("running default app") if __name__ == "__main__": - WSGIRequestHandler.protocol_version = "HTTP/1.1" - application.run(host='0.0.0.0', - port=80, - debug=False, - threaded=True, - ssl_context='adhoc') - + application.run( + host="0.0.0.0", port=80, debug=False, threaded=True, ssl_context="adhoc" + ) diff --git a/run2.py b/run2.py new file mode 100644 index 000000000..8799b8db0 --- /dev/null +++ b/run2.py @@ -0,0 +1,12 @@ +from werkzeug.serving import WSGIRequestHandler +from pychunkedgraph.app import create_app + +application = create_app() +print("running run2.py") + +if __name__ == "__main__": + WSGIRequestHandler.protocol_version = "HTTP/1.1" + + application.run( + host="0.0.0.0", port=80, debug=False, threaded=True, ssl_context="adhoc" + ) diff --git a/uwsgi_read.ini b/uwsgi_read.ini new file mode 100644 index 000000000..08b8b0de9 --- /dev/null +++ b/uwsgi_read.ini @@ -0,0 +1,114 @@ +[uwsgi] +socket = /tmp/uwsgi.sock +chown-socket = nginx:nginx +chmod-socket = 664 +# Graceful shutdown on SIGTERM, see https://github.com/unbit/uwsgi/issues/849#issuecomment-118869386 +hook-master-start = unix_signal:15 gracefully_kill_them_all + +module = run2 +callable = application + +uid = nginx +gid = nginx + +env = HOME=/home/nginx + +# Python venv +if-env = VIRTUAL_ENV +virtualenv = %(_) +endif = + +### Worker scaling +# maximum number of workers +processes = 120 + +# https://uwsgi-docs.readthedocs.io/en/latest/Cheaper.html#busyness-cheaper-algorithm +cheaper-algo = busyness + +# Time window for tracking average busyness +cheaper-overload = 20 + +# Number of idle cycles before stopping a worker +cheaper-busyness-multiplier = 3 + +# Minimum number of workers +cheaper = 8 + +# Start with 8 workers +cheaper-initial = 8 + +# Spawn at most 8 workers at once +cheaper-step = 8 + +# Start spawning more workers at 60% busyness +cheaper-busyness-max = 60 + +# Start killing workers if busyness falls below 20% +cheaper-busyness-min = 20 + + +### Reloads and limitations +# max socket listen queue length - requires net.somaxconn increase +listen = 4096 + +# Max request header size +buffer-size = 65535 + +# Don't spawn new workers if total memory over 6 GiB +cheaper-rss-limit-soft = 6442450944 + +# Reload worker after serving X requests +max-requests = 5000 + +# Grace period for single worker to reload/shutdown +worker-reload-mercy = 600 + +# Grace period for all workers and processes to reload/shutdown +reload-mercy = 605 + +# Kill stuck/unresponsive processes after 20 minutes +harakiri = 1200 + + +### Misc +# Maintain Python thread support +enable-threads = true + +# Required for cheaper-rss-limit-soft +memory-report = true + +# Additional log output for harakiri +harakiri-verbose = true + + +### Logging +# Filter our properly pre-formated app messages and pass them through +logger = app stdio +log-route = app ^{.*"source":.*}$ + +# Capture known / most common uWSGI messages +logger = uWSGIdebug stdio +logger = uWSGIwarn stdio + +log-route = uWSGIdebug ^{address space usage +log-route = uWSGIwarn \[warn\] + +log-encoder = json:uWSGIdebug {"source":"uWSGI","time":"${strftime:%Y-%m-%dT%H:%M:%S.000Z}","severity":"debug","message":"${msg}"} +log-encoder = nl:uWSGIdebug +log-encoder = json:uWSGIwarn {"source":"uWSGI","time":"${strftime:%Y-%m-%dT%H:%M:%S.000Z}","severity":"warning","message":"${msg}"} +log-encoder = nl:uWSGIwarn + +# Treat everything else as error message of unknown origin +logger = unknown stdio + +# Creating our own "inverse Regex" using negative lookaheads, which makes this +# log-route rather cryptic and slow... Unclear how to get a simple +# "fall-through" behavior for non-matching messages, otherwise. +log-route = unknown ^(?:(?!^{address space usage|\[warn\]|^{.*"source".*}$).)*$ + +log-encoder = json:unknown {"source":"unknown","time":"${strftime:%Y-%m-%dT%H:%M:%S.000Z}","severity":"error","message":"${msg}"} +log-encoder = nl:unknown + +log-4xx = true +log-5xx = true +disable-logging = true From 1d32ea55750bae3b9709ca09e7cdc69ccc159cf1 Mon Sep 17 00:00:00 2001 From: Forrest Collman Date: Wed, 10 Apr 2024 16:08:54 -0700 Subject: [PATCH 2/4] bumping min workers --- uwsgi_read.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uwsgi_read.ini b/uwsgi_read.ini index 08b8b0de9..df183aea8 100644 --- a/uwsgi_read.ini +++ b/uwsgi_read.ini @@ -20,7 +20,7 @@ endif = ### Worker scaling # maximum number of workers -processes = 120 +processes = 180 # https://uwsgi-docs.readthedocs.io/en/latest/Cheaper.html#busyness-cheaper-algorithm cheaper-algo = busyness @@ -32,13 +32,13 @@ cheaper-overload = 20 cheaper-busyness-multiplier = 3 # Minimum number of workers -cheaper = 8 +cheaper = 50 # Start with 8 workers -cheaper-initial = 8 +cheaper-initial = 50 # Spawn at most 8 workers at once -cheaper-step = 8 +cheaper-step = 50 # Start spawning more workers at 60% busyness cheaper-busyness-max = 60 From 39ccbe23c91abd282202f5779ec7265615c3b90d Mon Sep 17 00:00:00 2001 From: Forrest Collman Date: Wed, 10 Apr 2024 17:54:26 -0700 Subject: [PATCH 3/4] bumping listen --- uwsgi_read.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uwsgi_read.ini b/uwsgi_read.ini index df183aea8..0da0294c7 100644 --- a/uwsgi_read.ini +++ b/uwsgi_read.ini @@ -49,7 +49,7 @@ cheaper-busyness-min = 20 ### Reloads and limitations # max socket listen queue length - requires net.somaxconn increase -listen = 4096 +listen = 32768 # Max request header size buffer-size = 65535 From 82c00f9c1aaace9f443e22cfad1ca6b484cebc16 Mon Sep 17 00:00:00 2001 From: Forrest Collman Date: Mon, 17 Jun 2024 10:31:13 +0200 Subject: [PATCH 4/4] removing run2 --- run2.py | 12 ------------ uwsgi_read.ini | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 run2.py diff --git a/run2.py b/run2.py deleted file mode 100644 index 8799b8db0..000000000 --- a/run2.py +++ /dev/null @@ -1,12 +0,0 @@ -from werkzeug.serving import WSGIRequestHandler -from pychunkedgraph.app import create_app - -application = create_app() -print("running run2.py") - -if __name__ == "__main__": - WSGIRequestHandler.protocol_version = "HTTP/1.1" - - application.run( - host="0.0.0.0", port=80, debug=False, threaded=True, ssl_context="adhoc" - ) diff --git a/uwsgi_read.ini b/uwsgi_read.ini index 0da0294c7..9ef790341 100644 --- a/uwsgi_read.ini +++ b/uwsgi_read.ini @@ -5,7 +5,7 @@ chmod-socket = 664 # Graceful shutdown on SIGTERM, see https://github.com/unbit/uwsgi/issues/849#issuecomment-118869386 hook-master-start = unix_signal:15 gracefully_kill_them_all -module = run2 +module = run callable = application uid = nginx