Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uwsgi read #501

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
114 changes: 114 additions & 0 deletions uwsgi_read.ini
Original file line number Diff line number Diff line change
@@ -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 = run
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 = 180

# 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 = 50

# Start with 8 workers
cheaper-initial = 50

# Spawn at most 8 workers at once
cheaper-step = 50

# 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 = 32768

# 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
Loading