algorithm - Standard Java queue data structure with time qouta? -
in order implement service limits of request count per time quantity implementation of queue reject adding elements if enqueue()/add()
command exceeded frequency rate?
so example can call enqueue()/add()
no more 1000 times per second , prevent high resource consuming service ddos.
also queue must reject enqueue()/add()
if queue capacity exceeded (until call dequeue()/remove()
).
one simple way implement check following whenever new enqueue / add operation requested:
- check whether queue full
- check whether time since last enqueue operation > 1/1000 seconds. 2a) can modify point 2 above keeping time stamp of 1000 latest enqueue operations. whenever enqueue operation requested, check time since first operation made in queue. if more 1 second, pop out operation time stamp queue , add one.
Comments
Post a Comment