Re: Re[6]: Посоветуйте оптимальные настройки

Igor Sysoev is at rambler-co.ru
Thu Apr 13 10:46:31 MSD 2006


On Thu, 13 Apr 2006, ForJest wrote:

> Ага, спасибо. Т.е. подсчёт для средней скорости, как я указал выше
> будет работать корректно при Keep-Alive, получается? Или нужно ещё
> скорректировать r->start_time?

Нет, не нужно.

Что касается патча, то, на первый взгляд, должно работать, хотя я ещё
эксперементально не проверял. Прилагаемый патч - модифицированный
вариант предложеннго: вызывать ngx_add_timer(0) не нужно.


Игорь Сысоев
http://sysoev.ru
-------------- next part --------------
--- src/http/ngx_http_write_filter_module.c	Wed Jan 11 15:37:47 2006
+++ src/http/ngx_http_write_filter_module.c	Thu Apr 13 10:38:16 2006
@@ -47,7 +47,7 @@
 ngx_int_t
 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
 {
-    off_t                      size, sent;
+    off_t                      size, to_send;
     ngx_uint_t                 last, flush;
     ngx_chain_t               *cl, *ln, **ll, *chain;
     ngx_connection_t          *c;
@@ -209,18 +209,19 @@
         return NGX_ERROR;
     }
 
-    sent = c->sent;
-
     chain = c->send_chain(c, r->out, r->limit_rate);
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http write filter %p", chain);
 
     if (r->limit_rate) {
-        sent = c->sent - sent;
-        c->write->delayed = 1;
-        ngx_add_timer(r->connection->write,
-                      (ngx_msec_t) (sent * 1000 / r->limit_rate));
+        to_send = r->limit_rate * (ngx_time() - r->start_time);
+
+        if (c->sent > to_send) {
+            c->write->delayed = 1;
+            ngx_add_timer(r->connection->write,
+                    (ngx_msec_t) ((c->sent - to_send) * 1000 / r->limit_rate));
+        }
     }
 
     if (chain == NGX_CHAIN_ERROR) {


More information about the nginx-ru mailing list