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:

  1. check whether queue full
  2. 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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -