diff options
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/modules/ngx_http_gzip_filter.c | 5 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 32 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.h | 3 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.c | 21 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.h | 1 | ||||
| -rw-r--r-- | src/http/ngx_http_filter.h | 8 | ||||
| -rw-r--r-- | src/http/ngx_http_output_filter.c | 21 | ||||
| -rw-r--r-- | src/http/ngx_http_request.h | 3 | ||||
| -rw-r--r-- | src/http/ngx_http_write_filter.c | 24 |
9 files changed, 73 insertions, 45 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index df360b80b..5b8cebb4b 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -287,6 +287,8 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_create_temp_hunk(r->pool, conf->bufs.size, 0, 0), ngx_http_gzip_error(ctx)); + ctx->out_hunk->tag = (ngx_hunk_tag_t) + &ngx_http_gzip_filter_module; ctx->out_hunk->type |= NGX_HUNK_RECYCLED; ctx->hunks++; @@ -417,7 +419,8 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _ return ngx_http_gzip_error(ctx); } - ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out); + ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out, + (ngx_hunk_tag_t) &ngx_http_gzip_filter_module); ctx->last_out = &ctx->out; } } diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index eefa1f886..e3157d8e6 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -410,6 +410,7 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev) ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); return; } + p->header_in->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; } n = ngx_http_proxy_read_upstream_header(p); @@ -712,6 +713,7 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) ep->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter; ep->output_ctx = r; + ep->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; ep->bufs = p->lcf->bufs; ep->max_busy_len = p->lcf->max_busy_len; ep->upstream = p->upstream.connection; @@ -720,7 +722,7 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) ep->log = r->connection->log; ep->temp_path = p->lcf->temp_path; - ep->temp_file = ngx_palloc(r->pool, sizeof(ngx_file_t)); + ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); if (ep->temp_file == NULL) { ngx_http_proxy_finalize_request(p, 0); return; @@ -750,10 +752,23 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) */ p->header_in->last = p->header_in->pos; - /* STUB */ ep->cachable = 1; -#if 0 - ep->max_temp_file_size = 1000000000; -#endif + /* STUB */ ep->cachable = 0; + + if (p->lcf->cyclic_temp_file) { + + /* + * we need to disable the use of sendfile() if we use cyclic temp file + * because the writing a new data can interfere with sendfile + * that uses the same kernel file pages + */ + + ep->cyclic_temp_file = 1; + r->sendfile = 0; + + } else { + ep->cyclic_temp_file = 0; + r->sendfile = 1; + } p->event_pipe = ep; @@ -1162,16 +1177,17 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) conf->header_size = 4096; conf->read_timeout = 30000; - conf->bufs.num = 10; + conf->bufs.num = 5; conf->bufs.size = 4096; conf->max_busy_len = 8192; /* CHECK in _init conf->max_temp_size >= conf->bufs.size !!! */ - conf->max_temp_file_size = 4096 * 6; + conf->max_temp_file_size = 4096 * 3; - conf->temp_file_write_size = 4096 * 1; + conf->temp_file_write_size = 4096 * 2; + conf->cyclic_temp_file= 1; ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)), NULL); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index fe6ca23b7..597c309ff 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -26,10 +26,11 @@ typedef struct { ngx_bufs_t bufs; - /* STUB */ + /* STUB names */ int max_busy_len; int max_temp_file_size; int temp_file_write_size; + int cyclic_temp_file; /* */ ngx_path_t *temp_path; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 73d089574..601568377 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -130,6 +130,13 @@ static ngx_command_t ngx_http_core_commands[] = { offsetof(ngx_http_core_loc_conf_t, doc_root), NULL}, + {ngx_string("sendfile"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_core_loc_conf_t, sendfile), + NULL}, + {ngx_string("send_timeout"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, ngx_conf_set_msec_slot, @@ -334,7 +341,6 @@ int ngx_http_find_location_config(ngx_http_request_t *r) int i, rc; ngx_http_core_loc_conf_t *clcf, **clcfp; ngx_http_core_srv_conf_t *cscf; - ngx_http_write_filter_conf_t *wcf; cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); @@ -364,13 +370,14 @@ ngx_log_debug(r->connection->log, "rc: %d" _ rc); } } - wcf = ngx_http_get_module_loc_conf(r, ngx_http_write_filter_module); + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - if (!(ngx_io.flags & NGX_IO_SENDFILE) || !wcf->sendfile) { - r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; - } + if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) { + r->sendfile = 0; - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + } else { + r->sendfile = 1; + } if (clcf->handler) { /* @@ -828,6 +835,7 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) */ + lcf->sendfile = NGX_CONF_UNSET; lcf->send_timeout = NGX_CONF_UNSET; lcf->discarded_buffer_size = NGX_CONF_UNSET; lcf->keepalive_timeout = NGX_CONF_UNSET; @@ -896,6 +904,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_str_value(conf->default_type, prev->default_type, "text/plain"); + ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0); ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 10000); ngx_conf_merge_size_value(conf->discarded_buffer_size, prev->discarded_buffer_size, 1500); diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index f6048f036..9cc979145 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -110,6 +110,7 @@ typedef struct { ngx_array_t *types; ngx_str_t default_type; + int sendfile; /* sendfile */ ngx_msec_t send_timeout; /* send_timeout */ ssize_t send_lowat; /* send_lowat */ ssize_t discarded_buffer_size; /* discarded_buffer_size */ diff --git a/src/http/ngx_http_filter.h b/src/http/ngx_http_filter.h index 7792bb9e7..343afd04b 100644 --- a/src/http/ngx_http_filter.h +++ b/src/http/ngx_http_filter.h @@ -7,12 +7,6 @@ #define NGX_HTTP_FILTER_NEED_TEMP 4 -typedef struct { - ssize_t buffer_output; - int sendfile; -} ngx_http_write_filter_conf_t; - - int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in); int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in); @@ -20,7 +14,5 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in); extern int (*ngx_http_top_header_filter) (ngx_http_request_t *r); extern int (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch); -extern ngx_module_t ngx_http_write_filter_module; - #endif /* _NGX_HTTP_FILTER_H_INCLUDED_ */ diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c index ae95de843..061798e3d 100644 --- a/src/http/ngx_http_output_filter.c +++ b/src/http/ngx_http_output_filter.c @@ -32,7 +32,8 @@ typedef struct { } ngx_http_output_filter_ctx_t; -static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src); +static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src, + int sendfile); static void *ngx_http_output_filter_create_conf(ngx_conf_t *cf); static char *ngx_http_output_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child); @@ -77,7 +78,8 @@ ngx_module_t ngx_http_output_filter_module = { #define need_to_copy(r, hunk) \ (!ngx_hunk_special(hunk) \ - && (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \ + && (!r->sendfile \ + || ((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \ && (hunk->type & NGX_HUNK_IN_MEMORY) == 0) \ || ((r->filter & NGX_HTTP_FILTER_NEED_TEMP) \ && (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))))) @@ -162,6 +164,8 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_create_temp_hunk(r->pool, conf->bufs.size, 0, 0), NGX_ERROR); + ctx->hunk->tag = (ngx_hunk_tag_t) + &ngx_http_output_filter_module; ctx->hunk->type |= NGX_HUNK_RECYCLED; ctx->hunks++; @@ -170,7 +174,8 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) } } - rc = ngx_http_output_filter_copy_hunk(ctx->hunk, ctx->in->hunk); + rc = ngx_http_output_filter_copy_hunk(ctx->hunk, ctx->in->hunk, + r->sendfile); if (rc == NGX_ERROR) { return rc; @@ -215,13 +220,15 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) last = ngx_next_filter(r, ctx->out); - ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out); + ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out, + (ngx_hunk_tag_t) &ngx_http_output_filter_module); ctx->last_out = &ctx->out; } } -static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src) +static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src, + int sendfile) { ssize_t n, size; @@ -279,6 +286,10 @@ ngx_log_debug(src->file->log, "READ: %qd:%qd %X:%X %X:%X" _ src->file_pos += n; dst->last += n; + if (!sendfile) { + dst->type &= ~NGX_HUNK_FILE; + } + if ((src->type & NGX_HUNK_LAST) && src->file_pos == src->file_last) { dst->type |= NGX_HUNK_LAST; } diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 887afd937..913a0367e 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -190,6 +190,9 @@ struct ngx_http_request_s { #endif unsigned pipeline:1; + /* can we use sendfile ? */ + unsigned sendfile:1; + unsigned chunked:1; unsigned header_only:1; unsigned keepalive:1; diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 4032c7f52..109a9f43b 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -6,6 +6,11 @@ typedef struct { + ssize_t buffer_output; +} ngx_http_write_filter_conf_t; + + +typedef struct { ngx_chain_t *out; } ngx_http_write_filter_ctx_t; @@ -18,13 +23,6 @@ static int ngx_http_write_filter_init(ngx_cycle_t *cycle); static ngx_command_t ngx_http_write_filter_commands[] = { - {ngx_string("sendfile"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, - ngx_conf_set_flag_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_write_filter_conf_t, sendfile), - NULL}, - {ngx_string("buffer_output"), NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, ngx_conf_set_size_slot, @@ -94,9 +92,6 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) } } - conf = ngx_http_get_module_loc_conf(r->main ? r->main : r, - ngx_http_write_filter_module); - /* add the new chain to the existent one */ for (/* void */; in; in = in->next) { @@ -107,10 +102,6 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) *le = ce; le = &ce->next; - if (!(ngx_io.flags & NGX_IO_SENDFILE) || !conf->sendfile) { - ce->hunk->type &= ~NGX_HUNK_FILE; - } - size += ngx_hunk_size(ce->hunk); if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { @@ -128,6 +119,9 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) last _ flush _ size); #endif + conf = ngx_http_get_module_loc_conf(r->main ? r->main : r, + ngx_http_write_filter_module); + /* * avoid the output if there is no last hunk, no flush point and * size of the hunks is smaller then "buffer_output" @@ -174,7 +168,6 @@ static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf) NULL); conf->buffer_output = NGX_CONF_UNSET; - conf->sendfile = NGX_CONF_UNSET; return conf; } @@ -187,7 +180,6 @@ static char *ngx_http_write_filter_merge_conf(ngx_conf_t *cf, ngx_http_write_filter_conf_t *conf = child; ngx_conf_merge_size_value(conf->buffer_output, prev->buffer_output, 1460); - ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0); return NULL; } |
