@@ -53,12 +53,21 @@ public class DatastoreOptions extends ServiceOptions<Datastore, DatastoreOptions
5353 private static final String DEFAULT_DATABASE_ID = "" ;
5454 public static final String PROJECT_ID_ENV_VAR = "DATASTORE_PROJECT_ID" ;
5555 public static final String LOCAL_HOST_ENV_VAR = "DATASTORE_EMULATOR_HOST" ;
56+
57+ // Default to a slightly larger channel count to handle a larger initial QPS. The initial
58+ // configuration should be able to handle a max of ~500 concurrent streams as each gRPC
59+ // channel can handle a max of 100 streams (limited by Google Middleware). The initial
60+ // configuration aims to have a max of ~250 concurrent streams and will rely on the ChannelPool
61+ // to resize according to the client's average load.
5662 public static final int INIT_CHANNEL_COUNT = 5 ;
63+ // Default to be larger than Gax's default (2) to better scale with spikes in requests
5764 static final int CHANNEL_POOL_DEFAULT_RESIZE_DELTA = 5 ;
58- // Configure this default to be 100 to match the typical default `MAX_CONCURRENT_STREAMS`.
59- // Larger values *may* experience possible client-side queueing as excess streams cannot be
60- // multiplexed onto a full Http2 connection.
61- static final int CHANNEL_POOL_MAX_RPCS_PER_CHANNEL = 100 ;
65+
66+ // Configure the min and max RPC/Channel default in accordance to Datastore configuration guide:
67+ // https://docs.cloud.google.com/datastore/docs/java-client-grpc#connection_pool_configuration
68+ static final int CHANNEL_POOL_MIN_RPCS_PER_CHANNEL = 10 ;
69+ static final int CHANNEL_POOL_MAX_RPCS_PER_CHANNEL = 50 ;
70+
6271 public static final int MIN_CHANNEL_COUNT = 1 ;
6372
6473 // This is a default max channel constant value set to handle the default initial channel
@@ -246,11 +255,13 @@ private DatastoreOptions(Builder builder) {
246255 // Datastore sets the initial channel pool count to be 5 channels to allow better handle
247256 // large loads of requests and the resize delta to be 5 to scale quicker. In cases of low
248257 // load, the channel count will scale down as needed and memory will be freed. The default
249- // configuration is set to try and handle ~500 QPS and will scale up and down as needed.
258+ // configuration is set to try and handle an average of ~250 QPS and will scale up and down
259+ // as needed.
250260 ChannelPoolSettings datastoreChannelPoolSettings =
251261 ChannelPoolSettings .builder ()
252262 .setInitialChannelCount (INIT_CHANNEL_COUNT )
253263 .setMinChannelCount (MIN_CHANNEL_COUNT )
264+ .setMinRpcsPerChannel (CHANNEL_POOL_MIN_RPCS_PER_CHANNEL )
254265 .setMaxRpcsPerChannel (CHANNEL_POOL_MAX_RPCS_PER_CHANNEL )
255266 .setMaxResizeDelta (CHANNEL_POOL_DEFAULT_RESIZE_DELTA )
256267 .build ();
0 commit comments