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

[WIP] Redesign persistence save to file task #4522

Closed

Conversation

chimp1984
Copy link
Contributor

@chimp1984 chimp1984 commented Sep 14, 2020

The model we borrowed from BitcoinJ wallet persistence comes with some complexity and performance costs if the queueUpForSave was called frequently (which is the case). We started for each queueUpForSave call a new thread and most returned without doing work if the persitable data was written by a concurrent task already.

A periodic timer task is a much more simple model. The costs for creating a new task is higher than a runnable execute without doing work in case that there was no new queueUpForSave call.
It also simplifies the usage for clients as the period for persiting is set at intitialisation and cannot be changed anymore (was a bit messy with many different delay values). The period for persistence should reflect the frequency of data changes and the importance that the data is the latest version if the user shuts down quickly.

There is now also a saveNow method in case immediate write is needed. This comes as sync or async with completeHandler so we dont need to add a safety delay before continuing (e.g. shutdown).

- Only set delay at initialisation
- Remove queueUpForSave methods with delay param
- Add saveNow method
- Use longer delay values
- Add shutdown method
Remove executor which got started at each save request, leading to many tasks in case that saveLater was called frequently, which is specially at startup the case.
Use a periodic timer instead, makes the model much more simple.
Add saveNow methods with executor as param so it can be written on synchronously on user thread as well.
Add completeHandlers to the saveNow method.
Add isInitialized to check if the storage is already initialized before calling queueUpForSave
@chimp1984 chimp1984 changed the title Redesign persistence save to file task [WIP] Redesign persistence save to file task Sep 14, 2020
@chimp1984
Copy link
Contributor Author

Replaced by #4527

@chimp1984 chimp1984 closed this Sep 15, 2020
@chimp1984 chimp1984 deleted the fix-persistence-issues branch September 15, 2020 18:11
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

1 participant