Welcome! Log In Create A New Profile

Advanced

multiple limit_conn per connection

October 25, 2010 11:06PM
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;
}

--------

Does this work? am I nuts for trying this?

Bryn
Subject Author Posted

multiple limit_conn per connection

bryndole October 25, 2010 11:06PM

Re: multiple limit_conn per connection

bryndole October 27, 2010 09:49PM

Re: multiple limit_conn per connection

Weibin Yao October 27, 2010 10:52PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 116
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready