From 1589ccc4067a681a14cd469b65a3c689b3a32283 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Wed, 9 Jul 2025 11:51:40 -0400 Subject: [PATCH] Recalculate maxQueueSize based on shards count Currently maxQueueSize is 256 by default. Problem is that some hosts can have 1 shard, others can have 256 shards. While having cap of 256 pending requests for 1 shard host is ok. For host of 256 shards it is way to low. This commit scales maxQueueSize by number of shards, which allow default value works for hosts of any size. --- .../main/java/com/datastax/driver/core/HostConnectionPool.java | 1 + .../src/main/java/com/datastax/driver/core/PoolingOptions.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java b/driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java index 14954b3b5dc..27495bcfd9c 100644 --- a/driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java +++ b/driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java @@ -514,6 +514,7 @@ ListenableFuture borrowConnection( int shardId = 0; if (host.getShardingInfo() != null) { + maxQueueSize = host.getShardingInfo().getShardsCount() * maxQueueSize; if (routingKey != null) { Metadata metadata = manager.cluster.getMetadata(); Token t = metadata.newToken(partitioner, routingKey); diff --git a/driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java b/driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java index 3741ef97ec0..258e3f1647b 100644 --- a/driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java +++ b/driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java @@ -462,7 +462,8 @@ public PoolingOptions setPoolTimeoutMillis(int poolTimeoutMillis) { } /** - * Returns the maximum number of requests that get enqueued if no connection is available. + * Returns the maximum number of requests per shard that get enqueued if no connection is + * available. * * @return the maximum queue size. */