[Store] parallelize per-bucket reads in BatchLoad via worker pool#3
Open
leaves-zwx wants to merge 1 commit into
Open
[Store] parallelize per-bucket reads in BatchLoad via worker pool#3leaves-zwx wants to merge 1 commit into
leaves-zwx wants to merge 1 commit into
Conversation
BatchLoad previously iterated buckets sequentially, issuing one set of preads per bucket before moving to the next. Each bucket is a separate file with no shared read state, so this serialization was purely artificial; on a single NVMe device with default 256 KiB bucket gaps it limited read throughput to ~1.4 GB/s while the device is capable of ~4-5 GB/s. Fix: mirror the WriteBucket parallelization pattern from commit e738cfd. Capture the per-bucket body as a lambda returning std::optional<ErrorCode> (nullopt on success, error code on unrecoverable failure) and dispatch the buckets across a bounded set of worker threads. Workers pull bucket indices from a shared atomic counter and stop as soon as one bucket returns a fatal error, so the caller joins all workers before returning. The serial path is retained when offload_read_threads<=1 or there is only one bucket, preserving the legacy behavior with no thread overhead. Thread safety: - bucket_read_plans is snapshotted into a vector of (bid, plans*) pairs before workers start; the unordered_map is never touched concurrently. - Each bucket opens its own fd via OpenFile; StorageFile instances are not shared across worker threads. - batch_object.at(key).ptr writes target disjoint keys (a key belongs to exactly one bucket), so different workers mutate distinct map values. - VLOG is thread-safe via glog. Env var (added): MOONCAKE_OFFLOAD_READ_THREADS (default 4). Set to 1 to fall back to the legacy serial loop. Mirrors MOONCAKE_OFFLOAD_WRITE_THREADS. Also adds a batchload_dispatch VLOG so the parallel/serial decision and effective thread count are visible in stage-4 diagnosis logs.
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.
BatchLoad previously iterated buckets sequentially, issuing one set of preads per bucket before moving to the next. Each bucket is a separate file with no shared read state, so this serialization was purely artificial; on a single NVMe device with default 256 KiB bucket gaps it limited read throughput to ~1.4 GB/s while the device is capable of ~4-5 GB/s.
Fix: mirror the WriteBucket parallelization pattern from commit e738cfd. Capture the per-bucket body as a lambda returning std::optional (nullopt on success, error code on unrecoverable failure) and dispatch the buckets across a bounded set of worker threads. Workers pull bucket indices from a shared atomic counter and stop as soon as one bucket returns a fatal error, so the caller joins all workers before returning. The serial path is retained when offload_read_threads<=1 or there is only one bucket, preserving the legacy behavior with no thread overhead.
Thread safety:
Env var (added): MOONCAKE_OFFLOAD_READ_THREADS (default 4). Set to 1 to fall back to the legacy serial loop. Mirrors MOONCAKE_OFFLOAD_WRITE_THREADS.
Also adds a batchload_dispatch VLOG so the parallel/serial decision and effective thread count are visible in stage-4 diagnosis logs.