Skip to content

Commit 56dd1b2

Browse files
committed
fix(datastore): Update initial ChannelPool configs according to Datastore best practice guide
1 parent 1431e11 commit 56dd1b2

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ 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 (up to ~500 QPS as
58+
// each channel can handle 100 max streams). This default remains a bit conservative and will
59+
// rely on the ChannelPool to resize according to the client's average load.
5660
public static final int INIT_CHANNEL_COUNT = 5;
61+
// Default to be larger than Gax's default (2) to better scale with spikes in requests
5762
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;
63+
64+
// Configure the min and max RPC/Channel default in accordance to Datastore configuration guide:
65+
// https://docs.cloud.google.com/datastore/docs/java-client-grpc#connection_pool_configuration
66+
static final int CHANNEL_POOL_MIN_RPCS_PER_CHANNEL = 10;
67+
static final int CHANNEL_POOL_MAX_RPCS_PER_CHANNEL = 50;
68+
6269
public static final int MIN_CHANNEL_COUNT = 1;
6370

6471
// This is a default max channel constant value set to handle the default initial channel
@@ -246,11 +253,13 @@ private DatastoreOptions(Builder builder) {
246253
// Datastore sets the initial channel pool count to be 5 channels to allow better handle
247254
// large loads of requests and the resize delta to be 5 to scale quicker. In cases of low
248255
// 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.
256+
// configuration is set to try and handle an average of ~250 QPS and will scale up and down
257+
// as needed.
250258
ChannelPoolSettings datastoreChannelPoolSettings =
251259
ChannelPoolSettings.builder()
252260
.setInitialChannelCount(INIT_CHANNEL_COUNT)
253261
.setMinChannelCount(MIN_CHANNEL_COUNT)
262+
.setMinRpcsPerChannel(CHANNEL_POOL_MIN_RPCS_PER_CHANNEL)
254263
.setMaxRpcsPerChannel(CHANNEL_POOL_MAX_RPCS_PER_CHANNEL)
255264
.setMaxResizeDelta(CHANNEL_POOL_DEFAULT_RESIZE_DELTA)
256265
.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)