[MODULE] limit traffic rate for nginx

Maxim Dounin mdounin at mdounin.ru
Sat Dec 18 01:25:24 MSK 2010


On Fri, Dec 17, 2010 at 09:17:07AM -0500, bigplum wrote:

> 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

Some notes:

1. You return NGX_DECLINED from body filter.  It's just wrong.

2. You set r->limit_rate dynamically to do actual rate limiting.  
Note that this isn't going to work well as limit_rate limits 
average download rate for request and not expected to be changed 
during downloading.

E.g. with 1MB/s limit per $remote_address suppose client connects 
and starts downloading file1.  After downloading 1G (at 1MB/s 
rate, i.e. after 1024 seconds) it starts downloading file2 (while 
still downloading file1).  Now r->limit_rate is set to 0.5MB/s for 
both requests.  This is not a problem for file2 request, but file1 
request will suddenly find client was already downloaded twice as 
much as it should be allowed and will pause downloading for 1024 

Maxim Dounin

More information about the nginx mailing list