Skip to content

Added an option to specify max idle time for a pooled socket. #185

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

Merged
merged 3 commits into from
Jan 11, 2023
Merged

Added an option to specify max idle time for a pooled socket. #185

merged 3 commits into from
Jan 11, 2023

Conversation

romanpolunin
Copy link

When memcached nodes in a large memcached cluster are intentionally restarted, like a couple every day, connections to those nodes become stale. This change is to add an option to discard pooled sockets if they have not been picked up from the pool in the recent time - in our case this would be about a minute. Those "old" sockets are very likely to become stale (since they are rarely picked up from the _freeItems stack - that only happens during occasional spikes in server load).

Added an option to specify max idle time for a pooled socket.
Default value is zero, which turns this feature off.
Enforcement is done at the time of picking the socket out of the pool, not by timer.

…ment is done at the time of picking the socket out of the pool, not by timer.
@romanpolunin
Copy link
Author

This is more of a suggestion PR, as it hasn't been tested. In particular, the logic around proper time _semaphore.Release() isn't fully clear to me (added a comment in MemcachedNode.cs).


if (pair.socket is not null)
{
try { pair.socket.Destroy(); } catch { }
Copy link
Author

Choose a reason for hiding this comment

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

This may need a call to _semaphore.Release() here.

@cnblogs-dudu cnblogs-dudu merged commit ee46b63 into cnblogs:main Jan 11, 2023
@cnblogs-dudu
Copy link

cnblogs-dudu commented Jan 12, 2023

Thanks for your contribution. Please try EnyimMemcachedCore 2.6.0-preview2

@romanpolunin romanpolunin deleted the conn-idle-time branch June 29, 2023 19:06
cw-sanikachavan pushed a commit to carwale/EnyimMemcachedCore that referenced this pull request Jan 17, 2025
…s#185)

Add an option to specify max idle time for a pooled socket

Co-authored-by: Roman Polunin <romanspo@gmail.com>
Co-authored-by: dudu <dudu@cnblogs.com>
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