Klaus Demo nginx / ce1e64f
prepare to allow various number of connections in child processes Igor Sysoev 13 years ago
3 changed file(s) with 36 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
142142 static ngx_int_t
143143 ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
144144 {
145 ngx_event_conf_t *ecf;
146145 ngx_epoll_conf_t *epcf;
147146
148 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
149
150147 epcf = ngx_event_get_conf(cycle->conf_ctx, ngx_epoll_module);
151148
152149 if (ep == -1) {
153 ep = epoll_create(ecf->connections / 2);
150 ep = epoll_create(cycle->connection_n / 2);
154151
155152 if (ep == -1) {
156153 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
435435
436436 #if !(NGX_WIN32)
437437
438 if ((unsigned) ecf->connections > FD_SETSIZE) {
438 if (cycle->connection_n > FD_SETSIZE) {
439439 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
440440 "the maximum number of files "
441 "supported by select() is " ngx_value(FD_SETSIZE));
441 "supported by select() is %ud", FD_SETSIZE);
442442 return NGX_CONF_ERROR;
443443 }
444444
595595 return NGX_ERROR;
596596 }
597597
598 cycle->connection_n = ecf->connections;
599
600598 for (m = 0; ngx_modules[m]; m++) {
601599 if (ngx_modules[m]->type != NGX_EVENT_MODULE) {
602600 continue;
603601 }
604602
605 if (ngx_modules[m]->ctx_index == ecf->use) {
606 module = ngx_modules[m]->ctx;
607 if (module->actions.init(cycle, ngx_timer_resolution) == NGX_ERROR)
608 {
609 /* fatal */
610 exit(2);
611 }
612 break;
613 }
603 if (ngx_modules[m]->ctx_index != ecf->use) {
604 continue;
605 }
606
607 module = ngx_modules[m]->ctx;
608
609 if (module->actions.init(cycle, ngx_timer_resolution) != NGX_OK) {
610 /* fatal */
611 exit(2);
612 }
613
614 break;
614615 }
615616
616617 #if !(NGX_WIN32)
660661
661662 #endif
662663
663 cycle->connections = ngx_alloc(sizeof(ngx_connection_t) * ecf->connections,
664 cycle->log);
664 cycle->connections =
665 ngx_alloc(sizeof(ngx_connection_t) * cycle->connection_n, cycle->log);
665666 if (cycle->connections == NULL) {
666667 return NGX_ERROR;
667668 }
668669
669670 c = cycle->connections;
670671
671 cycle->read_events = ngx_alloc(sizeof(ngx_event_t) * ecf->connections,
672 cycle->read_events = ngx_alloc(sizeof(ngx_event_t) * cycle->connection_n,
672673 cycle->log);
673674 if (cycle->read_events == NULL) {
674675 return NGX_ERROR;
684685 #endif
685686 }
686687
687 cycle->write_events = ngx_alloc(sizeof(ngx_event_t) * ecf->connections,
688 cycle->write_events = ngx_alloc(sizeof(ngx_event_t) * cycle->connection_n,
688689 cycle->log);
689690 if (cycle->write_events == NULL) {
690691 return NGX_ERROR;
718719 } while (i);
719720
720721 cycle->free_connections = next;
721 cycle->free_connection_n = ecf->connections;
722 cycle->free_connection_n = cycle->connection_n;
722723
723724 /* for each listening socket */
724725
11361137 ngx_uint_t rtsig;
11371138 ngx_core_conf_t *ccf;
11381139 #endif
1139 ngx_int_t i, connections;
1140 ngx_int_t i;
11401141 ngx_module_t *module;
11411142 ngx_event_module_t *event_module;
11421143
1143 connections = NGX_CONF_UNSET_UINT;
11441144 module = NULL;
11451145
11461146 #if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)
11491149
11501150 if (fd != -1) {
11511151 close(fd);
1152 connections = DEFAULT_CONNECTIONS;
11531152 module = &ngx_epoll_module;
11541153
11551154 } else if (ngx_errno != NGX_ENOSYS) {
1156 connections = DEFAULT_CONNECTIONS;
11571155 module = &ngx_epoll_module;
11581156 }
11591157
11621160 #if (NGX_HAVE_RTSIG)
11631161
11641162 if (module == NULL) {
1165 connections = DEFAULT_CONNECTIONS;
11661163 module = &ngx_rtsig_module;
11671164 rtsig = 1;
11681165
11741171
11751172 #if (NGX_HAVE_DEVPOLL)
11761173
1177 connections = DEFAULT_CONNECTIONS;
11781174 module = &ngx_devpoll_module;
11791175
11801176 #endif
11811177
11821178 #if (NGX_HAVE_KQUEUE)
11831179
1184 connections = DEFAULT_CONNECTIONS;
11851180 module = &ngx_kqueue_module;
11861181
11871182 #endif
11891184 #if (NGX_HAVE_SELECT)
11901185
11911186 if (module == NULL) {
1192
1193 #if (NGX_WIN32 || FD_SETSIZE >= DEFAULT_CONNECTIONS)
1194 connections = DEFAULT_CONNECTIONS;
1195 #else
1196 connections = FD_SETSIZE;
1197 #endif
11981187 module = &ngx_select_module;
11991188 }
12001189
12021191
12031192 if (module == NULL) {
12041193 for (i = 0; ngx_modules[i]; i++) {
1205 if (ngx_modules[i]->type == NGX_EVENT_MODULE) {
1206 event_module = ngx_modules[i]->ctx;
1207
1208 if (ngx_strcmp(event_module->name->data, event_core_name.data)
1209 == 0)
1210 {
1211 continue;
1212 }
1213
1214 module = ngx_modules[i];
1215 break;
1216 }
1194
1195 if (ngx_modules[i]->type != NGX_EVENT_MODULE) {
1196 continue;
1197 }
1198
1199 event_module = ngx_modules[i]->ctx;
1200
1201 if (ngx_strcmp(event_module->name->data, event_core_name.data) == 0)
1202 {
1203 continue;
1204 }
1205
1206 module = ngx_modules[i];
1207 break;
12171208 }
12181209 }
12191210
12221213 return NGX_CONF_ERROR;
12231214 }
12241215
1225 ngx_conf_init_uint_value(ecf->connections, connections);
1216 ngx_conf_init_uint_value(ecf->connections, DEFAULT_CONNECTIONS);
12261217 cycle->connection_n = ecf->connections;
12271218
12281219 ngx_conf_init_uint_value(ecf->use, module->ctx_index);