From 73678216eaae919068c163305d343cfd118c1128 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 27 Nov 2007 12:24:44 +0000 Subject: [PATCH] improve throughput with large limit_rate --- src/http/ngx_http_write_filter_module.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c index e5a26f003..bc62b1817 100644 --- a/src/http/ngx_http_write_filter_module.c +++ b/src/http/ngx_http_write_filter_module.c @@ -49,6 +49,7 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) { off_t size, sent, limit; ngx_uint_t last, flush; + ngx_msec_t delay; ngx_chain_t *cl, *ln, **ll, *chain; ngx_connection_t *c; ngx_http_core_loc_conf_t *clcf; @@ -245,14 +246,17 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) } if (r->limit_rate) { - sent = c->sent - sent; - c->write->delayed = 1; - ngx_add_timer(c->write, (ngx_msec_t) (sent * 1000 / r->limit_rate + 1)); + delay = (ngx_msec_t) ((c->sent - sent) * 1000 / r->limit_rate + 1); + + if (delay > 0) { + c->write->delayed = 1; + ngx_add_timer(c->write, delay); + } } else if (c->write->ready && clcf->sendfile_max_chunk && (size_t) (c->sent - sent) - >= clcf->sendfile_max_chunk - 2 * ngx_pagesize) + >= clcf->sendfile_max_chunk - 2 * ngx_pagesize) { c->write->delayed = 1; ngx_add_timer(c->write, 1);