|
VLink 2.0.0
A high-performance communication middleware
|
Hash-wheel timer for managing large numbers of concurrent timeouts efficiently. 更多...
类 | |
| class | vlink::WheelTimer |
| O(1) hash-wheel timer backed by a fixed-size circular slot array. 更多... | |
命名空间 | |
| namespace | vlink |
Hash-wheel timer for managing large numbers of concurrent timeouts efficiently.
WheelTimer implements a hashed timing wheel – a classic data structure for O(1) timer insertion, removal and expiry checking. It is appropriate when hundreds to hundreds of thousands of independent timeouts must be tracked simultaneously, such as in a session manager or a connection-pool keep-alive system.
Algorithm:
slots evenly-spaced time buckets.interval_ms.slots * interval_ms are stored with a round counter and skipped until the counter reaches zero.Lifecycle:
WheelTimer(slots, interval_ms).start() to launch the background worker thread.add(); store the returned Key for later removal.stop() to terminate the background thread.MessageLoop inside the callback.set_catchup_limit() controls how many missed slots are processed in one tick to prevent a long stall from causing a burst of expired callbacks.