Mine/add timer system - #334
Open
michael-grunder wants to merge 6 commits into
Open
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>
We store the timer in microseconds, but libhv uses milliseconds. This means a timer of `100.5` milliseconds will get scheduled `now + 100ms`. The timer then likely fires early, and we reschedule for `now + .5ms` which truncates to `0ms` in libhv which then deletes the timer. This issue was entierly found with codex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.