# HG changeset patch # User Igor Sysoev # Date 1080882880 0 # Node ID bcbe876f42622c124fade3ecb39ec1a1c70f08d3 # Parent 00c5660d27072486670a011a366e7398c8e2c9df nginx-0.0.3-2004-04-02-09:14:40 import diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -139,6 +139,7 @@ ngx_module_t ngx_event_core_module = { static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) { +#if !(WIN32) ngx_core_conf_t *ccf; ngx_event_conf_t *ecf; @@ -163,6 +164,7 @@ static ngx_int_t ngx_event_module_init(n "mmap(MAP_ANON|MAP_SHARED) failed"); return NGX_ERROR; } +#endif return NGX_OK; } diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -100,7 +100,6 @@ int ngx_event_pipe_read_upstream(ngx_eve /* use the pre-read hunks if they exist */ - p->read = 1; chain = p->preread_hunks; p->preread_hunks = NULL; n = p->preread_size; @@ -108,6 +107,10 @@ int ngx_event_pipe_read_upstream(ngx_eve ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe preread: %d", n); + if (n) { + p->read = 1; + } + } else { /* @@ -286,6 +289,35 @@ int ngx_event_pipe_read_upstream(ngx_eve p->free_raw_hunks = cl; } +#if (NGX_DEBUG0) + + if (p->in || p->busy || p->free_raw_hunks) { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf"); + } + + for (cl = p->in; cl; cl = cl->next) { + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe buf in " PTR_FMT ", pos " PTR_FMT ", size: %d", + cl->hunk->start, cl->hunk->pos, + cl->hunk->last - cl->hunk->pos); + } + + for (cl = p->busy; cl; cl = cl->next) { + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe buf busy " PTR_FMT ", pos " PTR_FMT ", size: %d", + cl->hunk->start, cl->hunk->pos, + cl->hunk->last - cl->hunk->pos); + } + + for (cl = p->free_raw_hunks; cl; cl = cl->next) { + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe buf free " PTR_FMT ", last " PTR_FMT ", size: %d", + cl->hunk->start, cl->hunk->last, + cl->hunk->end - cl->hunk->last); + } + +#endif + if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) { /* STUB */ p->free_raw_hunks->hunk->num = p->num++; @@ -315,7 +347,8 @@ int ngx_event_pipe_read_upstream(ngx_eve int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) { - size_t bsize, to_write; + size_t bsize; + ngx_uint_t flush; ngx_hunk_t *h; ngx_chain_t *out, **ll, *cl, *tl; @@ -368,44 +401,29 @@ int ngx_event_pipe_write_to_downstream(n break; } - /* - * bsize is the size of the busy hunks, - * to_write is the size of data in these hunks that - * would be written to a socket - */ + /* bsize is the size of the busy hunks */ bsize = 0; - to_write = 0; -#if 0 - if (!(p->upstream_eof || p->upstream_error || p->upstream_done)) { -#endif - for (cl = p->busy; cl; cl = cl->next) { - bsize += cl->hunk->end - cl->hunk->start; - to_write += ngx_hunk_size(cl->hunk); - } -#if 0 + for (cl = p->busy; cl; cl = cl->next) { + bsize += cl->hunk->end - cl->hunk->start; } -#endif + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe write busy: " SIZE_T_FMT, bsize); out = NULL; ll = NULL; + flush = 0; for ( ;; ) { if (p->out) { cl = p->out; -#if 0 - if (!(p->upstream_eof || p->upstream_error || p->upstream_done) - && (bsize + ngx_hunk_size(cl->hunk) > p->busy_size)) - { + if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { + flush = 1; break; } -#else - if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { - break; - } -#endif p->out = p->out->next; ngx_event_pipe_free_shadow_raw_hunk(&p->free_raw_hunks, @@ -414,17 +432,10 @@ int ngx_event_pipe_write_to_downstream(n } else if (!p->cachable && p->in) { cl = p->in; -#if 0 - if (!(p->upstream_eof || p->upstream_error || p->upstream_done) - && (bsize + ngx_hunk_size(cl->hunk) > p->busy_size)) - { + if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { + flush = 1; break; } -#else - if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) { - break; - } -#endif p->in = p->in->next; @@ -437,22 +448,13 @@ int ngx_event_pipe_write_to_downstream(n ngx_chain_add_link(out, ll, cl); } - if (out == NULL) { - - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe busy hunk data to write: %d", to_write); + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe write: out:" PTR_FMT ", f:%d", out, flush); - if (!(p->upstream_blocked && to_write)) { - break; - } - + if (out == NULL && !flush) { + break; } - /* - * if the upstream is blocked and there are the busy hunks - * to write then write these hunks - */ - if (p->output_filter(p->output_ctx, out) == NGX_ERROR) { p->downstream_error = 1; return ngx_event_pipe_drain_chains(p); @@ -533,8 +535,9 @@ static int ngx_event_pipe_write_chain_to do { hsize = cl->hunk->last - cl->hunk->pos; - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe hunk size: %d", hsize); + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe buf " PTR_FMT ", pos " PTR_FMT ", size: %d", + cl->hunk->start, cl->hunk->pos, hsize); if ((size + hsize > p->temp_file_write_size) || (p->temp_file->offset + size + hsize > p->max_temp_file_size)) diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -77,7 +77,14 @@ ngx_inline static void ngx_event_add_tim #endif if (ev->timer_set) { - if (key - ev->rbtree_key < 50) { + + /* + * Use the previous timer value if a difference between them is less + * then 100 milliseconds. It allows to minimize the rbtree operations + * for the fast connections. + */ + + if (key - ev->rbtree_key < 100 / NGX_TIMER_RESOLUTION) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, "event timer: %d, old: %d, new: %d", ngx_event_ident(ev->data), ev->rbtree_key, key); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -814,6 +814,8 @@ static char *ngx_http_proxy_merge_loc_co ngx_http_proxy_loc_conf_t *prev = parent; ngx_http_proxy_loc_conf_t *conf = child; + size_t size; + ngx_conf_merge_msec_value(conf->connect_timeout, prev->connect_timeout, 60000); ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 30000); @@ -823,22 +825,65 @@ static char *ngx_http_proxy_merge_loc_co ngx_conf_merge_value(conf->add_x_forwarded_for, prev->add_x_forwarded_for, 0); + ngx_conf_merge_msec_value(conf->read_timeout, prev->read_timeout, 30000); + ngx_conf_merge_size_value(conf->header_buffer_size, prev->header_buffer_size, 4096); - ngx_conf_merge_msec_value(conf->read_timeout, prev->read_timeout, 30000); ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 8, 4096); + + size = conf->header_buffer_size; + if (size < conf->bufs.size) { + size = conf->bufs.size; + } + + ngx_conf_merge_size_value(conf->busy_buffers_size, - prev->busy_buffers_size, 8192); + prev->busy_buffers_size, NGX_CONF_UNSET_SIZE); -#if 0 - if (conf->max_temp_file_size > conf->bufs.size) { - return "\"proxy_max_temp_file\" must be greater " - "than one of the \"proxy_buffers\""; + if (conf->busy_buffers_size == NGX_CONF_UNSET_SIZE) { + conf->busy_buffers_size = 2 * size; + + } else if (conf->busy_buffers_size < size) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"proxy_busy_buffers_size\" must be equal or bigger than " + "maximum of the value of \"proxy_header_buffer_size\" and " + "one of the \"proxy_buffers\""); + + return NGX_CONF_ERROR; } -#endif + ngx_conf_merge_size_value(conf->temp_file_write_size, - prev->temp_file_write_size, 16384); + prev->temp_file_write_size, NGX_CONF_UNSET_SIZE); + + if (conf->temp_file_write_size == NGX_CONF_UNSET_SIZE) { + conf->temp_file_write_size = 2 * size; + + } else if (conf->temp_file_write_size < size) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"proxy_temp_file_write_size\" must be equal or bigger than " + "maximum of the value of \"proxy_header_buffer_size\" and " + "one of the \"proxy_buffers\""); + + return NGX_CONF_ERROR; + } + + + ngx_conf_merge_size_value(conf->max_temp_file_size, + prev->max_temp_file_size, NGX_CONF_UNSET_SIZE); + + if (conf->max_temp_file_size == NGX_CONF_UNSET_SIZE) { + conf->max_temp_file_size = 2 * size; + + } else if (conf->max_temp_file_size < size) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"proxy_max_temp_file_size\" must be equal or bigger than " + "maximum of the value of \"proxy_header_buffer_size\" and " + "one of the \"proxy_buffers\""); + + return NGX_CONF_ERROR; + } + ngx_conf_merge_bitmask_value(conf->next_upstream, prev->next_upstream, (NGX_CONF_BITMASK_SET diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -1199,14 +1199,16 @@ static void ngx_http_proxy_send_response ep->preread_size = p->header_in->last - p->header_in->pos; - ep->hunk_to_file = ngx_calloc_hunk(r->pool); - if (ep->preread_hunks == NULL) { - ngx_http_proxy_finalize_request(p, 0); - return; + if (p->cachable) { + ep->hunk_to_file = ngx_calloc_hunk(r->pool); + if (ep->hunk_to_file == NULL) { + ngx_http_proxy_finalize_request(p, 0); + return; + } + ep->hunk_to_file->pos = p->header_in->start; + ep->hunk_to_file->last = p->header_in->pos; + ep->hunk_to_file->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; } - ep->hunk_to_file->pos = p->header_in->start; - ep->hunk_to_file->last = p->header_in->pos; - ep->hunk_to_file->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; if (ngx_event_flags & NGX_USE_AIO_EVENT) { /* the posted aio operation can currupt a shadow buffer */