Repository navigation
[Store] Parallelize DFS BatchRead for adapters without batch I/O - #5283
zuozhubinge wants to merge 4 commits into
Conversation
Adapters without batch I/O (POSIX) executed BatchRead requests one by one. Add an optional worker pool (MC_STORE_DFS_READ_THREADS) so the calling thread and pool workers drain validated reads from a shared cursor. Adapters that support batch I/O (3FS) keep the existing batched path. Signed-off-by: zuozhubinge <260291091@qq.com>
d23b968 to
e9c416f
Compare
fcczzz
left a comment
There was a problem hiding this comment.
Could we bound outstanding helper jobs across calls, or wait for every submitted job before returning? remaining only tracks reads, so the caller can finish a batch while its queued drain jobs still retain shared state. Repeated calls can accumulate these jobs while the workers are busy.
Also, PosixKeepsPerRequestBucketHandles still expects peak_open == 1, and its adapter counters are not thread-safe. With parallel reads enabled by default, this can fail or race. Could we explicitly keep that test serial, or synchronize the counters and update the expectations?
BatchRead returned once every read finished, while helper jobs still in the pool queue kept the call's shared state alive. Repeated calls with busy workers could pile up such jobs. Cap queued or running helper jobs at MOONCAKE_DFS_READ_THREADS across calls; without a free slot the caller reads the rest itself. PosixKeepsPerRequestBucketHandles expects one open bucket at a time and uses plain counters, so run it with MOONCAKE_DFS_READ_THREADS=1. Signed-off-by: zuozhubinge <260291091@qq.com>
|
@fcczzz Thanks for the review, both points make sense.
I'll push the update this week. |
The parallel read tests only covered shard layout. Add a bucket-layout test with MOONCAKE_DFS_READ_THREADS=128 that reads one object per bucket and checks content, balanced opens and closes, overlapping reads, and that one call holds at most kMaxOpenBucketsPerBatch bucket fds. Signed-off-by: zuozhubinge <260291091@qq.com>
|
@fcczzz Pushed the fixes:
Tests: |
Capping queued plus running helper jobs at the pool size let the first of several concurrent BatchRead calls hold every slot until its jobs finished; later calls got no helpers. On GPFS with 8 callers and 16 workers this cut throughput from 11650 to 8884 MB/s and raised per-call p99 from 41.2 to 118.7 ms. A job now frees its slot when a worker picks it up, and only queued jobs are capped, at 64x MOONCAKE_DFS_READ_THREADS. A cap of 8x still raised p99 by 18-43% once 16 to 64 callers reached it, so the cap is sized as a safeguard that normal load does not reach; outstanding jobs stay bounded. Signed-off-by: zuozhubinge <260291091@qq.com>
|
@fcczzz A correction to my previous reply: the bound I pushed in f70fd6f lowered throughput and raised tail latency with concurrent callers, so a668fb6 replaces it. What went wrong. f70fd6f capped queued plus running helper jobs at the pool size, and a job held its slot until it finished. With several concurrent
What a668fb6 does. A job frees its slot when a worker picks it up, so the counter covers only jobs still waiting in the queue, and that count is capped at 64 × This gives up what my previous reply said, that an enqueued job starts right away: a job can now wait behind up to 1024 queued jobs. A job whose call has already finished exits after one Why 64×. Any cap that the measured loads reached raised p99. A cap of 8 × threads was fine at 8 callers, but on a larger dataset (64 shards × 2 GiB) it raised p99 from 92 / 186 / 273 ms to 132 / 251 / 321 ms at 16 / 32 / 64 callers. With the 64× cap, same setup, medians of 3 runs alternated between builds:
64 callers × 16 helpers per call is 1024, the cap itself, so these runs cover loads up to the cap; they do not measure behavior above it. Above it, later calls get fewer helpers and their tail latency rises, but the queue stays bounded. Tests on a668fb6: |
Let capable filesystem adapters share cached-shard read ownership while keeping writes, lazy opening, and descriptor repair exclusive. POSIX opts in; adapters with per-read state retain serialized reads by default. Use a shard admission gate so new reads cannot bypass a writer or reopen that already owns admission. Release failed readers before acquiring exclusive ownership for the existing reopen/retry path. Add regressions for overlap, adapter opt-out, writer exclusion, and safe reopen. Complements the intra-batch read work in kvcache-ai#5283 without adding a worker pool or changing configuration defaults. Refs: kvcache-ai#5458 Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
Description
Problem
For filesystem adapters that do not implement batch I/O (today: POSIX),
DistributedStorageBackend::BatchReadexecutes the validated requests one afteranother through
ExecuteSingleIo. A batch of N reads issues N positional reads back toback, so the filesystem sees one outstanding request at a time.
The 3FS adapter already avoids this by submitting the whole batch through
BatchReadAt(#4497, #4498, #4510). This PR covers the adapters that do not have abatch interface.
Change
BatchReadkeeps its existing validation loop unchanged. After validation:SupportsBatchIo()(3FS) take the existing batched path. Nothingchanges for them, and the pool is never created.
ExecuteSingleIofrom a shared atomiccursor. The calling thread and up to
MOONCAKE_DFS_READ_THREADSpool workers claimops with
fetch_adduntil the cursor passes the end; the caller then waits for thein-flight ops to finish.
n - 1workers join abatch of
nops. In bucket layout the caller plus workers are also kept withinkMaxOpenBucketsPerBatch(64), since each bucket read holds its own fd. With the pooldisabled or a single request, the code path is the original serial loop.
64 ×
MOONCAKE_DFS_READ_THREADS; a job frees its slot when a worker picks it up.When the cap is reached, the call enqueues no more helpers and reads the rest itself.
Design notes
concurrency across all callers: N threads calling
BatchReadat once would drop fromN concurrent reads on the serial path to the pool size. An earlier revision of this
change worked this way and ran at 0.66x of serial with 8 callers on a 4-worker pool.
Draining the same cursor from the caller keeps every setting at or above serial.
are held in a
shared_ptrowned by every task. A queued task may start afterBatchReadreturns (for example when the pool is busy with another caller); it thenonly sees
next_index >= totaland exits without touchingopsorresults.pile up in the pool's unbounded queue on a busy pool. The cap counts only jobs not yet
started, because capping running jobs as well let the first concurrent call take
every slot (on GPFS with 8 callers: 8884 vs 11650 MB/s, p99 118.7 vs 41.2 ms). It is
set at 64× so the loads measured here stay at or below it: a cap of 8× raised p99 by
18-43% at 16-64 callers, while with 64× throughput and p99 were within 2% of no cap
(see Benchmark). Above the cap, later calls get fewer helpers.
results[op.index]. Thedecrement uses
acq_reland the waiter checks the counter withacquire, so thecaller sees every result before returning.
ExecuteSingleIofails onlythat request with
FILE_READ_FAIL. This keeps a pool thread from terminating theprocess and guarantees the completion counter always reaches zero. If
enqueuethrowsbecause the pool is stopping, the caller drains the remaining ops itself.
ExecuteSingleIostill holds the per-shard mutex, which[Store] Reopen DFS shard once on POSIX I/O failure before surfacing error #4512 needs for reopen-on-failure. Reads on the same shard therefore still serialize;
the parallelism comes from different shards (shard layout) or different bucket files
(bucket layout).
Configuration
MOONCAKE_DFS_READ_THREADS(new, inDistributedStorageEnvironmentVariables) sets thenumber of extra workers in addition to the calling thread.
posixadapter, 1 (serial) for other adapters<= 12..128> 128The pool is only created for adapters without
SupportsBatchIo(), withMOONCAKE_DFS_READ_THREADSthreads in either layout. In bucket layout at most 63 ofthem join a single call, so one call holds at most 64 bucket fds; concurrent calls can
use the remaining workers.
Behavior changes
MOONCAKE_DFS_READ_THREADS=1torestore the previous serial behavior.
MOONCAKE_DFS_READ_THREADS(default 16) resident workerthreads.
FILE_READ_FAILinstead of propagating out ofBatchRead.BatchReadcall may hold up to min(workers + 1, 64) bucket fds atonce instead of one.
path overlapping buffers ended with the last request's data; with the pool the
result is unspecified.
BatchGetalready passes one buffer per key.Scope
Client::BatchGetand range reads go through multi-requestBatchReadcalls andbenefit. Single-key
Client::Getreads a DFS replica throughReadDfsReplica, whichpasses one request to
BatchRead, so it stays serial.BatchWriteis unchanged.Related work
touch
BatchRead, so whichever lands second needs a rebase.storage_backend_bench.Follow-ups (separate PRs)
reads on the same shard can run concurrently.
BatchWriteusing the same scheme.Suggested Merge Priority
Module
mooncake-store)mooncake-common)Type of Change
How Has This Been Tested?
Test commands:
Test results:
Unit tests
ctest -R dfs: all 8 DFS test binaries pass (dfs_posix_test,dfs_immutable_bucket_backend_test,dfs_immutable_bucket_client_test,dfs_immutable_bucket_allocator_test,dfs_sync_client_test,dfs_read_checksum_test,dfs_enablement_config_test,master_service_dfs_scenario_test).New tests in
DfsBackendParallelTest(POSIX adapter, real files in a temp directory):MatchesSerialAndPreservesOrder: writes 256 objects striped over 8 shards and readsthem back in one batch with
MOONCAKE_DFS_READ_THREADS=1and=8. Every index mustsucceed and match its source byte for byte. The
=1run covers the serial path,which POSIX no longer uses by default.
MapsPerIndexErrorsByDescriptor: mixes valid reads with an invalid shard index, afile name that is not a shard file, and an unaligned offset. Under concurrency each
invalid index fails with
INVALID_PARAMSand the valid ones return correct data.EmptyAndSingleRequestWithPoolEnabled: an empty batch and a single-request batch withthe pool enabled.
ConcurrentCallersWithSmallPool: 8 threads callBatchReadat the same time on a2-worker pool, each over its own range. Every caller must get exactly its own data.
DfsBackendTest.BatchReadPreservesPerKeyErrorsnow runs with 8 workers. Its failuresare injected by file offset, so it checks hard read failures, short reads and
reopen-on-failure on the parallel path.
In
dfs_immutable_bucket_backend_test:PosixKeepsPerRequestBucketHandleschecks that one bucket fd is open at a time, whichonly holds on the serial path, so it now sets
MOONCAKE_DFS_READ_THREADS=1.PosixParallelReadsBoundOpenBuckets(new) reads 2 × 64 objects, one per bucket, with128 workers through an adapter with atomic counters. It checks the data, that every
opened bucket is closed, that more than one bucket was open at once, and that at most
64 were open at once.
ThreadSanitizer
-fsanitize=thread, 30 runs each of the fulldfs_posix_testanddfs_immutable_bucket_backend_testbinaries (60/60 pass): no reports in the new code.The only report seen is a pre-existing race inside glog 0.6.0
LogMessageTime::CalcGmtOffset()(strdup/free of a temporary) when two threads log atthe same time. It is triggered by the error-mapping test logging from several workers
and was suppressed with
race:google::LogMessageTime::CalcGmtOffset.Benchmark
Method: a standalone harness (not part of this PR) calls
BatchReaddirectly on a POSIXDistributedStorageBackendin shard layout, without master or client. It writes thedataset once with
BatchWrite, then for each thread setting builds a fresh backend andissues batches over strided offsets. Latency columns are per
BatchReadcall (one wholebatch), not per object. All runs had 0 errors.
GPFS (201 TB, accessed over TCP; the filesystem we deploy DFS on), 1 MiB objects,
batch 32 (32 MiB per call). GPFS caches were not cleared between runs (the GPFS
pagepool is not affected by
drop_caches).8 callers, 16 shards, 25 GiB, this PR's code (a668fb6), medians of 3 runs:
In the same session, alternated with these runs, the first revision of this PR
(e9c416f, no bound on queued jobs) gave 9736 MB/s at 16 workers with p99 52.0 ms. The
serial baseline, which is the same code in both builds, ranged from 2571 to 3428 MB/s
across runs.
More callers, 64 shards × 2 GiB, 16 workers, medians of 3 runs alternated with the first
revision of this PR (e9c416f, no bound on queued jobs):
The numbers below were measured on the first revision (e9c416f), one run per
configuration. 8 callers × 16 helpers per call is 128, an eighth of the 1024 bound.
while p50 drops. With 8 callers both p50 and p99 drop.
16 and 32 shards.
Local NVMe (for comparison only; our DFS deployments do not place shards on a local
disk; measured on the first revision, one run per configuration). 1 MiB objects, batch
64 (64 MiB per call), 1 caller, 3.2 GiB dataset,
posix_fadvise(DONTNEED)between sweeps:up to 16.
with 16 workers p99 rises from 169 to 210 ms.
Default
The default is 16 workers for POSIX, chosen from the GPFS 8-caller run on the first
revision: 16 workers gave 3.43× and cut per-call p99 from 175 to 60 ms, versus 2.82×
with 8 workers. On this PR's code, 16 workers give 3.28× with p99 196 → 55 ms. The cost is
up to 16 resident threads per backend and, in bucket layout, up to 17 bucket fds per
call. Deployments that prefer fewer threads can lower
MOONCAKE_DFS_READ_THREADS, and=1restores serial reads.Checklist
Signed-off-bytrailer certifying the DCO./scripts/code_format.shAI Assistance Disclosure
An AI coding assistant helped adapt the change to the current
BatchReadstructure,resolve rebase conflicts, review the code, trim the tests, and draft this description.
I reviewed every changed line, ran the tests and benchmarks myself, and take
responsibility for the change.