diff --git a/buildconf/all.ini b/buildconf/all.ini index 2bc1029c..2410a7d0 100644 --- a/buildconf/all.ini +++ b/buildconf/all.ini @@ -1,3 +1,3 @@ [uwsgi] -main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi,xslt,webdav,ssi,ldap,gccgo,rados,pypy +main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi,xslt,webdav,ssi,ldap,gccgo,rados,pypy,zabbix,curl_cron,tornado,tuntap,pty,mongrel2,alarm_curl,router_radius,airbrake inherit = base diff --git a/core/master.c b/core/master.c index f4d94b7a..ef856d00 100644 --- a/core/master.c +++ b/core/master.c @@ -222,7 +222,7 @@ static void get_linux_unbit_SIOBKLGQ(struct uwsgi_socket *uwsgi_sock) { static void master_check_listen_queue() { - uint64_t load = 0; + uint64_t backlog = 0; struct uwsgi_socket *uwsgi_sock = uwsgi.sockets; while(uwsgi_sock) { if (uwsgi_sock->family == AF_INET) { @@ -236,8 +236,8 @@ static void master_check_listen_queue() { #endif #endif - if (uwsgi_sock->queue > load) { - load = uwsgi_sock->queue; + if (uwsgi_sock->queue > backlog) { + backlog = uwsgi_sock->queue; } if (uwsgi_sock->queue > 0 && uwsgi_sock->queue >= uwsgi_sock->max_queue) { uwsgi_log_verbose("*** uWSGI listen queue of socket \"%s\" (fd: %d) full !!! (%llu/%llu) ***\n", uwsgi_sock->name, uwsgi_sock->fd, (unsigned long long) uwsgi_sock->queue, (unsigned long long) uwsgi_sock->max_queue); @@ -245,16 +245,20 @@ static void master_check_listen_queue() { uwsgi_sock = uwsgi_sock->next; } - uwsgi.shared->load = load; + // TODO load should be something more advanced based on different values + uwsgi.shared->load = backlog; + + uwsgi.shared->backlog = backlog; + if (uwsgi.vassal_sos_backlog > 0 && uwsgi.has_emperor) { - if (uwsgi.shared->load >= (uint64_t) uwsgi.vassal_sos_backlog) { + if (uwsgi.shared->backlog >= (uint64_t) uwsgi.vassal_sos_backlog) { // ask emperor for help char byte = 30; if (write(uwsgi.emperor_fd, &byte, 1) != 1) { uwsgi_error("write()"); } else { - uwsgi_log_verbose("asking Emperor for reinforcements (backlog: %llu)...\n", (unsigned long long) uwsgi.shared->load); + uwsgi_log_verbose("asking Emperor for reinforcements (backlog: %llu)...\n", (unsigned long long) uwsgi.shared->backlog); } } } diff --git a/core/master_utils.c b/core/master_utils.c index 64b6e7df..18fd692c 100644 --- a/core/master_utils.c +++ b/core/master_utils.c @@ -332,7 +332,7 @@ int uwsgi_cheaper_algo_backlog(int can_spawn) { int i; #ifdef __linux__ - int backlog = uwsgi.shared->load; + int backlog = uwsgi.shared->backlog; #else int backlog = 0; #endif @@ -728,9 +728,9 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { goto end; #ifdef __linux__ - if (uwsgi_stats_keylong_comma(us, "listen_queue", (unsigned long long) uwsgi.shared->load)) + if (uwsgi_stats_keylong_comma(us, "listen_queue", (unsigned long long) uwsgi.shared->backlog)) goto end; - if (uwsgi_stats_keylong_comma(us, "listen_queue_errors", (unsigned long long) uwsgi.shared->load)) + if (uwsgi_stats_keylong_comma(us, "listen_queue_errors", (unsigned long long) uwsgi.shared->backlog_errors)) goto end; #endif diff --git a/core/routing.c b/core/routing.c index 9ff3a014..12f70c34 100644 --- a/core/routing.c +++ b/core/routing.c @@ -1656,7 +1656,7 @@ static char *uwsgi_route_var_uwsgi(struct wsgi_request *wsgi_req, char *key, uin } else if (!uwsgi_strncmp(key, keylen, "lq", 2)) { - ret = uwsgi_num2str(uwsgi.shared->load); + ret = uwsgi_num2str(uwsgi.shared->backlog); *vallen = strlen(ret); } diff --git a/plugins/airbrake/airbrake_plugin.c b/plugins/airbrake/airbrake_plugin.c index 1c1143fc..ee54b72a 100644 --- a/plugins/airbrake/airbrake_plugin.c +++ b/plugins/airbrake/airbrake_plugin.c @@ -222,8 +222,8 @@ static void uwsgi_airbrake_loop(struct uwsgi_thread *ut) { // ARGH !!! if (!curl) return; - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.socket_timeout); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.socket_timeout); curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL); curl_easy_setopt(curl, CURLOPT_READDATA, ut); curl_easy_setopt(curl, CURLOPT_POST, 1L); diff --git a/plugins/alarm_curl/alarm_curl_plugin.c b/plugins/alarm_curl/alarm_curl_plugin.c index 61c7f576..bd04d49d 100644 --- a/plugins/alarm_curl/alarm_curl_plugin.c +++ b/plugins/alarm_curl/alarm_curl_plugin.c @@ -146,8 +146,8 @@ static void uwsgi_alarm_curl_loop(struct uwsgi_thread *ut) { // ARGH !!! if (!curl) return; - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.socket_timeout); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.socket_timeout); curl_easy_setopt(curl, CURLOPT_READFUNCTION, uwsgi_alarm_curl_read_callback); curl_easy_setopt(curl, CURLOPT_READDATA, ut); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); diff --git a/plugins/cheaper_backlog2/cheaper_backlog2.c b/plugins/cheaper_backlog2/cheaper_backlog2.c index ad8089ff..7a4be92c 100644 --- a/plugins/cheaper_backlog2/cheaper_backlog2.c +++ b/plugins/cheaper_backlog2/cheaper_backlog2.c @@ -17,7 +17,7 @@ int cheaper_backlog2_algo(int can_spawn) { int i; #ifdef __linux__ - int backlog = uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS]; + int backlog = uwsgi.socket_timeout; #else int backlog = 0; #endif diff --git a/plugins/cheaper_busyness/cheaper_busyness.c b/plugins/cheaper_busyness/cheaper_busyness.c index 2163b931..f8d8a304 100644 --- a/plugins/cheaper_busyness/cheaper_busyness.c +++ b/plugins/cheaper_busyness/cheaper_busyness.c @@ -164,7 +164,7 @@ int cheaper_busyness_algo(int can_spawn) { } #ifdef __linux__ - int backlog = uwsgi.shared->load; + int backlog = uwsgi.shared->backlog; #endif uint64_t now = uwsgi_micros(); diff --git a/plugins/curl_cron/curl_cron.c b/plugins/curl_cron/curl_cron.c index 4aa2ffdb..38f4f049 100644 --- a/plugins/curl_cron/curl_cron.c +++ b/plugins/curl_cron/curl_cron.c @@ -10,7 +10,7 @@ static void curl_cron_func(struct uwsgi_cron *uc, time_t now) { curl_easy_setopt(curl, CURLOPT_URL, uc->command); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.socket_timeout); // use 1 minute as the cron resolution curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60); uwsgi_log("[uwsgi-curl-cron] requesting %s\n", uc->command); diff --git a/plugins/emperor_mongodb/emperor_mongodb.cc b/plugins/emperor_mongodb/emperor_mongodb.cc index 24efb96a..0719cb9a 100644 --- a/plugins/emperor_mongodb/emperor_mongodb.cc +++ b/plugins/emperor_mongodb/emperor_mongodb.cc @@ -25,7 +25,7 @@ extern "C" void uwsgi_imperial_monitor_mongodb(struct uwsgi_emperor_scanner *ues // the connection object (will be automatically destroyed at each cycle) mongo::DBClientConnection c; // set the socket timeout - c.setSoTimeout(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + c.setSoTimeout(uwsgi.socket_timeout); // connect c.connect(uems->address); diff --git a/plugins/glusterfs/glusterfs.c b/plugins/glusterfs/glusterfs.c index afa0461d..92616b6c 100644 --- a/plugins/glusterfs/glusterfs.c +++ b/plugins/glusterfs/glusterfs.c @@ -200,7 +200,7 @@ static void uwsgi_glusterfs_add_mountpoint(char *arg, size_t arg_len) { static void uwsgi_glusterfs_setup() { if (!uglusterfs.timeout) { - uglusterfs.timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]; + uglusterfs.timeout = uwsgi.socket_timeout; } struct uwsgi_string_list *usl = uglusterfs.mountpoints; diff --git a/plugins/gridfs/gridfs.cc b/plugins/gridfs/gridfs.cc index a019d332..c5434372 100644 --- a/plugins/gridfs/gridfs.cc +++ b/plugins/gridfs/gridfs.cc @@ -169,7 +169,7 @@ static struct uwsgi_gridfs_mountpoint *uwsgi_gridfs_add_mountpoint(char *arg, si ugm->timeout = atoi(ugm->timeout_str); } else { - ugm->timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]; + ugm->timeout = uwsgi.socket_timeout; } if (ugm->prefix) { diff --git a/plugins/pty/pty.c b/plugins/pty/pty.c index dfe68239..87d4f6bf 100644 --- a/plugins/pty/pty.c +++ b/plugins/pty/pty.c @@ -292,7 +292,7 @@ static int uwsgi_pty_client() { uwsgi.restore_tc = 1; } - upty.server_fd = uwsgi_connect(remote, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0); + upty.server_fd = uwsgi_connect(remote, uwsgi.socket_timeout, 0); if (upty.server_fd < 0) { uwsgi_error("uwsgi_pty_client()/connect()"); exit(1); diff --git a/plugins/router_radius/radius.c b/plugins/router_radius/radius.c index c3cfa662..12650e44 100644 --- a/plugins/router_radius/radius.c +++ b/plugins/router_radius/radius.c @@ -104,7 +104,7 @@ static uint16_t uwsgi_radius_auth(struct uwsgi_radius_conf *urc, char *auth, siz } // now wait for the response - int ret = uwsgi.wait_read_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + int ret = uwsgi.wait_read_hook(fd, uwsgi.socket_timeout); if (ret <= 0) goto end; ssize_t rlen = read(fd, access_request, access_request_len); diff --git a/plugins/stats_pusher_mongodb/stats_pusher_mongodb.cc b/plugins/stats_pusher_mongodb/stats_pusher_mongodb.cc index 32ea5bc4..75c52b2e 100644 --- a/plugins/stats_pusher_mongodb/stats_pusher_mongodb.cc +++ b/plugins/stats_pusher_mongodb/stats_pusher_mongodb.cc @@ -40,7 +40,7 @@ extern "C" void stats_pusher_mongodb(struct uwsgi_stats_pusher_instance *uspi, t // the connection object (will be automatically destroyed at each cycle) mongo::DBClientConnection c; // set the socket timeout - c.setSoTimeout(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + c.setSoTimeout(uwsgi.socket_timeout); // connect c.connect(spmc->address); c.insert(spmc->collection, b); diff --git a/plugins/tornado/tornado.c b/plugins/tornado/tornado.c index 53711cac..19e05429 100644 --- a/plugins/tornado/tornado.c +++ b/plugins/tornado/tornado.c @@ -20,8 +20,8 @@ static void uwsgi_opt_setup_tornado(char *opt, char *value, void *null) { // set async mode uwsgi_opt_set_int(opt, value, &uwsgi.async); - if (uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] < 30) { - uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 30; + if (uwsgi.socket_timeout < 30) { + uwsgi.socket_timeout = 30; } // set loop engine uwsgi.loop = "tornado"; @@ -234,8 +234,8 @@ PyObject *py_uwsgi_tornado_accept(PyObject *self, PyObject *args) { wsgi_req->start_of_request_in_sec = wsgi_req->start_of_request/1000000; // enter harakiri mode - if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) { - set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]); + if (uwsgi.harakiri_options.workers > 0) { + set_harakiri(uwsgi.harakiri_options.workers); } uwsgi.async_proto_fd_table[wsgi_req->fd] = wsgi_req; @@ -322,7 +322,7 @@ static void tornado_loop() { uwsgi_log("!!! Running tornado without threads IS NOT recommended, enable them with --enable-threads !!!\n"); } - if (uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] < 30) { + if (uwsgi.socket_timeout < 30) { uwsgi_log("!!! Running tornado with a socket-timeout lower than 30 seconds is not recommended, tune it with --socket-timeout !!!\n"); } diff --git a/plugins/tuntap/tuntap.c b/plugins/tuntap/tuntap.c index 9807cea1..def027a5 100644 --- a/plugins/tuntap/tuntap.c +++ b/plugins/tuntap/tuntap.c @@ -500,7 +500,7 @@ void tuntaprouter_send_stats(struct uwsgi_tuntap_router *uttr) { size_t remains = us->pos; off_t pos = 0; while(remains > 0) { - int ret = uwsgi_waitfd_write(client_fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + int ret = uwsgi_waitfd_write(client_fd, uwsgi.socket_timeout); if (ret <= 0) { goto end0; } diff --git a/plugins/zabbix/plugin.c b/plugins/zabbix/plugin.c index 7d3a1320..5229ace3 100644 --- a/plugins/zabbix/plugin.c +++ b/plugins/zabbix/plugin.c @@ -110,7 +110,7 @@ end: if (error) return; - int fd = uwsgi_connect(zn->addr, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0); + int fd = uwsgi_connect(zn->addr, uwsgi.socket_timeout, 0); if (fd < 0) { uwsgi_error("stats_pusher_zabbix()/connect()"); return; diff --git a/uwsgi.h b/uwsgi.h index 56c30808..89cbbf10 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2765,6 +2765,9 @@ struct uwsgi_shared { struct uwsgi_cron cron[MAX_CRONS]; int cron_cnt; + uint64_t backlog; + uint64_t backlog_errors; + // gateways struct uwsgi_gateway gateways[MAX_GATEWAYS]; int gateways_cnt;