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

Alter how periodic session caching works #51

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

fractalwrench
Copy link
Contributor

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:

2023-11-09 14:20:51.419  4868-4868  [Embrace] Periodic cache of session
2023-11-09 14:20:53.420  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:20:55.435  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:20:57.438  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:20:59.443  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:21:01.448  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:21:03.450  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:21:05.454  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:21:07.463  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:21:09.466  4868-4950  [Embrace] Periodic cache of session
2023-11-09 14:21:11.470  4868-4950  [Embrace] Periodic cache of session

Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Merging #51 (9f72815) into master (ea815e8) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #51   +/-   ##
=======================================
  Coverage   74.67%   74.67%           
=======================================
  Files         308      308           
  Lines       10095    10095           
  Branches     1448     1448           
=======================================
  Hits         7538     7538           
  Misses       1982     1982           
  Partials      575      575           
Files Coverage Δ
...brace/android/embracesdk/session/SessionHandler.kt 85.92% <100.00%> (ø)

Copy link
Collaborator

Sweet. I was just looking at this today and if we have big session payloads, it could lead to a tonne of GC and lmkd kills once we background!

Copy link
Collaborator

@bidetofevil bidetofevil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. If need re-start the caching, we should probably just not shutdown the executor.

@fractalwrench
Copy link
Contributor Author

@bidetofevil I made a few changes based on your comments to use scheduleWithFixedDelay instead as that simplifies the implementation & avoids the need to shutdown an executor.

Copy link
Collaborator

@bidetofevil bidetofevil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. LGTM

@fractalwrench fractalwrench reopened this Nov 13, 2023
@fractalwrench fractalwrench merged commit 3d9b6e1 into master Nov 13, 2023
6 checks passed
@fractalwrench fractalwrench deleted the alter-periodic-caching branch November 13, 2023 11:20
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.

None yet

2 participants