Alter how periodic session caching works #51
Merged
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.
Goal
Embrace periodicially caches sessions on disk to handle the case that a crash might lead to data loss. While this is something we ultimately want to move away from, for now I've refactored the existing implementation so that it handles backpressure more gracefully.
Previously we were using a
ScheduledExecutorService
that executes a runnable at a fixed interval. This works fine for most purposes, but if the device is under severe strain then the executor service is unlikely to keep up, and will have a large queue of jobs to churn through (ironically causing more strain). Historically we had the same problem with ANR data capture.I've therefore refactored the logic so that after each cache a new job is scheduled for the given interval.
Testing
Relied on existing test coverage & manually verified that cached sessions make it through to the dash. I also checked that the interval is more or less the same: