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
This commit is contained in:
parent
812f376092
commit
5254ac2214
1 changed files with 11 additions and 7 deletions
|
@ -223,11 +223,14 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||||
return NGX_AGAIN;
|
return NGX_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (clcf->sendfile_max_chunk) {
|
if (clcf->sendfile_max_chunk
|
||||||
|
&& (off_t) clcf->sendfile_max_chunk < limit)
|
||||||
|
{
|
||||||
limit = clcf->sendfile_max_chunk;
|
limit = clcf->sendfile_max_chunk;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
limit = 0;
|
limit = clcf->sendfile_max_chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
sent = c->sent;
|
sent = c->sent;
|
||||||
|
@ -265,14 +268,15 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||||
delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate);
|
delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate);
|
||||||
|
|
||||||
if (delay > 0) {
|
if (delay > 0) {
|
||||||
|
limit = 0;
|
||||||
c->write->delayed = 1;
|
c->write->delayed = 1;
|
||||||
ngx_add_timer(c->write, delay);
|
ngx_add_timer(c->write, delay);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (c->write->ready
|
if (limit
|
||||||
&& clcf->sendfile_max_chunk
|
&& c->write->ready
|
||||||
&& (size_t) (c->sent - sent)
|
&& c->sent - sent >= limit - (off_t) (2 * ngx_pagesize))
|
||||||
>= clcf->sendfile_max_chunk - 2 * ngx_pagesize)
|
|
||||||
{
|
{
|
||||||
c->write->delayed = 1;
|
c->write->delayed = 1;
|
||||||
ngx_add_timer(c->write, 1);
|
ngx_add_timer(c->write, 1);
|
||||||
|
|
Loading…
Reference in a new issue