Show More
@@ -1,90 +1,90 b'' | |||||
1 | """ |
|
1 | """ | |
2 | gunicorn config extension and hooks. Sets additional configuration that is |
|
2 | gunicorn config extension and hooks. Sets additional configuration that is | |
3 | available post the .ini config. |
|
3 | available post the .ini config. | |
4 |
|
4 | |||
5 | - workers = ${cpu_number} |
|
5 | - workers = ${cpu_number} | |
6 | - threads = 1 |
|
6 | - threads = 1 | |
7 | - proc_name = ${gunicorn_proc_name} |
|
7 | - proc_name = ${gunicorn_proc_name} | |
8 | - worker_class = sync |
|
8 | - worker_class = sync | |
9 | - worker_connections = 10 |
|
9 | - worker_connections = 10 | |
10 | - max_requests = 1000 |
|
10 | - max_requests = 1000 | |
11 | - max_requests_jitter = 30 |
|
11 | - max_requests_jitter = 30 | |
12 | - timeout = 21600 |
|
12 | - timeout = 21600 | |
13 |
|
13 | |||
14 | """ |
|
14 | """ | |
15 |
|
15 | |||
16 | import multiprocessing |
|
16 | import multiprocessing | |
17 | import sys |
|
17 | import sys | |
18 | import threading |
|
18 | import threading | |
19 | import traceback |
|
19 | import traceback | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | # GLOBAL |
|
22 | # GLOBAL | |
23 | errorlog = '-' |
|
23 | errorlog = '-' | |
24 | accesslog = '-' |
|
24 | accesslog = '-' | |
25 | loglevel = 'debug' |
|
25 | loglevel = 'debug' | |
26 |
|
26 | |||
27 | # SECURITY |
|
27 | # SECURITY | |
28 | limit_request_line = 4094 |
|
28 | limit_request_line = 4094 | |
29 | limit_request_fields = 100 |
|
29 | limit_request_fields = 100 | |
30 | limit_request_field_size = 8190 |
|
30 | limit_request_field_size = 8190 | |
31 |
|
31 | |||
32 | # SERVER MECHANICS |
|
32 | # SERVER MECHANICS | |
33 | # None == system temp dir |
|
33 | # None == system temp dir | |
34 | worker_tmp_dir = None |
|
34 | worker_tmp_dir = None | |
35 | tmp_upload_dir = None |
|
35 | tmp_upload_dir = None | |
36 |
|
36 | |||
37 | # Custom log format |
|
37 | # Custom log format | |
38 | access_log_format = ( |
|
38 | access_log_format = ( | |
39 | '%(t)s GNCRN %(p)-8s %(h)-15s rqt:%(L)s %(s)s %(b)s "%(m)s:%(U)s %(q)s" usr:%(u)s "%(f)s" "%(a)s"') |
|
39 | '%(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"') | |
40 |
|
40 | |||
41 | # self adjust workers based on CPU count |
|
41 | # self adjust workers based on CPU count | |
42 | # workers = multiprocessing.cpu_count() * 2 + 1 |
|
42 | # workers = multiprocessing.cpu_count() * 2 + 1 | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | def post_fork(server, worker): |
|
45 | def post_fork(server, worker): | |
46 | server.log.info("[<%-10s>] WORKER spawned", worker.pid) |
|
46 | server.log.info("[<%-10s>] WORKER spawned", worker.pid) | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | def pre_fork(server, worker): |
|
49 | def pre_fork(server, worker): | |
50 | pass |
|
50 | pass | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | def pre_exec(server): |
|
53 | def pre_exec(server): | |
54 | server.log.info("Forked child, re-executing.") |
|
54 | server.log.info("Forked child, re-executing.") | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | def when_ready(server): |
|
57 | def when_ready(server): | |
58 | server.log.info("Server is ready. Spawning workers") |
|
58 | server.log.info("Server is ready. Spawning workers") | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def worker_int(worker): |
|
61 | def worker_int(worker): | |
62 | worker.log.info("[<%-10s>] worker received INT or QUIT signal", worker.pid) |
|
62 | worker.log.info("[<%-10s>] worker received INT or QUIT signal", worker.pid) | |
63 |
|
63 | |||
64 | # get traceback info, on worker crash |
|
64 | # get traceback info, on worker crash | |
65 | id2name = dict([(th.ident, th.name) for th in threading.enumerate()]) |
|
65 | id2name = dict([(th.ident, th.name) for th in threading.enumerate()]) | |
66 | code = [] |
|
66 | code = [] | |
67 | for thread_id, stack in sys._current_frames().items(): |
|
67 | for thread_id, stack in sys._current_frames().items(): | |
68 | code.append( |
|
68 | code.append( | |
69 | "\n# Thread: %s(%d)" % (id2name.get(thread_id, ""), thread_id)) |
|
69 | "\n# Thread: %s(%d)" % (id2name.get(thread_id, ""), thread_id)) | |
70 | for fname, lineno, name, line in traceback.extract_stack(stack): |
|
70 | for fname, lineno, name, line in traceback.extract_stack(stack): | |
71 | code.append('File: "%s", line %d, in %s' % (fname, lineno, name)) |
|
71 | code.append('File: "%s", line %d, in %s' % (fname, lineno, name)) | |
72 | if line: |
|
72 | if line: | |
73 | code.append(" %s" % (line.strip())) |
|
73 | code.append(" %s" % (line.strip())) | |
74 | worker.log.debug("\n".join(code)) |
|
74 | worker.log.debug("\n".join(code)) | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | def worker_abort(worker): |
|
77 | def worker_abort(worker): | |
78 | worker.log.info("[<%-10s>] worker received SIGABRT signal", worker.pid) |
|
78 | worker.log.info("[<%-10s>] worker received SIGABRT signal", worker.pid) | |
79 |
|
79 | |||
80 |
|
80 | |||
81 | def pre_request(worker, req): |
|
81 | def pre_request(worker, req): | |
82 | return |
|
82 | return | |
83 | worker.log.debug("[<%-10s>] PRE WORKER: %s %s", |
|
83 | worker.log.debug("[<%-10s>] PRE WORKER: %s %s", | |
84 | worker.pid, req.method, req.path) |
|
84 | worker.pid, req.method, req.path) | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | def post_request(worker, req, environ, resp): |
|
87 | def post_request(worker, req, environ, resp): | |
88 | return |
|
88 | return | |
89 | worker.log.debug("[<%-10s>] POST WORKER: %s %s resp: %s", worker.pid, |
|
89 | worker.log.debug("[<%-10s>] POST WORKER: %s %s resp: %s", worker.pid, | |
90 | req.method, req.path, resp.status_code) No newline at end of file |
|
90 | req.method, req.path, resp.status_code) |
General Comments 0
You need to be logged in to leave comments.
Login now