]> git.kaiwu.me - nginx.git/commitdiff
r1658 merge:
authorIgor Sysoev <igor@sysoev.ru>
Tue, 8 Jan 2008 17:13:54 +0000 (17:13 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 8 Jan 2008 17:13:54 +0000 (17:13 +0000)
improve throughput with large limit_rate

src/http/ngx_http_write_filter_module.c

index e5a26f00304cce520d38f8def335fd5161504ea6..bc62b18170152e5dc0082d4887560e7c2be00c3a 100644 (file)
@@ -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);