-
Notifications
You must be signed in to change notification settings - Fork 158
Parallel Write performance improvements #695
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
Open
MarkWolters
wants to merge
9
commits into
main
Choose a base branch
from
io_improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4bb017
make parallel writes truly asyn
MarkWolters 9ee6ab4
rebase on main
MarkWolters 26bc437
merge fix
MarkWolters 219aa73
make parallel writes configurable option for bench tests
MarkWolters 76e3edb
adding release notes
MarkWolters 51f5732
updating release notes to correct erroneous identification as new fea…
MarkWolters bc076be
add protection against partial writes
MarkWolters 07d3ace
speedup for the legacy path
MarkWolters 1f24c98
Merge branch 'main' into io_improvements
MarkWolters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| ### Fully Asynchronous Parallel Graph Index Writes | ||
|
|
||
| **Description** | ||
| `OnDiskParallelGraphIndexWriter` (introduced in #608) parallelizes serialization of | ||
| Level-0 (L0) node records to disk using Java's `AsynchronousFileChannel`. Although it | ||
| already used the async channel API, each write was previously submitted and immediately | ||
| blocked on via `Future.get()` before the next one began — writing a node's ordinal, then | ||
| each feature, then its neighbor list as a sequence of blocking round-trips rather than a | ||
| truly asynchronous pipeline. This PR removes that bottleneck so parallel writes take full | ||
| advantage of async I/O: | ||
|
|
||
| - **Fast path** (no pre-written features — the common case): each task now packs its | ||
| entire ordinal range into a single contiguous `ByteBuffer` and issues one | ||
| `channel.write()` call for the whole range, instead of one blocking write per node field. | ||
| - **Legacy path** (some features already placed on disk via `writeFeaturesInline()`): each | ||
| task identifies the contiguous byte spans it still owns, submits every write for its | ||
| entire range up front, and only then waits on the collected futures — letting the OS | ||
| schedule the full I/O workload instead of alternating write-then-wait per span. | ||
| - The old per-thread scratch `ByteBuffer`, sized to a single record, forced writes to | ||
| serialize at the buffer level regardless of channel concurrency. It has been removed; | ||
| each task now allocates its own range-sized (fast path) or per-region (legacy path) | ||
| buffer instead. | ||
|
|
||
| **Also in this PR:** a `parallelGraphConstruction` boolean was added to | ||
| `ConstructionParameters`, letting BenchYAML / AutoBenchYAML test configs opt into | ||
| `OnDiskParallelGraphIndexWriter` for index construction instead of the default serial | ||
| `OnDiskGraphIndexWriter`, without any code changes. | ||
|
|
||
| **Performance** | ||
| Example run writing with NVQ + FUSED_ADC features. Before this change, parallel writes | ||
| were ~4x-8x faster than sequential: | ||
| ``` | ||
| Sequential write: 6074.18 ms | ||
| Parallel write: 1373.73 ms | ||
| Speedup: 4.42x | ||
| ``` | ||
| After this change, the same comparison shows ~24x-32x speedups: | ||
| ``` | ||
| Sequential write: 20147.29 ms | ||
| Parallel write: 627.52 ms | ||
| Speedup: 32.11x | ||
| ``` | ||
|
|
||
| **How to Enable** | ||
|
|
||
| *Programmatic API* — no change; `OnDiskParallelGraphIndexWriter.Builder` (available since | ||
| #608) is used the same way as before. The throughput improvement is automatic: | ||
|
|
||
| ```java | ||
| // Serial (existing) path | ||
| var writer = new OnDiskGraphIndexWriter.Builder(graph, outputPath) | ||
| .withMapper(ordinalMapper) | ||
| .with(new InlineVectors(dimension)) | ||
| .build(); | ||
|
|
||
| // Parallel path | ||
| var writer = new OnDiskParallelGraphIndexWriter.Builder(graph, outputPath) | ||
| .withMapper(ordinalMapper) | ||
| .with(new InlineVectors(dimension)) | ||
| // Optional tuning: | ||
| .withParallelWorkerThreads(0) // 0 = use available processors | ||
| .withParallelDirectBuffers(false) // true = off-heap ByteBuffers | ||
| .build(); | ||
|
|
||
| writer.write(featureStateSuppliers); | ||
| writer.close(); | ||
| ``` | ||
|
|
||
| To supply a shared, externally-managed executor (e.g. to bound total thread count across | ||
| concurrent builds): | ||
|
|
||
| ```java | ||
| ExecutorService ioPool = Executors.newFixedThreadPool(16); | ||
| var writer = new OnDiskParallelGraphIndexWriter.Builder(graph, outputPath) | ||
| .withMapper(ordinalMapper) | ||
| .with(new InlineVectors(dimension)) | ||
| .withExecutor(ioPool) // caller is responsible for shutdown | ||
| .build(); | ||
| ``` | ||
|
|
||
| *BenchYAML / AutoBenchYAML* — new in this PR: add the following field under | ||
| `construction` in any index-parameter YAML config file: | ||
|
|
||
| ```yaml | ||
| construction: | ||
| parallelGraphConstruction: Yes # default: No | ||
| ``` | ||
|
|
||
| When set to `Yes`, `Grid` uses `OnDiskParallelGraphIndexWriter` for the on-disk build path. | ||
| The field is optional and defaults to `No` (serial writes) if omitted, so existing config | ||
| files require no changes. | ||
|
|
||
| **Notes** | ||
| - The writer produces output in the same on-disk format as `OnDiskGraphIndexWriter`; indexes | ||
| written with either class are interchangeable and loaded with `OnDiskGraphIndex.load()`. | ||
| This PR changes only the internal write scheduling, not the on-disk format. | ||
| - Write tasks perform blocking file I/O. For best performance supply an I/O-sized thread pool | ||
| (thread count ≥ logical cores) rather than a compute-sized pool when using `withExecutor()`. | ||
420 changes: 309 additions & 111 deletions
420
jvector-base/src/main/java/io/github/jbellis/jvector/graph/disk/NodeRecordTask.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.