improve throughput with large limit_rate
diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c
index e5a26f0..bc62b18 100644
--- a/src/http/ngx_http_write_filter_module.c
+++ b/src/http/ngx_http_write_filter_module.c
@@ -49,6 +49,7 @@
{
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 @@
}
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);