control that event with integer number is not happening more than N times per second
<p>My system generates events with integer number. Totally there are about 10 000 of events from 1 to 10 000. Every time I receive new event with numer i need to check how many times I've already received event with such number in tha last second:</p>

<ul>
<li>if I have received this event more than ~3-10 times in last second than I need to ignore it</li>
<li>otherwise i need to process it.</li>
</ul>

<p>So I just need to control and ignore "flood" with events with the same number.</p>

<p>There are two requirements:</p>

<ul>
<li>overhead of the flood control should be really MINIMAL as it used in HFT trading</li>
<li>at the same time i do not need to control "exactly" I just need "roughly" flood control. I.e. it's ok to stop receive events somewhere between 3 and 10 events per second.</li>
</ul>

<p>So my proposal would be:</p>

<ul>
<li>create int[10 000] array</li>
<li>every second refresh all items in this array to 0 (refresh operation of item of the array is atomic, also we can iterate over array without any problems and without locking because we do not insert or delete items, however probably someone can recomend special function to "zero" array, take into accout that I can read array at the same time from another thread)</li>
<li>every time new event received we a) <code>Interlocked.Increment</code> corresponding item in the array and only if the result is less than a threshold (~3) we will process it.</li>
</ul>

<p>So flood control would be just one <code>Intrerlocked.Increment</code> operation and one comparision operation.</p>

<p>What do you tnink can you recommend something better?</p>
