From f046d47eb22186a6794be78a5508fbb4f2e64f41 Mon Sep 17 00:00:00 2001 From: Unbit Date: Thu, 14 Feb 2013 09:17:59 +0100 Subject: [PATCH] worker's busy value is now dinamically computed --- core/master_checks.c | 12 +++++++++++- core/master_utils.c | 10 ++++------ core/utils.c | 3 --- plugins/carbon/carbon.c | 10 ++++++++-- plugins/cheaper_busyness/cheaper_busyness.c | 4 ++-- plugins/python/python_plugin.c | 2 +- plugins/python/uwsgi_pymodule.c | 4 ++-- uwsgi.h | 3 ++- 8 files changed, 30 insertions(+), 18 deletions(-) diff --git a/core/master_checks.c b/core/master_checks.c index 90fe9172..0ccbfaae 100644 --- a/core/master_checks.c +++ b/core/master_checks.c @@ -76,7 +76,7 @@ void uwsgi_master_check_idle() { // security check, stop the check if there are busy workers for (i = 1; i <= uwsgi.numproc; i++) { if (uwsgi.workers[i].cheaped == 0 && uwsgi.workers[i].pid > 0) { - if (uwsgi.workers[i].busy == 1) { + if (uwsgi_worker_is_busy(i)) { return; } } @@ -266,3 +266,13 @@ int uwsgi_master_check_daemons_death(int diedpid) { } return 0; } + +int uwsgi_worker_is_busy(int wid) { + int i; + for(i=0;i 0) { // if a non-busy worker is found, the overload_count is decremented and stop the cycle - if (uwsgi.workers[i].busy == 0) { + if (uwsgi_worker_is_busy(i) == 0) { if (overload_count > 0) overload_count--; goto healthy; @@ -230,7 +230,7 @@ healthy: for (i = 1; i <= uwsgi.numproc; i++) { if (uwsgi.workers[i].cheaped == 0 && uwsgi.workers[i].pid > 0) { active_workers++; - if (uwsgi.workers[i].busy == 1) + if (uwsgi_worker_is_busy(i) == 1) busy_workers++; } } @@ -537,7 +537,6 @@ int uwsgi_respawn_worker(int wid) { // internal statuses should be reset too uwsgi.workers[wid].cheaped = 0; - uwsgi.workers[wid].busy = 0; // SUSPENSION is managed by the user, not the master... //uwsgi.workers[wid].suspended = 0; uwsgi.workers[wid].sig = 0; @@ -578,7 +577,6 @@ int uwsgi_respawn_worker(int wid) { uwsgi.workers[uwsgi.mywid].manage_next_request = 1; /* uwsgi.workers[uwsgi.mywid].cheaped = 0; - uwsgi.workers[uwsgi.mywid].busy = 0; uwsgi.workers[uwsgi.mywid].suspended = 0; uwsgi.workers[uwsgi.mywid].sig = 0; */ @@ -1034,7 +1032,7 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { if (uwsgi_stats_keyval_comma(us, "status", "cheap")) goto end; } - else if (uwsgi.workers[i + 1].suspended && !uwsgi.workers[i + 1].busy) { + else if (uwsgi.workers[i + 1].suspended && !uwsgi_worker_is_busy(i+1)) { if (uwsgi_stats_keyval_comma(us, "status", "pause")) goto end; } @@ -1043,7 +1041,7 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { if (uwsgi_stats_keyvalnum_comma(us, "status", "sig", (unsigned long long) uwsgi.workers[i + 1].signum)) goto end; } - else if (uwsgi.workers[i + 1].busy) { + else if (uwsgi_worker_is_busy(i+1)) { if (uwsgi_stats_keyval_comma(us, "status", "busy")) goto end; } diff --git a/core/utils.c b/core/utils.c index 70458e3b..8648560a 100644 --- a/core/utils.c +++ b/core/utils.c @@ -860,7 +860,6 @@ void wsgi_req_setup(struct wsgi_request *wsgi_req, int async_id, struct uwsgi_so } uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].in_request = 0; - uwsgi.workers[uwsgi.mywid].busy = 0; // now check for suspend request if (uwsgi.workers[uwsgi.mywid].suspended == 1) { @@ -877,7 +876,6 @@ cycle: int wsgi_req_async_recv(struct wsgi_request *wsgi_req) { uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].in_request = 1; - uwsgi.workers[uwsgi.mywid].busy = 1; wsgi_req->start_of_request = uwsgi_micros(); wsgi_req->start_of_request_in_sec = wsgi_req->start_of_request / 1000000; @@ -902,7 +900,6 @@ int wsgi_req_async_recv(struct wsgi_request *wsgi_req) { int wsgi_req_recv(int queue, struct wsgi_request *wsgi_req) { uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].in_request = 1; - uwsgi.workers[uwsgi.mywid].busy = 1; wsgi_req->start_of_request = uwsgi_micros(); wsgi_req->start_of_request_in_sec = wsgi_req->start_of_request / 1000000; diff --git a/plugins/carbon/carbon.c b/plugins/carbon/carbon.c index 8303b90c..5d2a30a3 100644 --- a/plugins/carbon/carbon.c +++ b/plugins/carbon/carbon.c @@ -1,4 +1,10 @@ -#include "../../uwsgi.h" +#include + +/* + + Author: Ɓukasz Mierzwa + +*/ extern struct uwsgi_server uwsgi; @@ -128,7 +134,7 @@ void carbon_push_stats(int retry_cycle) { for (i = 0; i < uwsgi.numproc; i++) { u_carbon.current_busyness_values[i] = uwsgi.workers[i+1].running_time - u_carbon.last_busyness_values[i]; u_carbon.last_busyness_values[i] = uwsgi.workers[i+1].running_time; - u_carbon.was_busy[i-1] += uwsgi.workers[i+1].busy; + u_carbon.was_busy[i-1] += uwsgi_worker_is_busy(i+1); } u_carbon.need_retry = 0; diff --git a/plugins/cheaper_busyness/cheaper_busyness.c b/plugins/cheaper_busyness/cheaper_busyness.c index 58bd063b..29b98b34 100644 --- a/plugins/cheaper_busyness/cheaper_busyness.c +++ b/plugins/cheaper_busyness/cheaper_busyness.c @@ -1,4 +1,4 @@ -#include "../../uwsgi.h" +#include /* @@ -195,7 +195,7 @@ int cheaper_busyness_algo(void) { for (i = 0; i < uwsgi.numproc; i++) { if (uwsgi.workers[i+1].cheaped == 0 && uwsgi.workers[i+1].pid > 0) { active_workers++; - uwsgi_cheaper_busyness_global.was_busy[i] += uwsgi.workers[i+1].busy; + uwsgi_cheaper_busyness_global.was_busy[i] += uwsgi_worker_is_busy(i+1); } else { uwsgi_cheaper_busyness_global.was_busy[i] = 0; } diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 5f8c8576..24a9336f 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -299,7 +299,7 @@ void uwsgi_python_atexit() { return; // if busy do not run atexit hooks - if (uwsgi.workers[uwsgi.mywid].busy) + if (uwsgi_worker_is_busy(uwsgi.mywid)) return; // managing atexit in async mode is a real pain...skip it for now diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index ec034b2d..a1ad7017 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -1995,14 +1995,14 @@ PyObject *py_uwsgi_workers(PyObject * self, PyObject * args) { if (uwsgi.workers[i + 1].cheaped) { zero = PyString_FromString("cheap"); } - else if (uwsgi.workers[i + 1].suspended && !uwsgi.workers[i + 1].busy) { + else if (uwsgi.workers[i + 1].suspended && !uwsgi_worker_is_busy(i+1)) { zero = PyString_FromString("pause"); } else { if (uwsgi.workers[i + 1].sig) { zero = PyString_FromFormat("sig%d",uwsgi.workers[i + 1].signum); } - else if (uwsgi.workers[i + 1].busy) { + else if (uwsgi_worker_is_busy(i+1)) { zero = PyString_FromString("busy"); } else { diff --git a/uwsgi.h b/uwsgi.h index 43afd708..3fed7657 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2362,7 +2362,6 @@ struct uwsgi_rpc { int hijacked; uint64_t hijacked_count; - int busy; int cheaped; int suspended; int sig; @@ -3813,6 +3812,8 @@ int uwsgi_master_manage_events(int); void uwsgi_block_signal(int); void uwsgi_unblock_signal(int); +int uwsgi_worker_is_busy(int); + #define uwsgi_response_add_connection_close(x) uwsgi_response_add_header(x, "Connection", 10, "close", 5) #define uwsgi_response_add_content_type(x, y, z) uwsgi_response_add_header(x, "Content-Type", 12, y, z)