Repository navigation
Reclaim idle server RPC buffers under memory pressure - #19333
Conversation
|
Review summary (initial self-review): No confirmed issues found in the reviewed working-tree diff against base 60972db. No fixes were needed during review. git diff --check passed; tests were not run. Final local commit and confirmed PR head: 49d6b62. A fresh independent review of this published head remains pending before the PR can return to open. |
| private static long reclaimOneIdleConnection(ServerBufferPool pool) { | ||
| if (!reclaimingServerBuffers.compareAndSet(false, true)) { | ||
| return 0; | ||
| } | ||
| try { | ||
| List<ServerConnectionCandidate> candidates = new ArrayList<>(); | ||
| pool.collectCandidates(candidates, System.nanoTime()); | ||
| candidates.sort(ServerConnectionCandidate.RECLAMATION_ORDER); | ||
| for (ServerConnectionCandidate candidate : candidates) { |
There was a problem hiding this comment.
Reclaiming one connection seems to collect all candidates.
Is it possible that reclaiming n connections becomes n^2?
There was a problem hiding this comment.
Yes. Repeated calls previously rebuilt and sorted the full candidate list, so reclaiming N idle connections could require O(N^2 log N) total work. For a stable candidate set, the pool now sorts once and advances a cached cursor; connection registration/removal, request-state changes, and other buffer reclamation invalidate the snapshot as needed. The added regression test covers snapshot refresh after connection changes. The focused service-rpc test run passed (38 tests).
|
Review summary (comment handling): Addressed the performance concern: repeated one-connection calls previously recollected and sorted all candidates, which could take O(N^2 log N) across N stable idle connections. Per-pool snapshots now retain the ordered candidates and advance a cursor; connection/request changes or other buffer reclamation invalidate the snapshot. Added regression coverage for snapshot refresh after connection changes. Verification: |
jt2594838
left a comment
There was a problem hiding this comment.
The current implementation invalidate the snapshot after each reclaimation.
If there are n reclaimations, the total cost will still be very high.
We does not need all candidates for a reclaimation. Maybe we can remove the candidate from the candidates after reclaimation, reuse the candidates if possible, and update it when we have exhausted them?
|
Review summary (comment handling) Thanks for pointing out that rebuilding the candidate list after each reclamation could make repeated reclamation expensive. The allocation-pressure paths now advance and reuse ordered candidate snapshots for both the preferred pool and other pools; snapshots are invalidated when the candidate set changes, not merely because a candidate was reclaimed. The existing pool-priority ordering is preserved. Added regression coverage verifies snapshot reuse across repeated reclamations in both paths. Verification:
Reviewed source head: The PR remains open and this discussion remains unresolved. A fresh independent review of the updated head is pending. |
Summary
Reclaim oversized reusable RPC buffers on idle synchronous server connections when a new allocation is denied by the configured RPC buffer memory limit. Connections with active requests remain protected, and the input/output transports for one socket share activity state.
For example, after connection A completes a large request and becomes idle, connection B can reclaim A's excess reusable capacity under memory pressure; A remains usable for later requests.
Validation
mvn spotless:apply -P with-integration-tests -pl iotdb-client/service-rpc,iotdb-core/node-commons -ammvn clean test -pl iotdb-client/service-rpc,iotdb-core/node-commons -am -Dtest=AutoResizingBufferTest,TCompressedElasticFramedTransportTest,ThriftServerBufferReclamationTest -Dsurefire.failIfNoSpecifiedTests=false(38 tests passed)