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 ?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.