Repository navigation
Keeper: run consecutive read requests in parallel - #100778
Conversation
|
Workflow [PR], commit [5778d67] Summary: ❌
AI ReviewSummaryThis PR batches consecutive Keeper read requests and executes the thread-safe part in parallel, including PR Metadata
Suggested replacement:
Findings❌ Blockers
💡 Nits
Tests
ClickHouse Rules
Performance & SafetyThe intended throughput improvement is promising, but safety/correctness concerns (unsynchronized shared state, null-request handling, and unresolved ordering guarantees) currently outweigh performance gains for merge readiness. Final Verdict
|
| /// Bump session expiry times along the way. | ||
| if (session_id != prev_session_id) | ||
| { | ||
| session_expiry_queue.addNewSessionOrUpdate(session_id, session_and_timeout[session_id]); |
There was a problem hiding this comment.
session_and_timeout is accessed here without storage_mutex, but this function now runs in parallel with request processing and session_and_timeout can be erased on close (processRequest, same file, session_and_timeout.erase(session_id)). std::unordered_map does not support concurrent read/write, so this is UB (data race / possible iterator-bucket corruption).
Please read timeout under storage_mutex (or make this map access synchronized another way) before calling session_expiry_queue.addNewSessionOrUpdate.
There was a problem hiding this comment.
(No, session_and_timeout.erase(session_id) is not in a read request, let alone any of the requests in is_request_thread_safe list.)
There was a problem hiding this comment.
What, no, (a) session_and_timeout seems to be protected by process_and_responses_lock, which is locked here, (b) "this function now runs in parallel with request processing" - it doesn't.
| DECLARE(UInt64, max_requests_batch_bytes_size, 100*1024, "Max size in bytes of batch of requests that can be sent to RAFT", 0) \ | ||
| DECLARE(UInt64, max_read_batch_size, 100000, "Max size of batch of consecutive read requests that can be executed at once, possibly in parallel", 0) \ | ||
| DECLARE(UInt64, max_read_batch_bytes_size, 10000000, "Max size in bytes of batch of consecutive read requests that can be executed at once, possibly in parallel", 0) \ | ||
| DECLARE(UInt64, parallel_read_threads, 8, "Number of threads for parallel local read request processing. 0 means disabled.", 0) \ |
There was a problem hiding this comment.
The PR adds new coordination settings (max_read_batch_size, max_read_batch_bytes_size, parallel_read_threads, parallel_read_chunk_size, parallel_read_min_batch) in LIST_OF_COORDINATION_SETTINGS, but KeeperConfigurationAndSettings::dump doesn't emit them. As a result, conf/diagnostics output silently omits active values, which makes production debugging and config drift analysis harder.
Please extend dump to include these settings, consistent with existing settings serialization.
There was a problem hiding this comment.
Is there a reason dump doesn't just iterate over the settings (BaseSettings::all()) and print all of them?
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
flaky check: #102116 |
| DECLARE(UInt64, max_requests_batch_bytes_size, 100*1024, "Max size in bytes of batch of requests that can be sent to RAFT", 0) \ | ||
| DECLARE(UInt64, max_read_batch_size, 100000, "Max size of batch of consecutive read requests that can be executed at once, possibly in parallel", 0) \ | ||
| DECLARE(UInt64, max_read_batch_bytes_size, 10000000, "Max size in bytes of batch of consecutive read requests that can be executed at once, possibly in parallel", 0) \ | ||
| DECLARE(UInt64, parallel_read_threads, 8, "Number of threads for parallel local read request processing. 0 means disabled.", 0) \ |
|
The flaky check failure is fixed in #102148, let's update the branch. |
| return false; | ||
|
|
||
| server->putLocalReadRequest(request_info); | ||
| server->putLocalReadRequests({request_info}); |
There was a problem hiding this comment.
KeeperOverDispatcher registers callbacks before calling putLocalReadRequest. With this new behavior, putLocalReadRequest can now return false (e.g. no callback/live-session entry) without throwing, and all callers in KeeperOverDispatcher ignore the return value. That leaves the callback in callback_state->callbacks forever and no response is ever sent.
This is a real behavior regression: before this PR local reads always enqueued, now they can be dropped silently.
Please either (a) keep old behavior for local reads by throwing on failure (like putRequest), or (b) make all KeeperOverDispatcher::{exists,get,list,check,getACL} call sites handle false by erasing the registered callback and invoking it with an explicit error response.
There was a problem hiding this comment.
Unrelated to this PR, but fixed.
…Dispatcher ignoring putLocalReadRequest return value
LLVM Coverage Report
Changed lines: 81.75% (748/915) | lost baseline coverage: 97 line(s) · Uncovered code |
Changelog category (leave one):
Closes #95937
Closes #95938
If there are multiple read requests in a row, run them in multiple threads. Also applies to subrequests inside MultiRead. Watch manipulation is done separately in one thread.
On a local benchmark with mostly reads and a little writes I got 3.5x speedup (17.5k -> 63k read requests/s, mostly multireads). (keeper-bench config: https://pastila.nl/?00c54ccf/3a1344ec00ea197e7cc9ff44a6f7e5c5#+Z0DiSttp+fmd42D61UWMw==GCM + #100670 , keeper server config: https://pastila.nl/?00a5d52e/744ccab4edd77252f940cb85aadf86bd#BjZhlCPmFgu3zCzv4Zttlg==GCM )
I also tried disabling parallel reads and comparing to a build without this PR, to see if the added overhead of preparing tasks is noticeable. There was no significant difference; actually it got a little faster: 17.2k/s -> 17.5k/s (doesn't feel statistically significant, relative to variance between runs), presumably because the slowdown is outweighed by the speedup from the added batching of reads (
read_batchinKeeperDispatcher).Version info
26.4.1.834