# HG changeset patch # User Valentin Bartenev # Date 1327917699 0 # Node ID 7084faa7a4b4c45335bf06b8765a38549dc43b0e # Parent aac79fc948cc28a464218bf207d7f4a4e058f42b Limit req: number of cleanup calls reduced. Doing a cleanup before every lookup seems to be too aggressive. It can lead to premature removal of the nodes still usable, which increases the amount of work under a mutex lock and therefore decreases performance. In order to improve cleanup behavior, cleanup function call has been moved right before the allocation of a new node. diff --git a/src/http/modules/ngx_http_limit_req_module.c b/src/http/modules/ngx_http_limit_req_module.c --- a/src/http/modules/ngx_http_limit_req_module.c +++ b/src/http/modules/ngx_http_limit_req_module.c @@ -182,8 +182,6 @@ ngx_http_limit_req_handler(ngx_http_requ ngx_shmtx_lock(&ctx->shpool->mutex); - ngx_http_limit_req_expire(ctx, 1); - rc = ngx_http_limit_req_lookup(lrcf, hash, vv->data, len, &excess); ngx_shmtx_unlock(&ctx->shpool->mutex); @@ -385,6 +383,8 @@ ngx_http_limit_req_lookup(ngx_http_limit + offsetof(ngx_http_limit_req_node_t, data) + len; + ngx_http_limit_req_expire(ctx, 1); + node = ngx_slab_alloc_locked(ctx->shpool, size); if (node == NULL) {