Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ public class DatastoreOptions extends ServiceOptions<Datastore, DatastoreOptions
private static final String DEFAULT_DATABASE_ID = "";
public static final String PROJECT_ID_ENV_VAR = "DATASTORE_PROJECT_ID";
public static final String LOCAL_HOST_ENV_VAR = "DATASTORE_EMULATOR_HOST";

// Default to a slightly larger channel count to handle a larger initial QPS (up to ~500 QPS as
// each channel can handle 100 max streams). This default remains a bit conservative and will

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment at lines 57-58 refers to a stale implementation (~500 QPS and 100 max streams) which is inconsistent with the updated configuration. According to repository rules, comments referring to stale implementations should be removed rather than updated.

References
  1. Remove comments that refer to stale implementations instead of updating them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this relevant? If INIT_CHANNEL_COUNT = 5 and CHANNEL_POOL_MAX_RPCS_PER_CHANNEL = 50, the max QPS would be 250, right?

@lqiu96 lqiu96 Apr 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

500 streams is the theoretical max as GFE will enforce a limit of 100 streams/ channel. However CHANNEL_POOL_MAX_RPCS_PER_CHANNEL refers to the channel pool config where we aim to have an avg of 50 streams/ channel

// rely on the ChannelPool to resize according to the client's average load.
public static final int INIT_CHANNEL_COUNT = 5;
// Default to be larger than Gax's default (2) to better scale with spikes in requests
static final int CHANNEL_POOL_DEFAULT_RESIZE_DELTA = 5;
// Configure this default to be 100 to match the typical default `MAX_CONCURRENT_STREAMS`.
// Larger values *may* experience possible client-side queueing as excess streams cannot be
// multiplexed onto a full Http2 connection.
static final int CHANNEL_POOL_MAX_RPCS_PER_CHANNEL = 100;

// Configure the min and max RPC/Channel default in accordance to Datastore configuration guide:
// https://docs.cloud.google.com/datastore/docs/java-client-grpc#connection_pool_configuration
static final int CHANNEL_POOL_MIN_RPCS_PER_CHANNEL = 10;
static final int CHANNEL_POOL_MAX_RPCS_PER_CHANNEL = 50;

public static final int MIN_CHANNEL_COUNT = 1;

// This is a default max channel constant value set to handle the default initial channel
Expand Down Expand Up @@ -246,11 +253,13 @@ private DatastoreOptions(Builder builder) {
// Datastore sets the initial channel pool count to be 5 channels to allow better handle
// large loads of requests and the resize delta to be 5 to scale quicker. In cases of low
// load, the channel count will scale down as needed and memory will be freed. The default
// configuration is set to try and handle ~500 QPS and will scale up and down as needed.
// configuration is set to try and handle an average of ~250 QPS and will scale up and down
// as needed.
ChannelPoolSettings datastoreChannelPoolSettings =
ChannelPoolSettings.builder()
.setInitialChannelCount(INIT_CHANNEL_COUNT)
.setMinChannelCount(MIN_CHANNEL_COUNT)
.setMinRpcsPerChannel(CHANNEL_POOL_MIN_RPCS_PER_CHANNEL)
.setMaxRpcsPerChannel(CHANNEL_POOL_MAX_RPCS_PER_CHANNEL)
.setMaxResizeDelta(CHANNEL_POOL_DEFAULT_RESIZE_DELTA)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,15 @@ public void testGrpcDefaultChannelConfigurations() {
ChannelPoolSettings channelPoolSettings =
((InstantiatingGrpcChannelProvider) datastoreOptions.getTransportChannelProvider())
.getChannelPoolSettings();
assertEquals(channelPoolSettings.getInitialChannelCount(), DatastoreOptions.INIT_CHANNEL_COUNT);
assertEquals(channelPoolSettings.getMinChannelCount(), DatastoreOptions.MIN_CHANNEL_COUNT);
assertEquals(channelPoolSettings.getMaxChannelCount(), DEFAULT_MAX_CHANNEL_COUNT);
assertEquals(DatastoreOptions.INIT_CHANNEL_COUNT, channelPoolSettings.getInitialChannelCount());
assertEquals(DatastoreOptions.MIN_CHANNEL_COUNT, channelPoolSettings.getMinChannelCount());
assertEquals(DEFAULT_MAX_CHANNEL_COUNT, channelPoolSettings.getMaxChannelCount());
assertEquals(
channelPoolSettings.getMaxRpcsPerChannel(),
DatastoreOptions.CHANNEL_POOL_MAX_RPCS_PER_CHANNEL);
DatastoreOptions.CHANNEL_POOL_MIN_RPCS_PER_CHANNEL,
channelPoolSettings.getMinRpcsPerChannel());
assertEquals(
DatastoreOptions.CHANNEL_POOL_MAX_RPCS_PER_CHANNEL,
channelPoolSettings.getMaxRpcsPerChannel());
}

@Test
Expand Down
Loading