feat(spider-utils): Add a gRPC connection pool and route the execution-manager and scheduler gRPC clients through it. - #360
Conversation
|
Warning Review limit reached
More reviews will be available in 51 minutes and 25 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughThe PR adds a reusable gRPC ChangesPooled gRPC client rollout
Sequence Diagram(s)sequenceDiagram
participant GrpcSchedulerStorageClient
participant ConnectionPool
participant InboundQueueServiceClient
participant JobOrchestrationServiceClient
GrpcSchedulerStorageClient->>ConnectionPool: connect(endpoint, pool_size)
ConnectionPool-->>GrpcSchedulerStorageClient: inbound_queue_connection_pool and job_orchestration_connection_pool
GrpcSchedulerStorageClient->>ConnectionPool: get_client()
ConnectionPool-->>GrpcSchedulerStorageClient: InboundQueueServiceClient
GrpcSchedulerStorageClient->>InboundQueueServiceClient: poll_ready_tasks / poll_ready_commit_tasks / poll_ready_cleanup_tasks
GrpcSchedulerStorageClient->>ConnectionPool: get_client()
ConnectionPool-->>GrpcSchedulerStorageClient: JobOrchestrationServiceClient
GrpcSchedulerStorageClient->>JobOrchestrationServiceClient: get_job_state
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@components/spider-execution-manager/src/client/grpc/liveness.rs`:
- Line 26: The rustdoc on the liveness client currently mentions the wrong
endpoint, which is misleading in public documentation. Update the doc comment on
the liveness client connection helper in liveness.rs so it refers to the
liveness gRPC endpoint instead of the storage gRPC endpoint, keeping the wording
aligned with the actual service used by the liveness client and its connection
logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2ae0c52a-03a3-48e8-a334-0f2a54dfc7e2
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (9)
components/spider-execution-manager/src/client/grpc/liveness.rscomponents/spider-execution-manager/src/client/grpc/scheduler.rscomponents/spider-execution-manager/src/client/grpc/storage.rscomponents/spider-scheduler/Cargo.tomlcomponents/spider-scheduler/src/storage_client/grpc.rscomponents/spider-utils/Cargo.tomlcomponents/spider-utils/src/grpc/client.rscomponents/spider-utils/src/grpc/mod.rscomponents/spider-utils/src/lib.rs
…add-missing-services
Description
Summary
A
tonic[Channel] multiplexes every request over a single HTTP/2 connection, and cloning the channel does not change that — all clones share one connection and one dispatch buffer. Under concurrency this serializes request dispatch and caps throughput (see hyperium/h2#531). This PR adds a smallConnectionPooltospider-utilsthat holds several independent connections to one endpoint and hands them out round-robin, then migrates the execution-manager and scheduler gRPC clients to build on it instead of a single cloned channel.New pool (
spider-utils/src/grpc)grpc::client::ConnectionPool<GrpcServiceClientType>, a cheaply-cloneable handle (Arc-backed) over a fixed set of pre-connected service clients.ConnectionPool::connect(endpoint, pool_size, client_factory)eagerly openspool_sizeindependent connections and wraps each in a service client via theclient_factoryclosure.pool_sizeis aNonZeroUsizeso an empty pool is unrepresentable.ConnectionPool::get_client()returns the next client by a relaxed atomic round-robin counter; the returned client is a cheap clone that callers issue a single RPC on.grpc::Errorenum (InvalidEndpoint,TonicTransport) that the factory returns.Execution-manager clients (
spider-execution-manager)GrpcStorageClient,GrpcLivenessClient, andGrpcSchedulerClienteach replace their single…Client<Channel>field with aConnectionPool<…Client<Channel>>. Theirconnectconstructors gain apool_size: NonZeroUsizeparameter and build the pool, mapping the pool'sgrpc::Errorthrough each module's existing transport-error conversion. Every per-RPCself.client.clone()becomesself.connection_pool.get_client(); the request/response and error-mapping logic is otherwise unchanged.Scheduler client (
spider-scheduler)GrpcSchedulerStorageClientwraps two distinct storage services (InboundQueueServiceandJobOrchestrationService), so it now holds one pool per service (scheduler_connection_poolandjob_connection_pool), each withpool_sizeconnections. Itsconnectconstructor gains the samepool_sizeparameter. Addedspider-utilsas a dependency ofspider-scheduler.Checklist
breaking change.
Validation performed
Summary by CodeRabbit
New Features
Bug Fixes
Chores