-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add session pool options for multiplexed session. #2960
Changes from all commits
edc5bbf
49a85df
4cd497b
4a6aa8e
b2aa09d
8d6d71e
77e6e7d
e8b7fad
8aa84e1
57fd405
1253563
d4f6a60
3efaf7c
f41b39f
7e3287f
7edd24d
fe3649b
ae0dbc9
99cd112
7da9d8d
03cfaed
52662f8
cba2a00
b035607
e59cb3a
61ae225
f2f341e
c5652b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,10 @@ public class SessionPoolOptions { | |
/** Property for allowing mocking of session maintenance clock. */ | ||
private final Clock poolMaintainerClock; | ||
|
||
private final Duration waitForMultiplexedSession; | ||
private final boolean useMultiplexedSession; | ||
private final Duration multiplexedSessionMaintenanceDuration; | ||
|
||
private SessionPoolOptions(Builder builder) { | ||
// minSessions > maxSessions is only possible if the user has only set a value for maxSessions. | ||
// We allow that to prevent code that only sets a value for maxSessions to break if the | ||
|
@@ -93,6 +97,9 @@ private SessionPoolOptions(Builder builder) { | |
this.randomizePositionQPSThreshold = builder.randomizePositionQPSThreshold; | ||
this.inactiveTransactionRemovalOptions = builder.inactiveTransactionRemovalOptions; | ||
this.poolMaintainerClock = builder.poolMaintainerClock; | ||
this.useMultiplexedSession = builder.useMultiplexedSession; | ||
this.multiplexedSessionMaintenanceDuration = builder.multiplexedSessionMaintenanceDuration; | ||
this.waitForMultiplexedSession = builder.waitForMultiplexedSession; | ||
} | ||
|
||
@Override | ||
|
@@ -123,7 +130,11 @@ public boolean equals(Object o) { | |
&& Objects.equals(this.randomizePositionQPSThreshold, other.randomizePositionQPSThreshold) | ||
&& Objects.equals( | ||
this.inactiveTransactionRemovalOptions, other.inactiveTransactionRemovalOptions) | ||
&& Objects.equals(this.poolMaintainerClock, other.poolMaintainerClock); | ||
&& Objects.equals(this.poolMaintainerClock, other.poolMaintainerClock) | ||
&& Objects.equals(this.useMultiplexedSession, other.useMultiplexedSession) | ||
&& Objects.equals( | ||
this.multiplexedSessionMaintenanceDuration, other.multiplexedSessionMaintenanceDuration) | ||
&& Objects.equals(this.waitForMultiplexedSession, other.waitForMultiplexedSession); | ||
} | ||
|
||
@Override | ||
|
@@ -148,7 +159,10 @@ public int hashCode() { | |
this.releaseToPosition, | ||
this.randomizePositionQPSThreshold, | ||
this.inactiveTransactionRemovalOptions, | ||
this.poolMaintainerClock); | ||
this.poolMaintainerClock, | ||
this.useMultiplexedSession, | ||
this.multiplexedSessionMaintenanceDuration, | ||
this.waitForMultiplexedSession); | ||
} | ||
|
||
public Builder toBuilder() { | ||
|
@@ -271,6 +285,18 @@ long getRandomizePositionQPSThreshold() { | |
return randomizePositionQPSThreshold; | ||
} | ||
|
||
boolean getUseMultiplexedSession() { | ||
return useMultiplexedSession; | ||
} | ||
|
||
Duration getMultiplexedSessionMaintenanceDuration() { | ||
return multiplexedSessionMaintenanceDuration; | ||
} | ||
|
||
Duration getWaitForMultiplexedSession() { | ||
return waitForMultiplexedSession; | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
@@ -467,6 +493,9 @@ public static class Builder { | |
*/ | ||
private long randomizePositionQPSThreshold = 0L; | ||
|
||
private boolean useMultiplexedSession = false; | ||
private Duration multiplexedSessionMaintenanceDuration = Duration.ofDays(7); | ||
private Duration waitForMultiplexedSession = Duration.ofSeconds(10); | ||
private Clock poolMaintainerClock; | ||
|
||
private static Position getReleaseToPositionFromSystemProperty() { | ||
|
@@ -669,6 +698,47 @@ Builder setPoolMaintainerClock(Clock poolMaintainerClock) { | |
return this; | ||
} | ||
|
||
/** | ||
* Sets whether the client should use multiplexed session or not. If set to true, the client | ||
* optimises and runs multiple applicable requests concurrently on a single session. A single | ||
* multiplexed session is sufficient to handle all concurrent traffic. | ||
* | ||
* <p>When set to false, the client uses the regular session cached in the session pool for | ||
* running 1 concurrent transaction per session. We require to provision sufficient sessions by | ||
* making use of {@link SessionPoolOptions#minSessions} and {@link | ||
* SessionPoolOptions#maxSessions} based on the traffic load. Failing to do so will result in | ||
* higher latencies. | ||
*/ | ||
Builder setUseMultiplexedSession(boolean useMultiplexedSession) { | ||
this.useMultiplexedSession = useMultiplexedSession; | ||
return this; | ||
} | ||
|
||
@VisibleForTesting | ||
Builder setMultiplexedSessionMaintenanceDuration( | ||
Duration multiplexedSessionMaintenanceDuration) { | ||
this.multiplexedSessionMaintenanceDuration = multiplexedSessionMaintenanceDuration; | ||
return this; | ||
} | ||
|
||
/** | ||
* This option is only used when {@link SessionPoolOptions#useMultiplexedSession} is set to | ||
* true. If greater than zero, calls to {@link Spanner#getDatabaseClient(DatabaseId)} will block | ||
* for up to the given duration while waiting for the multiplexed session to be created. The | ||
* default value for this is 10 seconds. | ||
* | ||
* <p>If this is set to null or zero, the client does not wait for the session to be created, | ||
* which means that the first read requests could see more latency, as they will need to wait | ||
* until the multiplexed session has been created. | ||
* | ||
* <p>Note that we would need to use the option {@link SessionPoolOptions#waitForMinSessions} if | ||
* we want a similar blocking behavior for the other sessions within the session pool. | ||
*/ | ||
Builder setWaitForMultiplexedSession(Duration waitForMultiplexedSession) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this should somehow be combined with the
Or if we decide to keep them separate, then we should at least document this difference, so users can figure out why the first read/write transaction could get additional latency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.waitForMultiplexedSession = waitForMultiplexedSession; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets whether the client should automatically execute a background query to detect the dialect | ||
* that is used by the database or not. Set this option to true if you do not know what the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that we are making these method package-private because we don't want to expose these methods publicly yet, but that they will be made public at a later time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. Will make it public at a later point.