How many timeouts can Netty HashedWheelTimer handle?

doc says: "The default number of ticks per wheel (i.e. wheel size) is 512. You can specify a larger value if you plan to schedule a lot of timeouts."

Does this mean that by default it can only process 512 timeouts? If I want 100 thousand timeouts in 25 seconds (for SockJS ), what value should I set on the number of ticks per wheel?

+4
source share
1 answer

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.

+9
source

All Articles