Answer the question
In order to leave comments, you need to log in
How to save the state of the application so that there is no lag?
The application works in real time. It has a very complex and large state in the form of a tree structure that is constantly changing. Moreover, not only the values of the fields change, but also the structure itself: for example, elements may appear or disappear in arrays, or their sorting may change. Graphs and hash tables are also subject to all sorts of changes.
Trying to serialize this whole structure (into something like JSON or BSON) takes a few seconds.
How to save the state without interrupting the application?
Answer the question
In order to leave comments, you need to log in
Use fork, the child process gets a copy of the parent's memory almost free of charge due to the Copy-on-Write mechanism (this is if you have Linux).
This approach allows you to fork, after that, in the parent process, do further work, and in the child, do not rush to dump what you need to disk.
In this way, we dump an index of tens of gigabytes with almost no performance impact and almost no increase in memory costs, exactly the same way redis (rdb) does it.
When saving - clone the existing structure (in RAM; or always keep the clone "alive" if there is enough memory) and already it - save it asynchronously in the add. stream.
If it's a "clone", then pause its update: "unhook" the connection from the main structure.
After saving to disk, we reset the state of the clone to the "blank" / reset and restore the connection so that the "clone" "comes to life".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question