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.
This pull request changes Litestream's current polling-based file monitoring approach and uses a file watcher instead. It uses
inotify
on Linux andkqueue
on BSD. This provides two benefits. First, it's a step toward real-time read replication as changes will be able to be detected and propagated in milliseconds. Second, it allows a process to scale the number of monitored databases beyond what is practical right now.Currently, change detection is throttled at once per 100ms. This will be reduced to 10ms after another bug is fixed that was detected with the
HighLoad
test case. There's a trade off between change detection frequency and writing a lot of small files to disk. Limiting this to 100 files per second seems like a good threshold while still delivering low latency. This will be adjustable in the future.Originally the plan was to use fsnotify which is a great library but has some limitations due to it providing consistency across all platforms. Litestream needs to have a lot of control as it is being used for low-level replication and that isn't provided through the current
fsnotify
API. The library is also transitioning to an unmaintained state so there was some hesitancy around that going forward as well. Ultimately, the total amount of code to implement file watching for Linux & BSD wasn't too bad and it's nice to have more low-level control.Fixes #190