gunicorn_config.py
89 lines
| 2.2 KiB
| text/x-python
|
PythonLexer
/ configs / gunicorn_config.py
r1365 | """ | ||
gunicorn config extension and hooks. Sets additional configuration that is | |||
available post the .ini config. | |||
- workers = ${cpu_number} | |||
- threads = 1 | |||
- proc_name = ${gunicorn_proc_name} | |||
- worker_class = sync | |||
- worker_connections = 10 | |||
- max_requests = 1000 | |||
- max_requests_jitter = 30 | |||
- timeout = 21600 | |||
""" | |||
r1 | |||
import multiprocessing | |||
import sys | |||
import threading | |||
import traceback | |||
r1365 | # GLOBAL | ||
r1 | errorlog = '-' | ||
accesslog = '-' | |||
loglevel = 'debug' | |||
r1365 | # SECURITY | ||
r1 | limit_request_line = 4094 | ||
limit_request_fields = 100 | |||
limit_request_field_size = 8190 | |||
r1365 | # SERVER MECHANICS | ||
# None == system temp dir | |||
r1 | worker_tmp_dir = None | ||
tmp_upload_dir = None | |||
r1365 | # Custom log format | ||
access_log_format = ( | |||
r1549 | '%(t)s GNCRN %(p)-8s %(h)-15s rqt:%(L)s %(s)s %(b)-6s "%(m)s:%(U)s %(q)s" usr:%(u)s "%(f)s" "%(a)s"') | ||
r1 | |||
r1365 | # self adjust workers based on CPU count | ||
# workers = multiprocessing.cpu_count() * 2 + 1 | |||
r1 | |||
def post_fork(server, worker): | |||
r1365 | server.log.info("[<%-10s>] WORKER spawned", worker.pid) | ||
r1 | |||
def pre_fork(server, worker): | |||
pass | |||
def pre_exec(server): | |||
server.log.info("Forked child, re-executing.") | |||
def when_ready(server): | |||
server.log.info("Server is ready. Spawning workers") | |||
def worker_int(worker): | |||
worker.log.info("[<%-10s>] worker received INT or QUIT signal", worker.pid) | |||
r1365 | # get traceback info, on worker crash | ||
r1 | id2name = dict([(th.ident, th.name) for th in threading.enumerate()]) | ||
code = [] | |||
for thread_id, stack in sys._current_frames().items(): | |||
code.append( | |||
"\n# Thread: %s(%d)" % (id2name.get(thread_id, ""), thread_id)) | |||
for fname, lineno, name, line in traceback.extract_stack(stack): | |||
code.append('File: "%s", line %d, in %s' % (fname, lineno, name)) | |||
if line: | |||
code.append(" %s" % (line.strip())) | |||
worker.log.debug("\n".join(code)) | |||
def worker_abort(worker): | |||
worker.log.info("[<%-10s>] worker received SIGABRT signal", worker.pid) | |||
def pre_request(worker, req): | |||
return | |||
worker.log.debug("[<%-10s>] PRE WORKER: %s %s", | |||
worker.pid, req.method, req.path) | |||
def post_request(worker, req, environ, resp): | |||
return | |||
worker.log.debug("[<%-10s>] POST WORKER: %s %s resp: %s", worker.pid, | |||
req.method, req.path, resp.status_code) |