# Dynamic rate limiting per ip

**URL:** <https://www.ruby-forum.com/t/dynamic-rate-limiting-per-ip/238311>\
**Category:** NGINX\
**Created:** [January 2, 2014, 9:55pm UTC](https://www.ruby-forum.com/t/dynamic-rate-limiting-per-ip/238311 "2014-01-02T21:55:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [January 2, 2014, 9:55pm UTC](https://www.ruby-forum.com/t/dynamic-rate-limiting-per-ip/238311/1 "2014-01-02T21:55:19Z")

</div>

Hello Folks,

i have some setup with multiple server and i offer downloads for the  
users,  
in the case my servers bandwidth is overloaded i want the people to be  
able  
to start the download but with limited rate so the don’t have to wait in  
some kind of queue till the get there downloadlink. As soon as some  
slots  
frees the person highest in the queue download rate should increase to  
the  
max.

Any Ideas if this is possible with the limit\_rate of the http core  
module  
and lua?

If it would be possible to make 2 zone dicts where the ips of the the  
slow  
and fast connections are in. And if someone ratelimit is dropped his ip  
gets  
removed from the slow dict and added to the fast dict.

> **[GitHub - openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP...](https://github.com/openresty/lua-nginx-module#ngxshareddict)**
>
> Embed the Power of Lua into NGINX HTTP servers. Contribute to openresty/lua-nginx-module development by creating an account on GitHub.

Posted at Nginx Forum:

> **[dynamic rate limiting per ip](https://forum.nginx.org/read.php?2,245957,245957#msg-245957)**
>
> Hello Folks, i have some setup with multiple server and i offer downloads for the users, in the case my servers bandwidth is overloaded i want the people to be able to start the download but with limited rate so the don't have to wait in some kind of...

---

<div class="post-metadata">

**Author:** ![theotow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/0ea827/32.png) [@theotow](https://www.ruby-forum.com/u/theotow)\
**Post date:** [January 6, 2014, 5:08pm UTC](https://www.ruby-forum.com/t/dynamic-rate-limiting-per-ip/238311/2 "2014-01-06T17:08:10Z")

</div>

nobody an idea?

Posted at Nginx Forum:

> **[Re: dynamic rate limiting per ip](https://forum.nginx.org/read.php?2,245957,246064#msg-246064)**
>
> Hello Folks, i have some setup with multiple server and i offer downloads for the users, in the case my servers bandwidth is overloaded i want the people to be able to start the download but with limited rate so the don't have to wait in some kind of...

---

<div class="post-metadata">

**Author:** ![theotow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/0ea827/32.png) [@theotow](https://www.ruby-forum.com/u/theotow)\
**Post date:** [January 6, 2014, 8:33pm UTC](https://www.ruby-forum.com/t/dynamic-rate-limiting-per-ip/238311/3 "2014-01-06T20:33:50Z")

</div>

Hello!

On Thu, Jan 2, 2014 at 12:54 PM, theotow wrote:

> Any Ideas if this is possible with the limit\_rate of the http core module  
> and lua?

You can use ngx\_lua alone to do this.

> If it would be possible to make 2 zone dicts where the ips of the the slow  
> and fast connections are in. And if someone ratelimit is dropped his ip gets  
> removed from the slow dict and added to the fast dict.
> 
> [GitHub - openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP servers](https://github.com/chaoslawful/lua-nginx-module#ngxshareddict)

Yes, you can surely do that. You can use ngx.sleep() to hold back the  
exceeding clients without blocking other requests served by the same  
nginx worker.

Regards,  
-agentzh
