Skip to content

Commit 851fb89

Browse files
authored
fix(datastore): Update initial ChannelPool configs according to Datastore best practice guide (#12919)
1 parent 5846197 commit 851fb89

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

java-datastore/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,15 @@ public void testGrpcDefaultChannelConfigurations() {
184184
ChannelPoolSettings channelPoolSettings =
185185
((InstantiatingGrpcChannelProvider) datastoreOptions.getTransportChannelProvider())
186186
.getChannelPoolSettings();
187-
assertEquals(channelPoolSettings.getInitialChannelCount(), DatastoreOptions.INIT_CHANNEL_COUNT);
188-
assertEquals(channelPoolSettings.getMinChannelCount(), DatastoreOptions.MIN_CHANNEL_COUNT);
189-
assertEquals(channelPoolSettings.getMaxChannelCount(), DEFAULT_MAX_CHANNEL_COUNT);
187+
assertEquals(DatastoreOptions.INIT_CHANNEL_COUNT, channelPoolSettings.getInitialChannelCount());
188+
assertEquals(DatastoreOptions.MIN_CHANNEL_COUNT, channelPoolSettings.getMinChannelCount());
189+
assertEquals(DEFAULT_MAX_CHANNEL_COUNT, channelPoolSettings.getMaxChannelCount());
190190
assertEquals(
191-
channelPoolSettings.getMaxRpcsPerChannel(),
192-
DatastoreOptions.CHANNEL_POOL_MAX_RPCS_PER_CHANNEL);
191+
DatastoreOptions.CHANNEL_POOL_MIN_RPCS_PER_CHANNEL,
192+
channelPoolSettings.getMinRpcsPerChannel());
193+
assertEquals(
194+
DatastoreOptions.CHANNEL_POOL_MAX_RPCS_PER_CHANNEL,
195+
channelPoolSettings.getMaxRpcsPerChannel());
193196
}
194197

195198
@Test

0 commit comments

Comments
 (0)