mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-04 20:51:29 +00:00
worker's busy value is now dinamically computed
This commit is contained in:
+11
-1
@@ -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<uwsgi.cores;i++) {
|
||||
if (uwsgi.workers[wid].cores[i].in_request) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-6
@@ -187,7 +187,7 @@ int uwsgi_cheaper_algo_spare(void) {
|
||||
for (i = 1; i <= uwsgi.numproc; i++) {
|
||||
if (uwsgi.workers[i].cheaped == 0 && uwsgi.workers[i].pid > 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
#include "../../uwsgi.h"
|
||||
#include <uwsgi.h>
|
||||
|
||||
/*
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../../uwsgi.h"
|
||||
#include <uwsgi.h>
|
||||
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user