[MODULE] limit traffic rate for nginx

bigplum nginx-forum at nginx.us
Fri Dec 17 17:17:07 MSK 2010


Hello guys:

I wrote a module to limit rate by given variable rather than limit_rate
by connection. Most code of this module is copied from limit_conn
module. I'm confusing to write this new module or modify limit_conn
module. The modification will be easily but a new module would be
installed easily. So, how about this new module?

https://github.com/bigplum/Nginx-limit-traffic-rate-module

README:

Nginx directive limit_rate could limit connection's speed, and
limit_conn could
limit connection number by given variable. If the client is a browser,
it only
open one connection to the server. The speed will be limited to
limit_rate, unless
the client is a multi-thread download tool.

The limit_traffic_rate module record connection numbers by the variable
like 
limit_conn module, and set limit_rate to
limit_traffic_rate/cur_conn_number. So
if client is a browser, the download max rate will be
limit_traffic_rate, if client
is a multi-thread tool, the total rate also be limited to
limit_traffic_rate.

The limit_traffic_rate module need to use a share memory pool. Directive
syntax
is same to limit_zone. 

    http {
        limit_traffic_rate_zone   rate $remote_addr 32m;
        
        server {
            location /download/ {
                limit_traffic_rate  rate 20k;
            }
        }
    }

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




More information about the nginx mailing list