Nginx-limit-traffic-rate-module icon indicating copy to clipboard operation
Nginx-limit-traffic-rate-module copied to clipboard

limit_traffic_rate_zone rate $remote_addr not limiting by IP

Open ryanrbftp opened this issue 12 years ago • 6 comments

I have just installed a fresh copy of Nginx for our HTTP download file server. This module is amazing (when working properly) and just what we are looking for.

However, while we have managed to configure it to limit per connection - if a user from the same IP opens up another connection then the download speed is not shared - they get a full speed connection again.

For example, we have set the speed limit to 20kb/s... if a user connects with one connection goes to download a file with one thread, that's fine and speed is limited. But if they open multiple connections (for example a download software), they can achieve many 20kb/s connections - for example 5 connections brings 100kb/s.

How can I limit the connection speed across all connections from the same IP?

Current config:

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

ryanrbftp avatar May 13 '13 21:05 ryanrbftp

I have just tested this module with nginx-1.4.1, and it worked well.

So could you post the accesslog and debug log here to see what happened?

bigplum avatar May 14 '13 02:05 bigplum

We too are using a fresh copy of 1.4.1.

We have disabled accesslog and debug log. Is there any other way of diagnosing this?

ryanrbftp avatar May 14 '13 10:05 ryanrbftp

Okay, I have enabled debugging for connections from my IP only.

See from the screenshot 10x connections brings 200kb/s instead of the 20kb/s as stated in the config. Each connection has 20kb/s. screen shot 2013-05-14 at 12 05 28

See error.log (http://pastebin.com/YKVqH6Hm) with debug for my IP. I opened 10 connections to a single file in this example.

ryanrbftp avatar May 14 '13 11:05 ryanrbftp

I've pushed a path to fix this issue. And now I think it will work correctly.

This issue had been found before, but I forgot to sync the code to github. So sorry for that.

bigplum avatar May 15 '13 03:05 bigplum

Thank you very much! This seems to have fixed it.

However, a little bug...

When downloading two files at the same time - the first download gets priority of speed while the second download gets less priority. See screenshot.

screen shot 2013-05-15 at 11 53 02

Why is the speed not shared equally - i.e. 10kb/s each? Is the speed set once at initial connection or is updated live throughout the streaming process? Also, if the first download is canceled and only one connection is open (the second one) - the transfer speed does not increase up to 20kb/s.

Update: maybe it does increase but very, very slowly. Is there any way to update the refresh speed?

ryanrbftp avatar May 15 '13 10:05 ryanrbftp

This module use nginx core variable "limit_rate" to limit rate. Because of the limitation of "limit_rate", we can not distribute equally and smoothly. There were some discussion about this topic. Please refer to the post:

http://forum.nginx.org/read.php?2,159398,159515#msg-159515

bigplum avatar May 16 '13 01:05 bigplum