comparison src/event/modules/ngx_epoll_module.c @ 4134:a3203c4521c6

The "worker_aio_requests" directive. The default value is 32 AIO simultaneous requests per worker. Previously they were hardcoded to 1024, and it was too large, since Linux allocated them early on io_setup(), but not on request itself. So with default value of /proc/sys/fs/aio-max-nr equal to 65536 only 64 worker processes could be run simultaneously. 32 AIO requests are enough for modern disks even if server runs only 1 worker.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 20 Sep 2011 07:30:09 +0000
parents 04751572f900
children f68047884e83
comparison
equal deleted inserted replaced
4133:59b99f217c6d 4134:a3203c4521c6
84 #endif 84 #endif
85 85
86 86
87 typedef struct { 87 typedef struct {
88 ngx_uint_t events; 88 ngx_uint_t events;
89 ngx_uint_t aio_requests;
89 } ngx_epoll_conf_t; 90 } ngx_epoll_conf_t;
90 91
91 92
92 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer); 93 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer);
93 static void ngx_epoll_done(ngx_cycle_t *cycle); 94 static void ngx_epoll_done(ngx_cycle_t *cycle);
129 { ngx_string("epoll_events"), 130 { ngx_string("epoll_events"),
130 NGX_EVENT_CONF|NGX_CONF_TAKE1, 131 NGX_EVENT_CONF|NGX_CONF_TAKE1,
131 ngx_conf_set_num_slot, 132 ngx_conf_set_num_slot,
132 0, 133 0,
133 offsetof(ngx_epoll_conf_t, events), 134 offsetof(ngx_epoll_conf_t, events),
135 NULL },
136
137 { ngx_string("worker_aio_requests"),
138 NGX_EVENT_CONF|NGX_CONF_TAKE1,
139 ngx_conf_set_num_slot,
140 0,
141 offsetof(ngx_epoll_conf_t, aio_requests),
134 NULL }, 142 NULL },
135 143
136 ngx_null_command 144 ngx_null_command
137 }; 145 };
138 146
205 return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo); 213 return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo);
206 } 214 }
207 215
208 216
209 static void 217 static void
210 ngx_epoll_aio_init(ngx_cycle_t *cycle) 218 ngx_epoll_aio_init(ngx_cycle_t *cycle, ngx_epoll_conf_t *epcf)
211 { 219 {
212 int n; 220 int n;
213 struct epoll_event ee; 221 struct epoll_event ee;
214 222
215 ngx_eventfd = syscall(SYS_eventfd, 0); 223 ngx_eventfd = syscall(SYS_eventfd, 0);
230 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 238 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
231 "ioctl(eventfd, FIONBIO) failed"); 239 "ioctl(eventfd, FIONBIO) failed");
232 goto failed; 240 goto failed;
233 } 241 }
234 242
235 if (io_setup(1024, &ngx_aio_ctx) == -1) { 243 if (io_setup(epcf->aio_requests, &ngx_aio_ctx) == -1) {
236 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 244 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
237 "io_setup() failed"); 245 "io_setup() failed");
238 goto failed; 246 goto failed;
239 } 247 }
240 248
292 return NGX_ERROR; 300 return NGX_ERROR;
293 } 301 }
294 302
295 #if (NGX_HAVE_FILE_AIO) 303 #if (NGX_HAVE_FILE_AIO)
296 304
297 ngx_epoll_aio_init(cycle); 305 ngx_epoll_aio_init(cycle, epcf);
298 306
299 #endif 307 #endif
300 } 308 }
301 309
302 if (nevents < epcf->events) { 310 if (nevents < epcf->events) {
792 if (epcf == NULL) { 800 if (epcf == NULL) {
793 return NULL; 801 return NULL;
794 } 802 }
795 803
796 epcf->events = NGX_CONF_UNSET; 804 epcf->events = NGX_CONF_UNSET;
805 epcf->aio_requests = NGX_CONF_UNSET;
797 806
798 return epcf; 807 return epcf;
799 } 808 }
800 809
801 810
803 ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf) 812 ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf)
804 { 813 {
805 ngx_epoll_conf_t *epcf = conf; 814 ngx_epoll_conf_t *epcf = conf;
806 815
807 ngx_conf_init_uint_value(epcf->events, 512); 816 ngx_conf_init_uint_value(epcf->events, 512);
817 ngx_conf_init_uint_value(epcf->aio_requests, 32);
808 818
809 return NGX_CONF_OK; 819 return NGX_CONF_OK;
810 } 820 }