Save and Load performance
I am investigating some thread exhaustion issues with my application and this has led me toward exploring some metrics in automerge.
I have a document (happy to share privately) of around 1MB in size, around 170k change operations. For purposes of this ticket, it's called database.7.10.20230508
In my application I call document.save() periodically, and on application exit to persist the document to disk in the event of crashes, backups, restarts, etc.
This call, with this database takes a (blocking) 0.7s [1], which seems like a pretty significant amount of time. Is it?
pub fn whole_document_blob(&mut self) -> AutomergeSyncBlob {
let start = Instant::now();
let mut doc = self.document.write().unwrap();
histogram!("wait_for_automerge_lock", start.elapsed());
let start = Instant::now();
let res = doc.save();
histogram!("build_automerge_document_bytes", start.elapsed());
res
}# TYPE build_automerge_document_bytes summary
build_automerge_document_bytes{quantile="0"} 0.706331986
build_automerge_document_bytes{quantile="0.5"} 0.706310733304708
build_automerge_document_bytes{quantile="0.9"} 0.706310733304708
build_automerge_document_bytes{quantile="0.95"} 0.706310733304708
build_automerge_document_bytes{quantile="0.99"} 0.706310733304708
build_automerge_document_bytes{quantile="0.999"} 0.706310733304708
build_automerge_document_bytes{quantile="1"} 0.72542781
build_automerge_document_bytes_sum 53.609582082
build_automerge_document_bytes_count 75I think that I could possibly be using save_incremental for the periodic calls and only use save on load (so the first one comes through?) and on program exit but I'm not sure.
The docstring for this is not suggestive that this is correct (our data is more transactional and not like a single character change)
The output of this will not be a compressed document format, but a series of individual changes. This is useful if you know you have only made a small change since the last save and you want to immediately send it somewhere (e.g. you’ve inserted a single character in a text object).
On the other hand it suggests "the output will not be a compressed document format" and I don't know that we care about byte size of the document much at all.
I'm not seeing examples of this in either automerge-repo or in this one, so I would like to file this ticket to figure out what the appropriate patterns might be
[1] An earlier version of this ticket had a typo suggesting "0.7ms" was the value that I was calling "a significant amount of time" -- the value is 700 milliseconds or 0.7 seconds
Source: automerge/automerge