Limit the number of visits per unit time within website

principle:

Using FIFO Queque nature, the current time Enqueue Page each visit, when the number of elements of the Queue does not satisfy the specified constraints, may continue to access; Peek Queue Otherwise, the current time is compared with the value determined Peek, if the interval more than the specified time, then the access frequency reaches the limit value of the time interval required is greater than the limit value, the Dequeue an element, so that the next Enqueue. If the time interval is less than the specified time, you can not continue to visit.

Fake code:

if (queue.Count < num)

then queque.Enqueue (DataTime.Now.Ticks / 1000000) return to normal access

 

time1=queque.Peek

now=DataTime.Now.Ticks/1000000

queque.Enqueue(now)

if (now-time1> designated time)

then queue.Dequeue

return now-time1 <specified time

 

return 

Guess you like

Origin www.cnblogs.com/dennysong/p/10988009.html