Hildebrandt Tobias
07/08/2024, 1:54 PMConcurrentList<Pair<Long, String>>
and add the timestamp on each access and removeAt(0)
for each item above a limit like 5000 entries.
Then just count the amount of entries for String
with Long
higher than now - 1000
?
Or have an ConcurrentHashMap<String, Int>
and substract 1 every 10ms and add 1 for each access?
Both sound kind of slow.CLOVIS
07/08/2024, 2:13 PMSemaphore(1000)
and just add a delay(1000)
to each request to force it to take at least 1s. This way, if more requests are started, they are forced to wait until the previous ones are finished.Klitos Kyriacou
07/08/2024, 2:34 PMHildebrandt Tobias
07/08/2024, 8:17 PMSemaphore
, but the response is somewhat time critical.
It's not stock market levels of urgent, but waiting a for more than 250ms is not an option.
The meter is just to force the (b2b) customer to buy a higher access rate and flood protection, but the request itself should be fast.
Maybe I can return early via a callback or something and have the semaphore blocking part linger for some ms to keep a certain rate per second/minute.
Edit: Or I could just do a tryAquire
and if it fails I return TooManyRequest
and if I get the permit I immediately respond to the call, but let the thread linger for X ms.Hildebrandt Tobias
07/09/2024, 9:49 AMCLOVIS
07/09/2024, 9:59 AMdelay
at the end of the request, after you've answered to the client. This way, it doesn't slow down anything.CLOVIS
07/09/2024, 10:02 AMHildebrandt Tobias
07/09/2024, 10:24 AMHildebrandt Tobias
07/09/2024, 10:25 AMCLOVIS
07/09/2024, 10:51 AMCLOVIS
07/09/2024, 10:52 AMHildebrandt Tobias
07/09/2024, 10:53 AMHildebrandt Tobias
07/09/2024, 10:58 AM