lericson / pylibmc

A Python wrapper around the libmemcached interface from TangentOrg.
http://sendapatch.se/projects/pylibmc/
BSD 3-Clause "New" or "Revised" License
479 stars 137 forks source link

please add to the documentation behaviors section some information regarding: tcp_keepalive, retry_timeout. #273

Open trevorboydsmith opened 2 years ago

trevorboydsmith commented 2 years ago

in the documentation there is no mention of the behavior "tcp_keepalive". this behavior is important and necessary when running in a kubernetes or docker-compose scenario because the connection goes through something that monitors for dead connections and the thing that monitors for dead connections has a timeout of like 15 minutes or something.

so i set the memcached behavior "tcp_keepalive" to 300 to ensure that my connecitons do not get cut by the networking thing.

for more better description of the "networking thing" see https://github.com/zulip/zulip/pull/12711 which describes some about pika and also mentions the pylibmc.

my request: please add to the documentation some information regarding the "tcp_keepalive".

also i noticed there was missing a mention of "retry_timeout". please add that to the documentation too. (if you do not set this value to something like 5... does the client just error out on the first error?)


for the tcp keepalive to work you also need to set the "tcp_keepidle" value. unfortunately your python code does not expose this feature from the underlying c library. so for now i have a patch that i wrote.

diff --git a/src/_pylibmcmodule.h b/src/_pylibmcmodule.h
index cee9772..36a28bb 100644
--- a/src/_pylibmcmodule.h
+++ b/src/_pylibmcmodule.h
@@ -202,6 +202,7 @@ static PylibMC_Behavior PylibMC_behaviors[] = {
     { MEMCACHED_BEHAVIOR_TCP_NODELAY, "tcp_nodelay" },
 #if LIBMEMCACHED_VERSION_HEX >= 0x00044000
     { MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, "tcp_keepalive" },
+    { MEMCACHED_BEHAVIOR_TCP_KEEPIDLE, "tcp_keepidle" },
 #endif
     { MEMCACHED_BEHAVIOR_HASH, "hash" },
     { MEMCACHED_BEHAVIOR_KETAMA_HASH, "ketama_hash" },

and i do a pip download --no-binary=pylibmc pylibmc. extract, cd, patch, build, install.

tcp_keepalive is boolean value. see https://man7.org/linux/man-pages/man7/socket.7.html section SO_KEEPALIVE.

tcp_keepidle is integer time in seconds. see https://man7.org/linux/man-pages/man7/tcp.7.html section on TCP_KEEPIDLE.