Repository navigation
Let writes in while scans run on a live graph - #2969
Draft
miratepuffin wants to merge 3 commits into
Draft
miratepuffin wants to merge 3 commits into
miratepuffin wants to merge 3 commits into
Conversation
Scans used core_graph().lock(), which read-locks every node and edge segment for the whole scan, so writes waited for every overlapping scan to end. On a live graph, scans now take one segment at a time; read-only graphs are already locked and exporters keep lock() for a consistent copy. A scan entering a segment gives a waiting writer up to 1 ms first. Node writers block instead of retrying on a timer, and add_edge across two node segments waits on one and tries the other instead of spinning on both.
Contributor
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.
| Benchmark suite | Current: 3c89629 | Previous: d4702e6 | Ratio |
|---|---|---|---|
graphgen_max_out_degree/graphgen_max_out_degree |
361965 ns/iter (± 1551) |
75323 ns/iter (± 443) |
4.81 |
graphgen_max_in_degree/graphgen_max_in_degree |
366335 ns/iter (± 5000) |
78791 ns/iter (± 367) |
4.65 |
graphgen_min_out_degree/graphgen_min_out_degree |
365941 ns/iter (± 3879) |
75813 ns/iter (± 322) |
4.83 |
graphgen_min_in_degree/graphgen_min_in_degree |
365926 ns/iter (± 3479) |
78947 ns/iter (± 639) |
4.64 |
This comment was automatically generated by workflow using github-action-benchmark.
Contributor
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'RDF Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.
| Benchmark suite | Current: 5e6a657 | Previous: d4702e6 | Ratio |
|---|---|---|---|
bsbm5000_sparqloscope/000/raphtory |
20847167 ns/iter (± 3248912) |
6499060 ns/iter (± 211072) |
3.21 |
bsbm5000_sparqloscope/001/raphtory |
20598202 ns/iter (± 646941) |
6511938 ns/iter (± 120273) |
3.16 |
bsbm5000_sparqloscope/008/raphtory |
15064075 ns/iter (± 409023) |
1423347 ns/iter (± 5555) |
10.58 |
bsbm5000_sparqloscope/009/raphtory |
15360728 ns/iter (± 891377) |
1414191 ns/iter (± 5627) |
10.86 |
bsbm5000_sparqloscope/010/raphtory |
21578909 ns/iter (± 3573139) |
6866210 ns/iter (± 867676) |
3.14 |
bsbm5000_sparqloscope/030/raphtory |
18416988 ns/iter (± 155093) |
3263617 ns/iter (± 33186) |
5.64 |
bsbm5000_sparqloscope/045/raphtory |
16314695 ns/iter (± 514465) |
3132715 ns/iter (± 17987) |
5.21 |
bsbm5000_sparqloscope/063/raphtory |
16234798 ns/iter (± 156319) |
2037446 ns/iter (± 52108) |
7.97 |
mat_p/instant/sparql_snapshot@10523 |
95434768 ns/iter (± 2699957) |
15752592 ns/iter (± 73439) |
6.06 |
ver_p/instant/sparql_values_5_versions |
474407230 ns/iter (± 5394104) |
76149039 ns/iter (± 584816) |
6.23 |
This comment was automatically generated by workflow using github-action-benchmark.
A read guard per node made parallel aggregates on a live graph contend on the segment lock. Take one graph lock per chunk of 16k nodes instead.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
Scans over a live graph no longer hold every segment for the whole scan, so writes can get in while scans run.
Nodes::iter/par_iter/len,edges(), theLazyNodeStatepaths andPathFromNode::mapusedcore_graph().lock(), which read-locks every node and edge segment for the iterator's life. On a live graph they now iterate the unlocked storage, which locks each segment as the scan reaches it (the existing*_unlockediterators already did this). A read-only graph is alreadyGraphStorage::Locked, so it behaves as before. Exporters that need a consistent copy keeplock(): parquet encode,materialize, the cached view.head_arc()/locked()wait up to 1 ms while a writer is queued on the segment, then take the usual recursive read. The wait is bounded, so a thread that already reads the segment can't deadlock on it.write(), like edge heads.add_edgebetween two existing nodes in different segments waits on one segment and only tries the other, swapping on failure. Before, it spun on twotry_writercalls with no back-off.locked()useshead_arc()instead of a fairread_arc().Why are the changes needed?
While any scan ran, every write waited for it to finish. With scans overlapping, writes didn't get in at all: a reader always held each segment, and
read_recursivelets the next scan in past a queued writer. With one scan loop running, each write waited about one full scan; with four overlapping loops, no write completed until the scans stopped.Readers re-take segments they already hold, on the same thread and through rayon, so switching to fair reads would deadlock. Holding one segment at a time removes the overlap instead.
Does this PR introduce any user-facing change? If yes is this documented?
Yes. A scan of a live graph no longer sees one snapshot: it sees writes that land in segments it hasn't reached yet, and not those in segments it has already passed. Read-only graphs (
read_only(), served read-only graphs) and exporters still read a consistent snapshot. Writes to a graph that is being scanned now make progress instead of waiting for every scan to end.How was this patch tested?
The
db4-storage,raphtory-storageandraphtory-testssuites pass (release build).Still to come in this draft:
add_edgecalls within 10 s. I'll add it once it's been checked to fail ondb_v4and pass here.base,algobench_fast,algobench_medium,algobench_slow) ondb_v4and on this branch, interleaved and repeated, on live graphs and on the same graphs asread_only()handles. Any benchmark more than 5% slower will be flagged here.Are there any further changes required?
Parallel aggregates over a live graph now take a read guard per node op instead of reading under one whole-graph lock. If the benchmarks show that costs more than 5%, the parallel paths should lock one segment per rayon task instead.
Security implications if any