Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement FileWatcher #301

Merged
merged 1 commit into from
Feb 6, 2022
Merged

Implement FileWatcher #301

merged 1 commit into from
Feb 6, 2022

Conversation

benbjohnson
Copy link
Owner

@benbjohnson benbjohnson commented Feb 6, 2022

This pull request changes Litestream's current polling-based file monitoring approach and uses a file watcher instead. It uses inotify on Linux and kqueue 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

@benbjohnson benbjohnson self-assigned this Feb 6, 2022
Repository owner deleted a comment from sonarqubecloud bot Feb 6, 2022
@benbjohnson benbjohnson merged commit 762c7ae into main Feb 6, 2022
@benbjohnson benbjohnson deleted the inotify branch February 6, 2022 16:51
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.

Use fsnotify to watch for database updates
1 participant