Skip to content

Commit 5ce399a

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

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,12 @@ 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 a random hint instead of doing GAX round-robin.
196+
this.channelHint =
197+
getChannelHintOptions(
198+
session.getOptions(), ThreadLocalRandom.current().nextLong(Long.MAX_VALUE));
195199
}
196200

197201
@Override

0 commit comments

Comments
 (0)