-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: Affinity keys cleanup. Allow setting keys lifetime #174
Conversation
@@ -169,12 +170,18 @@ public static class GcpChannelPoolOptions { | |||
private final int concurrentStreamsLowWatermark; | |||
// Use round-robin channel selection for affinity binding calls. | |||
private final boolean useRoundRobinOnBind; | |||
// How long to keep an affinity key after its last use. |
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.
Nit: my intuition of the term "lifetime" starts when the affinity key creates, not when the affinity key last time used. Maybe change to "lifetime" to "staleTime"?
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 plan to introduce another option like refreshKeyLifetimeOnUse
which will default to true
but could be turned to false
in which case the affinityKeyLifetime
will be counted since key creation. So, I'll keep it as affinityKeyLifetime.
@@ -279,6 +298,37 @@ public Builder setUseRoundRobinOnBind(boolean enabled) { | |||
this.useRoundRobinOnBind = enabled; | |||
return this; | |||
} | |||
|
|||
/** | |||
* How long to keep an affinity key after its last use. Zero value means keeping keys forever. |
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.
Nit: how about initialize the value as Duration.ofSeconds(long.MAX_VALUE)?
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.
- We still need to treat zero value somehow. Removing key immediately is not an option. So we either restrict zero value or treat it as it is currently -- disabling keys removal.
- With maxvalue as a default we'll either create an unnecessary timer that will never fire or add a check (as it is now for zero) to not schedule a removal task.
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.
Left two nit comments. Thanks!
New config options for channel pool:
With these options we can set time-to-live (since last use) for affinity keys and how often cleanup procedure should run.
Example use case: if we know Cloud Spanner session is valid for ~1h, then we can set up automatic cleanup of old keys (sessions) from the affinity map.