Skip to content
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

Merged
merged 1 commit into from
May 9, 2024

Conversation

nimf
Copy link
Collaborator

@nimf nimf commented May 3, 2024

New config options for channel pool:

  • affinityKeyLifetime
  • cleanupInterval

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.

@nimf nimf requested a review from mohanli-ml May 3, 2024 18:05
@@ -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.
Copy link
Collaborator

@mohanli-ml mohanli-ml May 7, 2024

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"?

Copy link
Collaborator Author

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.
Copy link
Collaborator

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)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.
  2. 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.

Copy link
Collaborator

@mohanli-ml mohanli-ml left a 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!

@nimf nimf merged commit a2f5736 into master May 9, 2024
2 checks passed
@nimf nimf deleted the keys-lifetime branch May 9, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants