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 objec开发者_如何学编程t.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
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.
精彩评论