comparison src/http/ngx_http_write_filter_module.c @ 1847:fc0c2b4293e2 stable-0.5

r1658 merge: improve throughput with large limit_rate
author Igor Sysoev <igor@sysoev.ru>
date Tue, 08 Jan 2008 17:13:54 +0000
parents 0bd321c8ce67
children
comparison
equal deleted inserted replaced
1846:6bbb9057ef16 1847:fc0c2b4293e2
47 ngx_int_t 47 ngx_int_t
48 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) 48 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
49 { 49 {
50 off_t size, sent, limit; 50 off_t size, sent, limit;
51 ngx_uint_t last, flush; 51 ngx_uint_t last, flush;
52 ngx_msec_t delay;
52 ngx_chain_t *cl, *ln, **ll, *chain; 53 ngx_chain_t *cl, *ln, **ll, *chain;
53 ngx_connection_t *c; 54 ngx_connection_t *c;
54 ngx_http_core_loc_conf_t *clcf; 55 ngx_http_core_loc_conf_t *clcf;
55 56
56 c = r->connection; 57 c = r->connection;
243 c->error = 1; 244 c->error = 1;
244 return NGX_ERROR; 245 return NGX_ERROR;
245 } 246 }
246 247
247 if (r->limit_rate) { 248 if (r->limit_rate) {
248 sent = c->sent - sent; 249 delay = (ngx_msec_t) ((c->sent - sent) * 1000 / r->limit_rate + 1);
249 c->write->delayed = 1; 250
250 ngx_add_timer(c->write, (ngx_msec_t) (sent * 1000 / r->limit_rate + 1)); 251 if (delay > 0) {
252 c->write->delayed = 1;
253 ngx_add_timer(c->write, delay);
254 }
251 255
252 } else if (c->write->ready 256 } else if (c->write->ready
253 && clcf->sendfile_max_chunk 257 && clcf->sendfile_max_chunk
254 && (size_t) (c->sent - sent) 258 && (size_t) (c->sent - sent)
255 >= clcf->sendfile_max_chunk - 2 * ngx_pagesize) 259 >= clcf->sendfile_max_chunk - 2 * ngx_pagesize)
256 { 260 {
257 c->write->delayed = 1; 261 c->write->delayed = 1;
258 ngx_add_timer(c->write, 1); 262 ngx_add_timer(c->write, 1);
259 } 263 }
260 264