multiple limit_conn per connection

bryndole nginx-forum at nginx.us
Tue Oct 26 07:06:56 MSD 2010


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

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,144501,144501#msg-144501




More information about the nginx mailing list