View Issue Details

IDProjectCategoryView StatusLast Update
0000083Pgpool-IINew featurepublic2013-11-11 18:31
Reporterserge.logvinovAssigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000083: Set KeepAlive for backend (postgresql)
DescriptionTo test postgres link use tcp_keepalive

$ git branch
* V3_2_STABLE

$ git diff pool_connection_pool.c
diff --git a/pool_connection_pool.c b/pool_connection_pool.c
index 47faac9..46eca0e 100644
--- a/pool_connection_pool.c
+++ b/pool_connection_pool.c
@@ -540,6 +540,43 @@ int connect_inet_domain_socket_by_port(char *host, int port, bool retry)
                close(fd);
                return -1;
        }
+ /* set keepalive */
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)) < 0)
+ {
+ pool_error("connect_inet_domain_socket_by_port: setsockopt(SO_KEEPALIVE) failed: %s", strerror(errno));
+ close(fd);
+ return -1;
+ }
+ else
+ {
+#ifdef KEEPALIVE_WEB_USER
+ /*
+ All web users do not expect more than 1 minute
+ test link max time 25sec
+
+ in sysctl.conf
+ # net.ipv4.tcp_retries2=5
+ # net.ipv4.tcp_syn_retries=4
+ */
+ int keepalive_idle = 10;
+ int keepalive_count = 5;
+ int keepalive_interval = 3;
+ struct timeval timeout;
+ timeout.tv_sec = 10;
+ timeout.tv_usec = 0;
+
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &keepalive_idle, sizeof(int)) < 0)
+ pool_error("connect_inet_domain_socket_by_port: setsockopt(TCP_KEEPIDLE) failed: %s", strerror(errno));
+
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &keepalive_interval, sizeof(int)) < 0)
+ pool_error("connect_inet_domain_socket_by_port: setsockopt(TCP_KEEPINTVL) failed: %s", strerror(errno));
+
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &keepalive_count, sizeof(int)) < 0)
+ pool_error("connect_inet_domain_socket_by_port: setsockopt(TCP_KEEPCNT) failed: %s", strerror(errno));
+
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
+ pool_error("connect_inet_domain_socket_by_port: setsockopt(SO_SNDTIMEO) failed: %s", strerror(errno));
+#endif
+ }



Please keep KEEPALIVE_WEB_USER section. It for new ideas need. Maybe use config file to set this params?
I do not find how set tcp_retries2/tcp_syn_retries in func setsockopt().

TagsNo tags attached.

Activities

t-ishii

2013-11-11 18:31

developer   ~0000368

Please do not submit feature requests/proposals to the bug track. They should be posted to pgpool-hackers mailing list.

Issue History

Date Modified Username Field Change
2013-11-11 15:58 serge.logvinov New Issue
2013-11-11 18:31 t-ishii Note Added: 0000368