RFC - Store inflight state in-memory and flush to sqlite periodically#487
Draft
RFC - Store inflight state in-memory and flush to sqlite periodically#487
Conversation
this logic moved to get_pending_activation now.
043bf65 to
7c3fb12
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #487 +/- ##
==========================================
- Coverage 88.15% 86.42% -1.73%
==========================================
Files 20 22 +2
Lines 5359 5789 +430
==========================================
+ Hits 4724 5003 +279
- Misses 635 786 +151 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Currently all state changes are made in sqlite, and because of the way taskbroker's logic works out the application is almost entirely write operations. With sqlite only having a single write lock on the database, we often see both gRPC, upkeep and consumer latency increases at the same time as contention piles up in sqlite.
These changes move much of the activation state-machine into a set of in-memory heaps/sets that are wrapped with a mutex. This allows gRPC operations to become detached from SQLite writes which should reduce contention on the write lock. As activations are mutated by grpc, and upkeep, modified records are added to the
dirty_idsset, and periodically flushed to SQLite during ingest and upkeep.These changes mean that inflight state is no-longer fully durable. Instead, state changes can be lost between
commitcalls. This could lead to tasks being executed multiple times, but shouldn't result in tasks being lost or dropped. We already have the opportunity for duplicate execution (through processing deadlines), and we'd be expanding the scope of that problem but not creating new durability or data-loss scenarios (that I'm aware of).I've also separated the 'blob storage' and 'metadata storage' into separate tables. We have tried this in #369 and didn't move forward then as we weren't able to see noticeable improvements. My hope is that by separating the tables again, and removing write traffic we can reduce fragmentation in the database as rows containing activation blobs will not be mutated anymore. Splitting storage in Sqlite is also step towards storing large activations on the filesystem (which is also on our future plans).
Next steps
I'd like to get this onto sandboxes and validate:
If this prototype succeeds, I'll put together a more complete plan on how we could incrementally and safely ship these changes.