Welcome! Log In Create A New Profile

Advanced

New nginx module: ngx_softlimit

Zeljko Tomic
June 30, 2010 12:30PM
Hi,

I wrote a small, but sometimes very useful module for limiting the number of active connections, in a "soft" way.

Description and usage:
-----------------------
In situation when using nginx for serving static files and primarily as a proxy/proxy_cache with some slower backend (or even php fastcgi), limits of connections and requests that nginx can handle are much higher than they are on backend server(s). When you know the limits of your backend, it is bad practice to apply those limits on nginx's worker_connections, because it's obvious that when limits are met, new requests won't come through and this leaves you with bad visitor experience.

Better way to approach this problem would be to have the means to manipulate content which gets returned to visitor in such scenario. When limits are met, a simple variable is set to TRUE, which can be manipulated through nginx.conf. Not to speak further, here's an example:


location / {
softlimit_enable on;
softlimit_max_conn 50;

if ( $softlimit_alert ) {
return 599;
}
error_page 598 = @maintenance;
....
}

location @maintenance {
rewrite ^(.*)$ /maintenance.html last;
break;
}


Download and install:
---------------------
# wget http://unixreich.com/code/ngx_softlimit-0.1.tar.gz
# tar xzf ngx_softlimit-0.1.tar.gz
# ./configure --add-module=/path/to/ngx_softlimit-0.1
# make
# make install


Future development:
-------------------
As the module relies on ngx counters, it can be easely expanded to support counters other than ngx_stat_active. If some day you decide to put ngx_stat_backends (number of connections to backends), it can be even more useful.
Also, this is my first contribution to the project. I don't know if there's a code review procedure or something like that.. to list this module as a 3rd party one. Let me know if you'd like to put it there.

Thanks,

--
Zeljko Tomic <scyth@unixreich.com>

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

New nginx module: ngx_softlimit

Zeljko Tomic 2580 June 30, 2010 12:30PM

Re: New nginx module: ngx_softlimit

Denis F. Latypoff 993 June 30, 2010 12:38PM

Re: New nginx module: ngx_softlimit

Zeljko Tomic 990 June 30, 2010 12:50PM

Re: New nginx module: ngx_softlimit

Maxim Dounin 995 June 30, 2010 12:56PM

Re: New nginx module: ngx_softlimit

scyth 930 June 30, 2010 01:34PM

Re: New nginx module: ngx_softlimit

Maxim Dounin 911 June 30, 2010 06:56PM

Re: New nginx module: ngx_softlimit

Zeljko Tomic 957 June 30, 2010 08:28PM

Re: New nginx module: ngx_softlimit

Maxim Dounin 1002 June 30, 2010 11:44PM

Re: New nginx module: ngx_softlimit

Zeljko Tomic 1326 July 01, 2010 11:52AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 298
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready