summaryrefslogtreecommitdiff
path: root/src/event
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2011-09-20 11:21:32 +0000
committerJonathan Kolb <jon@b0g.us>2011-09-20 11:21:32 +0000
commit73e4a20a129d2afb1c5a1e1bb0a5d6966d9f5e5e (patch)
tree2b3effcc3781c00b66e25b5fc5cdeb97f4af962a /src/event
parentf4ca46af8aa347d4fd13c1db55a9a4e79bfacc92 (diff)
downloadnginx-da7460d7520d5b72afec5c32f15af4262c870fa1.tar.gz
Changes with nginx 1.1.4 20 Sep 2011v1.1.4
*) Feature: the ngx_http_upstream_keepalive module. *) Feature: the "proxy_http_version" directive. *) Feature: the "fastcgi_keep_conn" directive. *) Feature: the "worker_aio_requests" directive. *) Bugfix: if nginx was built --with-file-aio it could not be run on Linux kernel which did not support AIO. *) Bugfix: in Linux AIO error processing. Thanks to Hagai Avrahami. *) Bugfix: reduced memory consumption for long-lived requests. *) Bugfix: the module ngx_http_mp4_module did not support 64-bit MP4 "co64" atom.
Diffstat (limited to 'src/event')
-rw-r--r--src/event/modules/ngx_epoll_module.c152
-rw-r--r--src/event/ngx_event.c2
-rw-r--r--src/event/ngx_event_pipe.c34
-rw-r--r--src/event/ngx_event_pipe.h1
-rw-r--r--src/event/ngx_event_timer.c10
5 files changed, 138 insertions, 61 deletions
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c
index e30501b00..31c10c6dc 100644
--- a/src/event/modules/ngx_epoll_module.c
+++ b/src/event/modules/ngx_epoll_module.c
@@ -86,6 +86,7 @@ int eventfd(u_int initval)
typedef struct {
ngx_uint_t events;
+ ngx_uint_t aio_requests;
} ngx_epoll_conf_t;
@@ -133,6 +134,13 @@ static ngx_command_t ngx_epoll_commands[] = {
offsetof(ngx_epoll_conf_t, events),
NULL },
+ { ngx_string("worker_aio_requests"),
+ NGX_EVENT_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ 0,
+ offsetof(ngx_epoll_conf_t, aio_requests),
+ NULL },
+
ngx_null_command
};
@@ -184,7 +192,7 @@ ngx_module_t ngx_epoll_module = {
* into single eventfd() function with different number of parameters.
*/
-static long
+static int
io_setup(u_int nr_reqs, aio_context_t *ctx)
{
return syscall(SYS_io_setup, nr_reqs, ctx);
@@ -198,13 +206,81 @@ io_destroy(aio_context_t ctx)
}
-static long
+static int
io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events,
struct timespec *tmo)
{
return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo);
}
+
+static void
+ngx_epoll_aio_init(ngx_cycle_t *cycle, ngx_epoll_conf_t *epcf)
+{
+ int n;
+ struct epoll_event ee;
+
+ ngx_eventfd = syscall(SYS_eventfd, 0);
+
+ if (ngx_eventfd == -1) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "eventfd() failed");
+ ngx_file_aio = 0;
+ return;
+ }
+
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "eventfd: %d", ngx_eventfd);
+
+ n = 1;
+
+ if (ioctl(ngx_eventfd, FIONBIO, &n) == -1) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "ioctl(eventfd, FIONBIO) failed");
+ goto failed;
+ }
+
+ if (io_setup(epcf->aio_requests, &ngx_aio_ctx) == -1) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "io_setup() failed");
+ goto failed;
+ }
+
+ ngx_eventfd_event.data = &ngx_eventfd_conn;
+ ngx_eventfd_event.handler = ngx_epoll_eventfd_handler;
+ ngx_eventfd_event.log = cycle->log;
+ ngx_eventfd_event.active = 1;
+ ngx_eventfd_conn.fd = ngx_eventfd;
+ ngx_eventfd_conn.read = &ngx_eventfd_event;
+ ngx_eventfd_conn.log = cycle->log;
+
+ ee.events = EPOLLIN|EPOLLET;
+ ee.data.ptr = &ngx_eventfd_conn;
+
+ if (epoll_ctl(ep, EPOLL_CTL_ADD, ngx_eventfd, &ee) != -1) {
+ return;
+ }
+
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "epoll_ctl(EPOLL_CTL_ADD, eventfd) failed");
+
+ if (io_destroy(ngx_aio_ctx) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "io_destroy() failed");
+ }
+
+failed:
+
+ if (close(ngx_eventfd) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "eventfd close() failed");
+ }
+
+ ngx_eventfd = -1;
+ ngx_aio_ctx = 0;
+ ngx_file_aio = 0;
+}
+
#endif
@@ -225,52 +301,9 @@ ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
}
#if (NGX_HAVE_FILE_AIO)
- {
- int n;
- struct epoll_event ee;
-
- ngx_eventfd = syscall(SYS_eventfd, 0);
-
- if (ngx_eventfd == -1) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "eventfd() failed");
- return NGX_ERROR;
- }
-
- n = 1;
-
- if (ioctl(ngx_eventfd, FIONBIO, &n) == -1) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "ioctl(eventfd, FIONBIO) failed");
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "eventfd: %d", ngx_eventfd);
- n = io_setup(1024, &ngx_aio_ctx);
+ ngx_epoll_aio_init(cycle, epcf);
- if (n != 0) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, -n, "io_setup() failed");
- return NGX_ERROR;
- }
-
- ngx_eventfd_event.data = &ngx_eventfd_conn;
- ngx_eventfd_event.handler = ngx_epoll_eventfd_handler;
- ngx_eventfd_event.log = cycle->log;
- ngx_eventfd_event.active = 1;
- ngx_eventfd_conn.fd = ngx_eventfd;
- ngx_eventfd_conn.read = &ngx_eventfd_event;
- ngx_eventfd_conn.log = cycle->log;
-
- ee.events = EPOLLIN|EPOLLET;
- ee.data.ptr = &ngx_eventfd_conn;
-
- if (epoll_ctl(ep, EPOLL_CTL_ADD, ngx_eventfd, &ee) == -1) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "epoll_ctl(EPOLL_CTL_ADD, eventfd) failed");
- return NGX_ERROR;
- }
- }
#endif
}
@@ -316,9 +349,19 @@ ngx_epoll_done(ngx_cycle_t *cycle)
#if (NGX_HAVE_FILE_AIO)
- if (io_destroy(ngx_aio_ctx) != 0) {
- ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
- "io_destroy() failed");
+ if (ngx_eventfd != -1) {
+
+ if (io_destroy(ngx_aio_ctx) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "io_destroy() failed");
+ }
+
+ if (close(ngx_eventfd) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "eventfd close() failed");
+ }
+
+ ngx_eventfd = -1;
}
ngx_aio_ctx = 0;
@@ -667,8 +710,8 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
static void
ngx_epoll_eventfd_handler(ngx_event_t *ev)
{
- int n;
- long i, events;
+ int n, events;
+ long i;
uint64_t ready;
ngx_err_t err;
ngx_event_t *e;
@@ -738,8 +781,9 @@ ngx_epoll_eventfd_handler(ngx_event_t *ev)
return;
}
- /* events < 0 */
- ngx_log_error(NGX_LOG_ALERT, ev->log, -events, "io_getevents() failed");
+ /* events == -1 */
+ ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
+ "io_getevents() failed");
return;
}
}
@@ -758,6 +802,7 @@ ngx_epoll_create_conf(ngx_cycle_t *cycle)
}
epcf->events = NGX_CONF_UNSET;
+ epcf->aio_requests = NGX_CONF_UNSET;
return epcf;
}
@@ -769,6 +814,7 @@ ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_epoll_conf_t *epcf = conf;
ngx_conf_init_uint_value(epcf->events, 512);
+ ngx_conf_init_uint_value(epcf->aio_requests, 32);
return NGX_CONF_OK;
}
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index c57d37ec4..8a472ffe8 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -1027,7 +1027,7 @@ ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
"when the server runs without a master process "
"the \"%V\" event type must be the same as "
"in previous configuration - \"%s\" "
- "and it can not be changed on the fly, "
+ "and it cannot be changed on the fly, "
"to change it you need to stop server "
"and start it again",
&value[1], old_ecf->name);
diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c
index 53d738f0a..4f45bb872 100644
--- a/src/event/ngx_event_pipe.c
+++ b/src/event/ngx_event_pipe.c
@@ -392,8 +392,32 @@ ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
cl->buf->file_last - cl->buf->file_pos);
}
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
+ "pipe length: %O", p->length);
+
#endif
+ if (p->free_raw_bufs && p->length != -1) {
+ cl = p->free_raw_bufs;
+
+ if (cl->buf->last - cl->buf->pos >= p->length) {
+
+ /* STUB */ cl->buf->num = p->num++;
+
+ if (p->input_filter(p, cl->buf) == NGX_ERROR) {
+ return NGX_ABORT;
+ }
+
+ p->free_raw_bufs = cl->next;
+ ngx_free_chain(p->pool, cl);
+ }
+ }
+
+ if (p->length == 0) {
+ p->upstream_done = 1;
+ p->read = 1;
+ }
+
if ((p->upstream_eof || p->upstream_error) && p->free_raw_bufs) {
/* STUB */ p->free_raw_bufs->buf->num = p->num++;
@@ -633,13 +657,13 @@ ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
rc = p->output_filter(p->output_ctx, out);
+ ngx_chain_update_chains(p->pool, &p->free, &p->busy, &out, p->tag);
+
if (rc == NGX_ERROR) {
p->downstream_error = 1;
return ngx_event_pipe_drain_chains(p);
}
- ngx_chain_update_chains(&p->free, &p->busy, &out, p->tag);
-
for (cl = p->free; cl; cl = cl->next) {
if (cl->buf->temp_file) {
@@ -848,6 +872,12 @@ ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
}
p->last_in = &cl->next;
+ if (p->length == -1) {
+ return NGX_OK;
+ }
+
+ p->length -= b->last - b->pos;
+
return NGX_OK;
}
diff --git a/src/event/ngx_event_pipe.h b/src/event/ngx_event_pipe.h
index 00b8acf66..26334673c 100644
--- a/src/event/ngx_event_pipe.h
+++ b/src/event/ngx_event_pipe.h
@@ -65,6 +65,7 @@ struct ngx_event_pipe_s {
ssize_t busy_size;
off_t read_length;
+ off_t length;
off_t max_temp_file_size;
ssize_t temp_file_write_size;
diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c
index 2931a9f4e..76a1a1f41 100644
--- a/src/event/ngx_event_timer.c
+++ b/src/event/ngx_event_timer.c
@@ -103,11 +103,11 @@ ngx_event_expire_timers(void)
if (ngx_threaded && ngx_trylock(ev->lock) == 0) {
/*
- * We can not change the timer of the event that is been
- * handling by another thread. And we can not easy walk
- * the rbtree to find a next expired timer so we exit the loop.
- * However it should be rare case when the event that is
- * been handling has expired timer.
+ * We cannot change the timer of the event that is being
+ * handled by another thread. And we cannot easy walk
+ * the rbtree to find next expired timer so we exit the loop.
+ * However, it should be a rare case when the event that is
+ * being handled has an expired timer.
*/
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,