summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2012-02-05 16:12:55 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2012-02-05 16:12:55 +0000
commit21f546d0d6b2938d6a8305079ed26c8e49d4f5e2 (patch)
tree378da824a66d4b780c1211827d709a1214169609
parentff8c2aedfee6514ba50391dcf5fef5bd02016684 (diff)
downloadnginx-21f546d0d6b2938d6a8305079ed26c8e49d4f5e2.tar.gz
Merge of r4384, r4385:
Fixes for limit_rate: *) Fixed throughput problems with large limit_rate. Previous attempt to fix this was in r1658 (0.6.18), though that one wasn't enough (it was a noop). *) Fixed interaction of limit_rate and sendfile_max_chunk. It's possible that configured limit_rate will permit more bytes per single operation than sendfile_max_chunk. To protect disk from takeover by a single client it is necessary to apply sendfile_max_chunk as a limit regardless of configured limit_rate. See here for report (in Russian): http://mailman.nginx.org/pipermail/nginx-ru/2010-March/032806.html
-rw-r--r--src/http/ngx_http_write_filter_module.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c
index 46351349c..a9660ee1f 100644
--- a/src/http/ngx_http_write_filter_module.c
+++ b/src/http/ngx_http_write_filter_module.c
@@ -223,11 +223,14 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
return NGX_AGAIN;
}
- } else if (clcf->sendfile_max_chunk) {
- limit = clcf->sendfile_max_chunk;
+ if (clcf->sendfile_max_chunk
+ && (off_t) clcf->sendfile_max_chunk < limit)
+ {
+ limit = clcf->sendfile_max_chunk;
+ }
} else {
- limit = 0;
+ limit = clcf->sendfile_max_chunk;
}
sent = c->sent;
@@ -262,17 +265,18 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
}
- delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate + 1);
+ delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate);
if (delay > 0) {
+ limit = 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)
+ if (limit
+ && c->write->ready
+ && c->sent - sent >= limit - (off_t) (2 * ngx_pagesize))
{
c->write->delayed = 1;
ngx_add_timer(c->write, 1);