perf(watch): eliminate 100ms polling delay in event delivery by miladev95 · Pull Request #343 · rosedblabs/rosedb · GitHub
Skip to content

perf(watch): eliminate 100ms polling delay in event delivery - #343

Open
miladev95 wants to merge 1 commit into
rosedblabs:mainfrom
miladev95:fix/watcher-event-latency
Open

miladev95 wants to merge 1 commit into
rosedblabs:mainfrom
miladev95:fix/watcher-event-latency

Conversation

@miladev95

Copy link
Copy Markdown

In ‍watch.go, the sendEvent goroutine polls the event queue with time.Sleep(100 * time.Millisecond) when it is empty. As a result, an event generated by a Put/Delete/batch commit can sit in the queue for up to 100ms before being sent to the consumer channel, even when the consumer is already blocked waiting.

This can be fixed with a capacity-1 notification channel that wakes the sender immediately, keeping the existing shutdown semantics.

The watcher goroutine previously polled the event queue every 100ms,
so a watch event could be delayed by up to 100ms even when the
consumer was already blocked waiting on the channel.

Replace the polling loop with a capacity-1 notification channel:
putEvent signals it after enqueueing, and sendEvent blocks on it and
drains all queued events. Shutdown semantics via the done channel
are unchanged.

Also add a test asserting an event is delivered within 50ms of a Put.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant