Add internal timer system for async timeout handling - #330
Conversation
Add src/timer.c with a pre-allocated pool of timers managed as a sorted linked list. Timers can be scheduled, cancelled, and processed one at a time (to allow callbacks to free the context). This is the foundation for running multiple concurrent timers (command timeout, connect timeout, cluster topology refresh, etc.) through a single adapter scheduleTimer hook. Callers that need periodic behavior reschedule in their callback. Uses CLOCK_MONOTONIC on Unix and QueryPerformanceCounter on Windows. Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Connect and command timeouts are now separate timers: - connect_timer: scheduled during connect, cancelled on success - command_timer: scheduled on first write when connected, tracks reply activity to detect unresponsive servers valkeyAsyncHandleTimeout dispatches expired timers via valkeyProcessTimers. No adapter changes required. | Test | main | PR | |--------------------------|--------|--------| | 10000x PING pipelined | 0.004s | 0.005s | (avg from 4 runs) | 10000x INCRBY pipelined | 0.004s | 0.004s | (avg from 4 runs) | 10000x LRANGE pipelined | 0.793s | 0.782s | (avg from 4 runs) Note: changing command_timeout at runtime no longer affects an already-running timer. The new value takes effect after the current timer fires. Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
|
This is a massive improvement. I'm still going through it but I have a couple extra commits in a branch on my fork Just the overflow comment and re-allowing a user to disable a timeout after it has been set. I think we still want that behavior? |
Co-authored-by: Michael Grunder <michael.grunder@gmail.com> Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Co-authored-by: Michael Grunder <michael.grunder@gmail.com> Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Co-authored-by: Michael Grunder <michael.grunder@gmail.com> Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Co-authored-by: Michael Grunder <michael.grunder@gmail.com> Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
|
@michael-grunder Moved the valkeyTimerList allocation now, alot better. I also added your improvement commits. I wonder if its possible to get rid of I think the command timeout could be moved already by starting the The connect timer is harder since we need to start it in |
Adds a pre-allocated timer pool that supports multiple concurrent async timers through a single adapter hook.
This allows adding additional timers (cluster topology refresh, c-ares DNS timeouts, health checks) without requiring adapter changes.
Timer framework (commit 1)
Async timeout migration (commit 2)
connect_timerandcommand_timerwith own callbacksrefreshTimeoutis now a regular exported function (for TLS .so)Behavior change
Changing
command_timeoutat runtime no longer affects an already-running timer.The new value takes effect after the current timer fires.