Reputation: 5582
My service is calling an other service and this other service throttle me based on the number of request sent during a hole minutes (doesn't matter how much per second, as long as there is < x request in the last minute)
I would like to display a really really rough estimate to my user of how much request has been made during the last minute. It doesn't need to be accurate in anyway it is just a way for the user to see what roughly the numbers are
What would be the best, least memory demanding way of implementing such a counter ?
Upvotes: 1
Views: 1841
Reputation: 328923
You could do something like:
int[] requestCount = new int[60]
requestCount[(System.currentTimeMillis() / 1000) % 60]++;
IntStream.of(requestCount).sum();
Note:
final AtomicInteger[]
array.The footprint should be fairly small.
Upvotes: 2