Multiple limit_conn per connection

I’m trying to limit the number of simultaneous connections based on a
CGI args. For example some queries are more expensive to process than
others, and I’m trying to avoid a few slow/expensive queries to starve
out all the other faster queries.

I would like to set an overall (server wide) connection limit of 100
connections overall, with 50 connection limit for &opt1 is set, a 30
connection limit if &opt2 is set, and a 10 connection limit of &opt3 is
set.

Ideally I could use “if” but of course “if is evil” so something I’m
trying something like this:

invariant variable so that all connections are in the same traffic

bucket
limit_zone all $nginx_version 64k;
limit_zone opt1 $nginx_version 64k;
limit_zone opt2 $nginx_version 64k;
limit_zone opt3 $nginx_version 64k;

location / {
limit_conn all 100;

if ( $arg_opt1 ) {
rewrite ^ /opt1/$request_uri last;
}
proxy_pass http://backends;
}

location /opt1/ {
limit_conn opt1 50;
if ( $arg_opt2 ) {
rewrite ^ /opt2/$request_uri last;
}
proxy_pass http://backends;
}

location /opt2/ {
limit_conn opt2 30;
if ( $arg_opt3 ) {
rewrite ^ /opt3/$request_uri last;
}
proxy_pass http://backends;
}

location /opt3/ {
limit_conn opt3 10;
proxy_pass http://backends;
}

I did some more research, ran a few experiments, and even looked at the
code.

What I described above is not possible. The limit_conn method fires
exactly once for a connection, even if it goes to a “@retry” location.
If you have several internal redirects ( rewrite /foo /bar last; ) only
the last limit_conn is fired.

Posted at Nginx Forum:

bryndole at 2010-10-28 9:49 wrote:

I did some more research, ran a few experiments, and even looked at the
code.

What I described above is not possible. The limit_conn method fires
exactly once for a connection, even if it goes to a “@retry” location.
If you have several internal redirects ( rewrite /foo /bar last; ) only
the last limit_conn is fired.

Maybe you can also use the limit_request. This module is similar with
the limit_conn module. Both the two module are limited to be used only
once in one request.

Posted at Nginx Forum:
Re: multiple limit_conn per connection


nginx mailing list
[email protected]
nginx Info Page


Weibin Y.