You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apisix.apache.org by Law Sheldon <sh...@outlook.com> on 2020/01/06 03:32:39 UTC

[DISCUSS] Add distributed token bucket limit plugin based on Redis

Hello, everyone



I want to add a distributed token bucket limit plugin based on Redis. Although most of the existing current limit plugins have already been used in most scenarios, there are still some specific scenarios that need to implement distributed speed limiting.

Token bucket-based speed limit can effectively correct traffic spikes caused by fixed-time window current limit and make limiting smoothly.

And we hope that the limit algorithm can limit the flow based on your own custom keywords. These keywords can be the header used to mark the source app, or it can be a query parameter.



How to do it? We package the token bucket algorithm into a Lua script, use the Redis “script load” command to load the token bucket algorithm into the Redis Server, and then perform the current limit through “evalsha” command.





[cid:image001.png@01D5C47D.B3ADB700]



Can anyone give some advice? Is this needed for APISIX?


Re: [DISCUSS] Add distributed token bucket limit plugin based on Redis

Posted by Ming Wen <we...@apache.org>.
`multiple Apache APISIX instances` is not a problem here, the architecture
diagram mainly describes the Redis side.

you can refer to the implement of the limit-count plugin[1], which is also
supported Redis.

I have one question:
Is there a performance impact if you run Lua script in Redis?
Can we run related Lua code in the Apache APISIX side, and only using Redis as
a public token bucket?
We optimized for LuaJIT in Apache APISIX. But it will not effective in
Redis.

[1]
https://github.com/apache/incubator-apisix/blob/master/lua/apisix/plugins/limit-count.lua

Thanks,
Ming Wen, Apache APISIX
Twitter: _WenMing


YuanSheng Wang <me...@apache.org> 于2020年1月6日周一 下午12:11写道:

> Hi:
>
> Found a problem, only `shdict` is not enough, because APISIX Gateway allows
> multiple instances.
>
>
> On Mon, Jan 6, 2020 at 11:55 AM Law Sheldon <sh...@outlook.com>
> wrote:
>
> > The picture url: http://p0.qhimg.com/t019b29b44ac6e1b307.png
> >
> > 发件人: Law Sheldon <sh...@outlook.com>
> > 答复: "dev@apisix.apache.org" <de...@apisix.apache.org>
> > 日期: 2020年1月6日 星期一 上午11:32
> > 收件人: "dev@apisix.apache.org" <de...@apisix.apache.org>
> > 主题: [DISCUSS] Add distributed token bucket limit plugin based on Redis
> >
> >
> > Hello, everyone
> >
> >
> >
> > I want to add a distributed token bucket limit plugin based on Redis.
> > Although most of the existing current limit plugins have already been
> used
> > in most scenarios, there are still some specific scenarios that need to
> > implement distributed speed limiting.
> >
> > Token bucket-based speed limit can effectively correct traffic spikes
> > caused by fixed-time window current limit and make limiting smoothly.
> >
> > And we hope that the limit algorithm can limit the flow based on your own
> > custom keywords. These keywords can be the header used to mark the source
> > app, or it can be a query parameter.
> >
> >
> >
> > How to do it? We package the token bucket algorithm into a Lua script,
> use
> > the Redis “script load” command to load the token bucket algorithm into
> the
> > Redis Server, and then perform the current limit through “evalsha”
> command.
> >
> >
> >
> >
> >
> > [cid:image001.png@01D5C47D.B3ADB700]
> >
> >
> >
> > Can anyone give some advice? Is this needed for APISIX?
> >
> >
>
> --
> *MembPhis*
> My github: https://github.com/membphis
> Apache APISIX: https://github.com/apache/incubator-apisix
>

Re: [DISCUSS] Add distributed token bucket limit plugin based on Redis

Posted by YuanSheng Wang <me...@apache.org>.
Hi:

Found a problem, only `shdict` is not enough, because APISIX Gateway allows
multiple instances.


On Mon, Jan 6, 2020 at 11:55 AM Law Sheldon <sh...@outlook.com> wrote:

> The picture url: http://p0.qhimg.com/t019b29b44ac6e1b307.png
>
> 发件人: Law Sheldon <sh...@outlook.com>
> 答复: "dev@apisix.apache.org" <de...@apisix.apache.org>
> 日期: 2020年1月6日 星期一 上午11:32
> 收件人: "dev@apisix.apache.org" <de...@apisix.apache.org>
> 主题: [DISCUSS] Add distributed token bucket limit plugin based on Redis
>
>
> Hello, everyone
>
>
>
> I want to add a distributed token bucket limit plugin based on Redis.
> Although most of the existing current limit plugins have already been used
> in most scenarios, there are still some specific scenarios that need to
> implement distributed speed limiting.
>
> Token bucket-based speed limit can effectively correct traffic spikes
> caused by fixed-time window current limit and make limiting smoothly.
>
> And we hope that the limit algorithm can limit the flow based on your own
> custom keywords. These keywords can be the header used to mark the source
> app, or it can be a query parameter.
>
>
>
> How to do it? We package the token bucket algorithm into a Lua script, use
> the Redis “script load” command to load the token bucket algorithm into the
> Redis Server, and then perform the current limit through “evalsha” command.
>
>
>
>
>
> [cid:image001.png@01D5C47D.B3ADB700]
>
>
>
> Can anyone give some advice? Is this needed for APISIX?
>
>

-- 
*MembPhis*
My github: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix

Re: [DISCUSS] Add distributed token bucket limit plugin based on Redis

Posted by Law Sheldon <sh...@outlook.com>.
The picture url: http://p0.qhimg.com/t019b29b44ac6e1b307.png

发件人: Law Sheldon <sh...@outlook.com>
答复: "dev@apisix.apache.org" <de...@apisix.apache.org>
日期: 2020年1月6日 星期一 上午11:32
收件人: "dev@apisix.apache.org" <de...@apisix.apache.org>
主题: [DISCUSS] Add distributed token bucket limit plugin based on Redis


Hello, everyone



I want to add a distributed token bucket limit plugin based on Redis. Although most of the existing current limit plugins have already been used in most scenarios, there are still some specific scenarios that need to implement distributed speed limiting.

Token bucket-based speed limit can effectively correct traffic spikes caused by fixed-time window current limit and make limiting smoothly.

And we hope that the limit algorithm can limit the flow based on your own custom keywords. These keywords can be the header used to mark the source app, or it can be a query parameter.



How to do it? We package the token bucket algorithm into a Lua script, use the Redis “script load” command to load the token bucket algorithm into the Redis Server, and then perform the current limit through “evalsha” command.





[cid:image001.png@01D5C47D.B3ADB700]



Can anyone give some advice? Is this needed for APISIX?