]> git.kaiwu.me - nginx.git/commitdiff
Core: added a warning about reusing connections.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 10 Aug 2020 15:52:59 +0000 (18:52 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 10 Aug 2020 15:52:59 +0000 (18:52 +0300)
Previously, reusing connections happened silently and was only
visible in monitoring systems.  This was shown to be not very user-friendly,
and administrators often didn't realize there were too few connections
available to withstand the load, and configured timeouts (keepalive_timeout
and http2_idle_timeout) were effectively reduced to keep things running.

To provide at least some information about this, a warning is now logged
(at most once per second, to avoid flooding the logs).

src/core/ngx_connection.c
src/core/ngx_cycle.h

index 88fefcea269fdfc50c0ac5a2ea625a8c703651b8..91e1b3b2e228c746ca881a86655e9b64e1d9506c 100644 (file)
@@ -1298,6 +1298,19 @@ ngx_drain_connections(ngx_cycle_t *cycle)
     ngx_queue_t       *q;
     ngx_connection_t  *c;
 
+    if (cycle->reusable_connections_n == 0) {
+        return;
+    }
+
+    if (cycle->connections_reuse_time != ngx_time()) {
+        cycle->connections_reuse_time = ngx_time();
+
+        ngx_log_error(NGX_LOG_WARN, cycle->log, 0,
+                      "%ui worker_connections are not enough, "
+                      "reusing connections",
+                      cycle->connection_n);
+    }
+
     n = ngx_max(ngx_min(32, cycle->reusable_connections_n / 8), 1);
 
     for (i = 0; i < n; i++) {
index 54fa2e6bfcf8cae93602c35c680b3dd36bc14f1b..0f7d9bc741ad4762742f7890be52911026d886db 100644 (file)
@@ -55,6 +55,7 @@ struct ngx_cycle_s {
 
     ngx_queue_t               reusable_connections_queue;
     ngx_uint_t                reusable_connections_n;
+    time_t                    connections_reuse_time;
 
     ngx_array_t               listening;
     ngx_array_t               paths;