对于 Hazelcast 来说,一张大地图和多张小地图哪个更好?

发布于 2024-10-08 17:14:24 字数 351 浏览 0 评论 0原文

我想创建一个可以限制速率的速率限制器系统 向多个服务器发出请求。 为此我想创建计数器(每个 ip 1 个计数器 地址) 这样所有服务器都可以检查并更新这些计数器。

我的问题:最好的方法是什么,创建一张地图并使用ip 客户端的地址作为密钥,该 ip 的计数器将是 在 java 对象中。该对象将是映射条目的值。

或者

为每个 IP 地址创建一个映射并使用计数器名称作为键并 计数器值作为条目(int)的值

我的关键优先事项是速度。检索计数器对象并 增加它必须非常快。

那么什么是最好的呢?许多小地图还是一张大地图?

我希望有人能帮助我解决这个问题。

问候,

马丁

I would like to create a rate-limter system which can rate-limit
requests to multiple servers.
For this i would like to create counters ( 1 counter for each ip
address)
this way all the servers can check and update these counters.

My question: what is the best approach , create one map and use the ip
address of the client as the key and the counters for that ip would be
in a java object.that object would be the value for the map entry.

or

create a map for each ip address and use the counter name as key and
counter value as the value for the entry (int)

my key priority is speed. retrieving the counter object and
incrementing it must be done very fast.

so what is best? many small maps or one large map?

I hope someone can help me with this.

regards,

Maarten

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-10-15 17:14:24

速率限制计数器可能是系统中最具争议的对象之一。我不知道 Hazelcast 地图是否会表现得足够好。

您可能会看一下 Hazelcast 1.9 中的 AtomicNumber 接口,但我不知道您是否可以创建任意多个这些对象(或者即使您可以在创建后处理它们)。

您最好的选择可能是使用 HAProxy 或类似的负载均衡器在应用程序服务器前面实施限制规则。

The rate-limiting counters are likely to be one of the most contentious objects in the system. I don't know if Hazelcast maps are going to perform well enough.

You might take a look at the AtomicNumber interface in Hazelcast 1.9, but I do not know if you can create arbitrarily many of these objects (or even if you can dispose of them once created).

Your best bet might be to use HAProxy or similar load balancer to implement your throttling rules in front of your app servers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文