]> git.kaiwu.me - nginx.git/commitdiff
make limit_req to conform to the leaky bucket algorithm
authorIgor Sysoev <igor@sysoev.ru>
Tue, 6 Oct 2009 09:37:18 +0000 (09:37 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 6 Oct 2009 09:37:18 +0000 (09:37 +0000)
src/http/modules/ngx_http_limit_req_module.c

index 84e70b4f4563dd4f832e8a446667500791eb3567..b203d96e39292d6bdf9a5084243940c0acce65a9 100644 (file)
@@ -379,6 +379,11 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_conf_t *lrcf, ngx_uint_t hash,
 
                 excess = lr->excess - ctx->rate * ngx_abs(ms) / 1000 + 1000;
 
+                if ((ngx_uint_t) excess > lrcf->burst) {
+                    *lrp = lr;
+                    return NGX_BUSY;
+                }
+
                 if (excess < 0) {
                     excess = 0;
                 }
@@ -388,10 +393,6 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_conf_t *lrcf, ngx_uint_t hash,
 
                 *lrp = lr;
 
-                if ((ngx_uint_t) excess > lrcf->burst) {
-                    return NGX_BUSY;
-                }
-
                 if (excess) {
                     return NGX_AGAIN;
                 }