Skip to content

Commit 42650fa

Browse files
authored
chore: add a random channel hint with single use transactions while u… (#3065)
Without the hint, GAX would do a round-robin on channels. In theory, a random hint would give a better performance than round robin at a high QPS workload. Also YCSB benchmarks suggest having the hint is better for higher QPS.
1 parent 252e0ff commit 42650fa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractReadContext.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ private SingleReadContext(Builder builder) {
190190
this.bound = builder.bound;
191191
// single use transaction have a single RPC and hence there is no need
192192
// of a channel hint. GAX will automatically choose a hint when used
193-
// with a multiplexed session.
194-
this.channelHint = getChannelHintOptions(session.getOptions(), null);
193+
// with a multiplexed session to perform a round-robin channel selection. We are
194+
// passing a hint here to prefer random channel selection instead of doing GAX round-robin.
195+
this.channelHint =
196+
getChannelHintOptions(
197+
session.getOptions(), ThreadLocalRandom.current().nextLong(Long.MAX_VALUE));
195198
}
196199

197200
@Override

0 commit comments

Comments
 (0)