comparison src/core/ngx_connection.c @ 6220:5e6142609e48

Core: idle connections now closed only once on exiting. Iterating through all connections takes a lot of CPU time, especially with large number of worker connections configured. As a result nginx processes used to consume CPU time during graceful shutdown. To mitigate this we now only do a full scan for idle connections when shutdown signal is received. Transitions of connections to idle ones are now expected to be avoided if the ngx_exiting flag is set. The upstream keepalive module was modified to follow this.
author Valentin Bartenev <vbart@nginx.com>
date Tue, 11 Aug 2015 16:28:55 +0300
parents 3096ae76ba47
children 954b67727af3
comparison
equal deleted inserted replaced
6219:808fd1f0b94b 6220:5e6142609e48
1157 ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, 1157 ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0,
1158 "reusing connection"); 1158 "reusing connection");
1159 1159
1160 c->close = 1; 1160 c->close = 1;
1161 c->read->handler(c->read); 1161 c->read->handler(c->read);
1162 }
1163 }
1164
1165
1166 void
1167 ngx_close_idle_connections(ngx_cycle_t *cycle)
1168 {
1169 ngx_uint_t i;
1170 ngx_connection_t *c;
1171
1172 c = cycle->connections;
1173
1174 for (i = 0; i < cycle->connection_n; i++) {
1175
1176 /* THREAD: lock */
1177
1178 if (c[i].fd != -1 && c[i].idle) {
1179 c[i].close = 1;
1180 c[i].read->handler(c[i].read);
1181 }
1162 } 1182 }
1163 } 1183 }
1164 1184
1165 1185
1166 ngx_int_t 1186 ngx_int_t