Skip to content

Commit 2058dc3

Browse files
committed
chore: add a random channel hint with single use transactions while using multiplexed sessions.
1 parent e444ffc commit 2058dc3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ 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. But GAX currently uses an AtomicLong to perform round-robin
194+
// channel selection and that will cause contention issues at high-concurrency. So we are
195+
// passing
196+
// a random hint instead of doing GAX round-robin.
197+
this.channelHint =
198+
getChannelHintOptions(
199+
session.getOptions(), ThreadLocalRandom.current().nextLong(Long.MAX_VALUE));
195200
}
196201

197202
@Override

0 commit comments

Comments
 (0)