A wheel is basically a hash table with a separate chain whose hash function is โnotification timeโ. A separate chain is implemented as an unlimited ordered set, so the wheel can have an almost unlimited number of timeouts.
If you plan a timeout that expires in the distant future (i.e. a large delay), the large delay will be divided by wheelSize * tickDuration and use its remainder as a timeout hash. Consequently, the current slot in the wheel can contain both timeouts that expire during the next tickDuration , and timeouts expiring in (tickDuration * wheelSize * n) ms, where the variable n will decrease as the timer flows through the wheel, The latter will cost some processor time when the timer thread visits the slot, because in fact their turn does not end. (This is similar to a collision in traditional hash tables). To reduce the likelihood of collisions, you can increase the size of the wheel.
For example, if you are sure that the scheduled timeout will expire in a minute, you can make wheelSize * tickDuration minute (for example, 600 slots * 100 ms).
Read more about hashed wheels.
source share