diff --git a/src/base.h b/src/base.h index 755c045e..8a43ab1b 100644 --- a/src/base.h +++ b/src/base.h @@ -170,7 +170,7 @@ struct server { int cur_fds; /* currently used fds */ int sockets_disabled; - uint32_t max_conns; + uint32_t lim_conns; connection *conns_pool; log_error_st *errh; diff --git a/src/connections.c b/src/connections.c index 215f77cf..502aa703 100644 --- a/src/connections.c +++ b/src/connections.c @@ -50,6 +50,7 @@ static void connection_reset(connection *con); static connection *connections_get_new_connection(server *srv) { connections * const conns = &srv->conns; connection *con; + --srv->lim_conns; if (srv->conns_pool) { con = srv->conns_pool; srv->conns_pool = con->next; @@ -70,6 +71,7 @@ static void connection_del(server *srv, connection *con) { connections * const conns = &srv->conns; if (con->ndx != --conns->used) /* not last element */ (conns->ptr[con->ndx] = conns->ptr[conns->used])->ndx = con->ndx; + ++srv->lim_conns; } static void connection_close(connection *con) { diff --git a/src/mod_status.c b/src/mod_status.c index 4f846263..7be98ae5 100644 --- a/src/mod_status.c +++ b/src/mod_status.c @@ -543,7 +543,7 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st * "\n" "
\n" "")); - buffer_append_int(b, srv->conns.used); + buffer_append_int(b, srv->srvconf.max_conns - srv->lim_conns); buffer_append_string_len(b, CONST_STR_LEN(" connections\n")); int per_line = 50; @@ -629,10 +629,10 @@ static handler_t mod_status_handle_server_status_text(server *srv, request_st * buffer_append_int(b, log_epoch_secs - srv->startup_ts); buffer_append_string_len(b, CONST_STR_LEN("\nBusyServers: ")); - buffer_append_int(b, srv->conns.used); + buffer_append_int(b, srv->srvconf.max_conns - srv->lim_conns); buffer_append_string_len(b, CONST_STR_LEN("\nIdleServers: ")); - buffer_append_int(b, srv->conns.size - srv->conns.used); + buffer_append_int(b, srv->lim_conns); /*(could omit)*/ buffer_append_string_len(b, CONST_STR_LEN("\nScoreboard: ")); for (uint32_t i = 0; i < srv->conns.used; ++i) { @@ -645,7 +645,7 @@ static handler_t mod_status_handle_server_status_text(server *srv, request_st * : mod_status_get_short_state(cr->state); buffer_append_string_len(b, state, 1); } - for (uint32_t i = 0; i < srv->conns.size - srv->conns.used; ++i) { + for (uint32_t i = 0; i < srv->lim_conns; ++i) { /*(could omit)*/ buffer_append_string_len(b, CONST_STR_LEN("_")); } buffer_append_string_len(b, CONST_STR_LEN("\n")); @@ -689,10 +689,10 @@ static handler_t mod_status_handle_server_status_json(server *srv, request_st * buffer_append_int(b, log_epoch_secs - srv->startup_ts); buffer_append_string_len(b, CONST_STR_LEN(",\n\t\"BusyServers\": ")); - buffer_append_int(b, srv->conns.used); + buffer_append_int(b, srv->srvconf.max_conns - srv->lim_conns); buffer_append_string_len(b, CONST_STR_LEN(",\n\t\"IdleServers\": ")); - buffer_append_int(b, srv->conns.size - srv->conns.used); + buffer_append_int(b, srv->lim_conns); /*(could omit)*/ buffer_append_string_len(b, CONST_STR_LEN(",\n")); for (j = 0, avg = 0; j < 5; j++) { diff --git a/src/network.c b/src/network.c index 860d54ba..58fcb70a 100644 --- a/src/network.c +++ b/src/network.c @@ -55,7 +55,7 @@ static handler_t network_server_handle_fdevent(void *context, int revents) { /* accept()s at most 100 new connections before * jumping out to process events on other connections */ - int loops = (int)(srv->max_conns - srv->conns.used); + int loops = (int)srv->lim_conns; if (loops > 100) loops = 100; else if (loops <= 0) diff --git a/src/server.c b/src/server.c index 8d2077cf..5681cf49 100644 --- a/src/server.c +++ b/src/server.c @@ -963,7 +963,7 @@ static int server_graceful_state_bg (server *srv) { * to allow graceful shutdown tasks to be run by server and by modules) */ log_error(srv->errh, __FILE__, __LINE__, "[note] pid %lld continuing to handle %u connection(s) in progress", - (long long)getpid(), srv->conns.used); + (long long)getpid(), srv->srvconf.max_conns - srv->lim_conns); if (0 == srv->srvconf.max_worker) { /* reset graceful_shutdown; wait for signal from restarted server */ @@ -1036,7 +1036,7 @@ static void server_sockets_disable (server *srv) { server_sockets_set_event(srv, 0); srv->sockets_disabled = 1; log_error(srv->errh, __FILE__, __LINE__, - (srv->conns.used >= srv->max_conns) + (0 == srv->lim_conns) ? "[note] sockets disabled, connection limit reached" : "[note] sockets disabled, out-of-fds"); } @@ -1046,13 +1046,13 @@ static void server_overload_check (server *srv) { if (srv->fdwaitqueue.used) return; - if (srv->cur_fds < srv->max_fds_lowat && srv->conns.used < srv->max_conns) + if (srv->cur_fds < srv->max_fds_lowat && 0 != srv->lim_conns) server_sockets_enable(srv); } static void server_load_check (server *srv) { /* check if hit limits for num fds used or num connections */ - if (srv->cur_fds > srv->max_fds_hiwat || srv->conns.used >= srv->max_conns) + if (srv->cur_fds > srv->max_fds_hiwat || 0 == srv->lim_conns) server_sockets_disable(srv); } @@ -1758,13 +1758,13 @@ static int server_main_setup (server * const srv, int argc, char **argv) { log_error(srv->errh, __FILE__, __LINE__, "can't have more connections than fds/2: %hu %d", srv->srvconf.max_conns, srv->max_fds); - srv->max_conns = srv->srvconf.max_conns = srv->max_fds/2; + srv->lim_conns = srv->srvconf.max_conns = srv->max_fds/2; } else if (srv->srvconf.max_conns) { /* otherwise respect the wishes of the user */ - srv->max_conns = srv->srvconf.max_conns; + srv->lim_conns = srv->srvconf.max_conns; } else { /* or use the default: we really don't want to hit max-fds */ - srv->max_conns = srv->srvconf.max_conns = srv->max_fds/3; + srv->lim_conns = srv->srvconf.max_conns = srv->max_fds/3; } connections_init(srv);