Skip to content

Commit

Permalink
core: add max-worker-lifetime-delta
Browse files Browse the repository at this point in the history
To not reload workers at the same time, instead with a timeout that depends on
their worker id.

Fix #2020
  • Loading branch information
ergo authored and xrmx committed Jun 14, 2020
1 parent c8d364d commit 95d1d74
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Vladimir Didenko
Alexandre Bonnetain
Darvame Hleran
Sokolov Yura <funny.falcon@gmail.com>
Marcin Lulek <info@webreactor.eu>
2 changes: 1 addition & 1 deletion core/master_checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ int uwsgi_master_check_workers_deadline() {
// check if worker was running longer than allowed lifetime
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0 && uwsgi.max_worker_lifetime > 0) {
uint64_t lifetime = uwsgi_now() - uwsgi.workers[i].last_spawn;
if (lifetime > uwsgi.max_worker_lifetime && uwsgi.workers[i].manage_next_request == 1) {
if (lifetime > (uwsgi.max_worker_lifetime + (i-1) * uwsgi.max_worker_lifetime_delta) && uwsgi.workers[i].manage_next_request == 1) {
uwsgi_log("worker %d lifetime reached, it was running for %llu second(s)\n", i, (unsigned long long) lifetime);
uwsgi.workers[i].manage_next_request = 0;
kill(uwsgi.workers[i].pid, SIGWINCH);
Expand Down
1 change: 1 addition & 0 deletions core/uwsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
{"max-requests-delta", required_argument, 0, "add (worker_id * delta) to the max_requests value of each worker", uwsgi_opt_set_64bit, &uwsgi.max_requests_delta, 0},
{"min-worker-lifetime", required_argument, 0, "number of seconds worker must run before being reloaded (default is 60)", uwsgi_opt_set_64bit, &uwsgi.min_worker_lifetime, 0},
{"max-worker-lifetime", required_argument, 0, "reload workers after the specified amount of seconds (default is disabled)", uwsgi_opt_set_64bit, &uwsgi.max_worker_lifetime, 0},
{"max-worker-lifetime-delta", required_argument, 0, "add (worker_id * delta) seconds to the max_worker_lifetime value of each worker", uwsgi_opt_set_int, &uwsgi.max_worker_lifetime_delta, 0},

{"socket-timeout", required_argument, 'z', "set internal sockets timeout", uwsgi_opt_set_int, &uwsgi.socket_timeout, 0},
{"no-fd-passing", no_argument, 0, "disable file descriptor passing", uwsgi_opt_true, &uwsgi.no_fd_passing, 0},
Expand Down
2 changes: 2 additions & 0 deletions uwsgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,8 @@ struct uwsgi_server {
int dynamic_apps;

struct uwsgi_buffer *websockets_continuation_buffer;

uint64_t max_worker_lifetime_delta;
};

struct uwsgi_rpc {
Expand Down

0 comments on commit 95d1d74

Please sign in to comment.