Mercurial > hg > nginx
comparison src/http/ngx_http_write_filter_module.c @ 4442:41b2d17534c1 stable-1.0
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
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 05 Feb 2012 16:12:55 +0000 |
parents | 4f5753877376 |
children | 4919fb357a5d |
comparison
equal
deleted
inserted
replaced
4441:e30845779761 | 4442:41b2d17534c1 |
---|---|
221 c->buffered |= NGX_HTTP_WRITE_BUFFERED; | 221 c->buffered |= NGX_HTTP_WRITE_BUFFERED; |
222 | 222 |
223 return NGX_AGAIN; | 223 return NGX_AGAIN; |
224 } | 224 } |
225 | 225 |
226 } else if (clcf->sendfile_max_chunk) { | 226 if (clcf->sendfile_max_chunk |
227 && (off_t) clcf->sendfile_max_chunk < limit) | |
228 { | |
229 limit = clcf->sendfile_max_chunk; | |
230 } | |
231 | |
232 } else { | |
227 limit = clcf->sendfile_max_chunk; | 233 limit = clcf->sendfile_max_chunk; |
228 | |
229 } else { | |
230 limit = 0; | |
231 } | 234 } |
232 | 235 |
233 sent = c->sent; | 236 sent = c->sent; |
234 | 237 |
235 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | 238 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
260 if (nsent < 0) { | 263 if (nsent < 0) { |
261 nsent = 0; | 264 nsent = 0; |
262 } | 265 } |
263 } | 266 } |
264 | 267 |
265 delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate + 1); | 268 delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate); |
266 | 269 |
267 if (delay > 0) { | 270 if (delay > 0) { |
271 limit = 0; | |
268 c->write->delayed = 1; | 272 c->write->delayed = 1; |
269 ngx_add_timer(c->write, delay); | 273 ngx_add_timer(c->write, delay); |
270 } | 274 } |
271 | 275 } |
272 } else if (c->write->ready | 276 |
273 && clcf->sendfile_max_chunk | 277 if (limit |
274 && (size_t) (c->sent - sent) | 278 && c->write->ready |
275 >= clcf->sendfile_max_chunk - 2 * ngx_pagesize) | 279 && c->sent - sent >= limit - (off_t) (2 * ngx_pagesize)) |
276 { | 280 { |
277 c->write->delayed = 1; | 281 c->write->delayed = 1; |
278 ngx_add_timer(c->write, 1); | 282 ngx_add_timer(c->write, 1); |
279 } | 283 } |
280 | 284 |