prepare to allow various number of connections in child processes

This commit is contained in:
Igor Sysoev 2008-06-23 13:23:29 +00:00
parent f2a1484347
commit ce1e64f404
3 changed files with 33 additions and 45 deletions

View File

@ -143,15 +143,12 @@ ngx_module_t ngx_epoll_module = {
static ngx_int_t static ngx_int_t
ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer) ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
{ {
ngx_event_conf_t *ecf;
ngx_epoll_conf_t *epcf; ngx_epoll_conf_t *epcf;
ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
epcf = ngx_event_get_conf(cycle->conf_ctx, ngx_epoll_module); epcf = ngx_event_get_conf(cycle->conf_ctx, ngx_epoll_module);
if (ep == -1) { if (ep == -1) {
ep = epoll_create(ecf->connections / 2); ep = epoll_create(cycle->connection_n / 2);
if (ep == -1) { if (ep == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,

View File

@ -436,10 +436,10 @@ ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
#if !(NGX_WIN32) #if !(NGX_WIN32)
if ((unsigned) ecf->connections > FD_SETSIZE) { if (cycle->connection_n > FD_SETSIZE) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"the maximum number of files " "the maximum number of files "
"supported by select() is " ngx_value(FD_SETSIZE)); "supported by select() is %ud", FD_SETSIZE);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }

View File

@ -596,22 +596,23 @@ ngx_event_process_init(ngx_cycle_t *cycle)
return NGX_ERROR; return NGX_ERROR;
} }
cycle->connection_n = ecf->connections;
for (m = 0; ngx_modules[m]; m++) { for (m = 0; ngx_modules[m]; m++) {
if (ngx_modules[m]->type != NGX_EVENT_MODULE) { if (ngx_modules[m]->type != NGX_EVENT_MODULE) {
continue; continue;
} }
if (ngx_modules[m]->ctx_index == ecf->use) { if (ngx_modules[m]->ctx_index != ecf->use) {
module = ngx_modules[m]->ctx; continue;
if (module->actions.init(cycle, ngx_timer_resolution) == NGX_ERROR)
{
/* fatal */
exit(2);
}
break;
} }
module = ngx_modules[m]->ctx;
if (module->actions.init(cycle, ngx_timer_resolution) != NGX_OK) {
/* fatal */
exit(2);
}
break;
} }
#if !(NGX_WIN32) #if !(NGX_WIN32)
@ -661,15 +662,15 @@ ngx_event_process_init(ngx_cycle_t *cycle)
#endif #endif
cycle->connections = ngx_alloc(sizeof(ngx_connection_t) * ecf->connections, cycle->connections =
cycle->log); ngx_alloc(sizeof(ngx_connection_t) * cycle->connection_n, cycle->log);
if (cycle->connections == NULL) { if (cycle->connections == NULL) {
return NGX_ERROR; return NGX_ERROR;
} }
c = cycle->connections; c = cycle->connections;
cycle->read_events = ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->read_events = ngx_alloc(sizeof(ngx_event_t) * cycle->connection_n,
cycle->log); cycle->log);
if (cycle->read_events == NULL) { if (cycle->read_events == NULL) {
return NGX_ERROR; return NGX_ERROR;
@ -685,7 +686,7 @@ ngx_event_process_init(ngx_cycle_t *cycle)
#endif #endif
} }
cycle->write_events = ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->write_events = ngx_alloc(sizeof(ngx_event_t) * cycle->connection_n,
cycle->log); cycle->log);
if (cycle->write_events == NULL) { if (cycle->write_events == NULL) {
return NGX_ERROR; return NGX_ERROR;
@ -719,7 +720,7 @@ ngx_event_process_init(ngx_cycle_t *cycle)
} while (i); } while (i);
cycle->free_connections = next; cycle->free_connections = next;
cycle->free_connection_n = ecf->connections; cycle->free_connection_n = cycle->connection_n;
/* for each listening socket */ /* for each listening socket */
@ -1137,11 +1138,10 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_uint_t rtsig; ngx_uint_t rtsig;
ngx_core_conf_t *ccf; ngx_core_conf_t *ccf;
#endif #endif
ngx_int_t i, connections; ngx_int_t i;
ngx_module_t *module; ngx_module_t *module;
ngx_event_module_t *event_module; ngx_event_module_t *event_module;
connections = NGX_CONF_UNSET_UINT;
module = NULL; module = NULL;
#if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL) #if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)
@ -1150,11 +1150,9 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
if (fd != -1) { if (fd != -1) {
close(fd); close(fd);
connections = DEFAULT_CONNECTIONS;
module = &ngx_epoll_module; module = &ngx_epoll_module;
} else if (ngx_errno != NGX_ENOSYS) { } else if (ngx_errno != NGX_ENOSYS) {
connections = DEFAULT_CONNECTIONS;
module = &ngx_epoll_module; module = &ngx_epoll_module;
} }
@ -1163,7 +1161,6 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
#if (NGX_HAVE_RTSIG) #if (NGX_HAVE_RTSIG)
if (module == NULL) { if (module == NULL) {
connections = DEFAULT_CONNECTIONS;
module = &ngx_rtsig_module; module = &ngx_rtsig_module;
rtsig = 1; rtsig = 1;
@ -1175,14 +1172,12 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
#if (NGX_HAVE_DEVPOLL) #if (NGX_HAVE_DEVPOLL)
connections = DEFAULT_CONNECTIONS;
module = &ngx_devpoll_module; module = &ngx_devpoll_module;
#endif #endif
#if (NGX_HAVE_KQUEUE) #if (NGX_HAVE_KQUEUE)
connections = DEFAULT_CONNECTIONS;
module = &ngx_kqueue_module; module = &ngx_kqueue_module;
#endif #endif
@ -1190,12 +1185,6 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
#if (NGX_HAVE_SELECT) #if (NGX_HAVE_SELECT)
if (module == NULL) { if (module == NULL) {
#if (NGX_WIN32 || FD_SETSIZE >= DEFAULT_CONNECTIONS)
connections = DEFAULT_CONNECTIONS;
#else
connections = FD_SETSIZE;
#endif
module = &ngx_select_module; module = &ngx_select_module;
} }
@ -1203,18 +1192,20 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
if (module == NULL) { if (module == NULL) {
for (i = 0; ngx_modules[i]; i++) { for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type == NGX_EVENT_MODULE) {
event_module = ngx_modules[i]->ctx;
if (ngx_strcmp(event_module->name->data, event_core_name.data) if (ngx_modules[i]->type != NGX_EVENT_MODULE) {
== 0) continue;
{
continue;
}
module = ngx_modules[i];
break;
} }
event_module = ngx_modules[i]->ctx;
if (ngx_strcmp(event_module->name->data, event_core_name.data) == 0)
{
continue;
}
module = ngx_modules[i];
break;
} }
} }
@ -1223,7 +1214,7 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
ngx_conf_init_uint_value(ecf->connections, connections); ngx_conf_init_uint_value(ecf->connections, DEFAULT_CONNECTIONS);
cycle->connection_n = ecf->connections; cycle->connection_n = ecf->connections;
ngx_conf_init_uint_value(ecf->use, module->ctx_index); ngx_conf_init_uint_value(ecf->use, module->ctx_index);