Question & Answer
Question
This technote describes how to view and change TCP/IP keepalive settings or DB2 registry variables to: (1) improve detection of when a client or server that is no longer responding or (2) prevent disconnects on idle connections.
Answer
For further discussion on this topic, visit this developerWorks forum thread:
https://www.ibm.com/developerworks/community/forums/html/topic?id=efaf25ec-4321-4b48-8c90-05c4a3cc3b56
TCP/IP keepalive settings
TCP/IP uses operating system keepalive parameters to detect when the client or server side of an idle connection is no longer responding. DB2 sets the TCP/IP keepalive setting on both the client and server by default.
You may wish to decrease the keepalive parameters on the server side machine to improve detection of client failures, or decrease the keepalive parameters on the client side machine to improve detection of server failures. Alternatively, you may wish to increase the keepalive parameters on the server side machine to prevent client disconnects on idle connections, or increase the keepalive parameters on the client side machine to prevent server disconnects on idle connections.
Each keepalive parameter comes with a default setting; many parameters are configurable. In general, the parameters:
- Determine how long to wait before probing the idle connection. On most platforms the default is 2 hours.
- Determine how long to wait before retrying the probe after initial failure to respond.
- Determine the maximum number of times to retry the probe.
Modifying any keepalive parameter may involve trade-offs and affects applications on your entire machine. For example, changing these parameters affects rlogin, ssh, and telnet. You may wish to reset additional TCP/IP parameters, depending on the overall impact to other TCP/IP parameters. Contact your operating system administrator for help with setting these values.
This Technote describes how to display and modify keepalive values on various operating systems. The table below lists the keepalive parameters and operating systems covered by this TechNote.
Table 1: Keepalive Parameters by Operating System
Operating System | Parameter wait time before probing the connection | Parameter interval between retry probes | Parameter maximum retry probes | Unit of measure |
AIX | tcp_keepidle (the length of time to keep an idle TCP connection active) | tcp_keepintvl (the interval between packets sent to validate the TCP connection) | n/a | half-seconds |
HP-UX 11i | tcp_time_wait_interval (the time that a TCP connection stays in TIME-WAIT state) | tcp_keepalive_interval (the interval between probes) | tcp_keepalives_kill1 (the maximum number of times to probe before dropping) | milliseconds |
Linux | tcp_keepalive_time (the interval between the last data packet sent and the first keepalive probe) | tcp_keepalive_intvl (the interval between subsequent keepalive probes) | tcp_keepalive_probes (the number of probes that are sent and unacknowledged before the client considers the connection broken and notifies the application layer) | seconds |
Solaris | tcp_time_wait_interval (the time that a TCP connection stays in TIME-WAIT state) | tcp_keepalive_interval (the interval between probes) | n/a | milliseconds |
Windows | KeepAliveTime (the time that can elapse without a communication from an endpoint connection before the system checks whether the endpoint connection is still active) | KeepAliveInterval (the time between retransmissions of keepalives, once the KeepAliveTime has expired) | TcpMaxDataRetransmissions (the maximum number of retransmissions before the connection is ended) | milliseconds |
Notes: (1): tcp_keepalives_kill cannot be modified on HP. It is set to 1.
Displaying and modifying keepalive values
Follow these steps to modify the values.
1. Log in as root (or as an Administrator on Windows).
2. Run help on the network tuning parameter or use the man pages on UNIX systems.
Platform | Operating System Command |
AIX | no -a |
HP-UX 11i | ndd -h supported |
Linux | sysctl -h |
Sun Solaris | ndd /dev/tcp \? |
Windows | (Windows NT 3.x) From the Start menu, choose Run and enter "Regentry.hlp" and choose "network services" and choose "TCP/IP Transport Entries". |
3. Display current settings. The values for <tcp_parameter> are shown in Table 1.
Platform | Operating System Command |
AIX | no -o<tcp_parameter> |
HP-UX 11i | ndd -get /dev/tcp <tcp_parameter> |
Linux | sysctl net.ipv4.<tcp_parameter> |
Sun Solaris | ndd -get /dev/tcp <tcp_parameter> |
Windows | From the Start menu, choose Run and enter Regedt32 to view the parameter located in the Registry file HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters |
4. Display the range of available settings.
Platform | Operating System Command |
AIX | This option is not available. |
HP-UX 11i | ndd -h <tcp_parameter> |
Linux | This option is not available. |
Sun Solaris | This option is not available. |
Windows | (Windows NT 3.x) From the Start menu, choose Run and enter "Regentry.hlp" and choose "network services" and choose "TCP/IP Transport Entries". |
5. Modify keepalive values.
Platform | Operating System Command |
AIX | no -o <tcp_parameter>= <tcp _value> |
HP-UX 11i | ndd -set /dev/tcp <tcp_parameter> <tcp_value> |
Linux | sysctl -w net.ipv4.<tcp_parameter> = <tcp_value> (sets the value temporarily until next reboot) To make the change permanently: Update /etc/sysctl.conf with net.ipv4.<tcp_parameter> = <tcp_value> and issue: Red Hat: chkconfig sysctl on Suse: chkconfig boot.sysctl on |
Sun Solaris | ndd -set /dev/tcp <tcp_parameter> <tcp_value> |
Windows | Run Regedt32 to edit the Registry file located in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters. Enter a new value and choose OK. Reboot after editing. |
DB2 registry variables to help detect when a client or server is not responding
If you do not wish to adjust the keepalive operating system settings, DB2 has additional registry variable settings that you can use to help detect some situations where a client or server is not responding.
DB2CHECKCLIENTINTERVAL - Adjusting this variable on the server determines how quickly the DB2 server can detect a client-server connection has been terminated (for example, a client kills a DB2 application). Setting this variable does not help with situations where the client is not responding because of an abnormal machine termination where TCP cannot respond (operating system keepalive values must be adjusted to handle this condition).
DB2TCP_CLIENT_CONTIMEOUT - Adjust this variable on a client to guarantee that a connection will be established or will fail within a specified amount of time. This is useful when the server is not responding because the machine is
DB2TCP_CLIENT_RCVTIMEOUT - Adjust this variable on the client to terminate the connection if data is not received from the server within a specified amount of time. This is useful in situations where a connection has already been established with the server but the server is no longer responding because the machine is overloaded.
DB2TCP_CLIENT_KEEPALIVE_TIMEOUT - Adjust this variable at the client to override the default system-wide TCP keepalive behavior for all TCP/IP-based database connections and instance attachments. The value specified represents the maximum amount of time in seconds that a connection can remain idle before being considered to have died. For database connections, this registry variable can be overridden by the database-specific KeepAliveTimeout keyword in the db2dsdriver.cfg file. Both settings are supported only on AIX, Linux, and Windows platforms, and are available as of V9.7 FP1.
Note: Because DB2TCP_CLIENT_KEEPALIVE_TIMEOUT is not supported on Solaris. If you are using that platform consider using the tcp_ip_abort_interval parameter, which specifies how long an idle connection will stay open, to identify a network failure or storage outage.
Recommendations for keepalive settings
- The suggested value for the keepalive timeout is 15 seconds.
- You should set the keepalive timeout either through the registry variable, DB2TCP_CLIENT_KEEPALIVE_TIMEOUT, or through db2dsdriver.cfg file
For additional details on these registry variables, see the Communications variables topic in the product Information Center at:
- http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.doc/doc/r0005660.htm (for Version 9.1)
- http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.admin.regvars.doc/doc/r0005660.html (for Version 9.5)
- http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.admin.regvars.doc/doc/r0005660.html (for Version 9.7)
- http://publib.boulder.ibm.com/infocenter/db2luw/v9r8/topic/com.ibm.db2.luw.admin.regvars.doc/doc/r0005660.html (for Version 9.8)
- http://publib.boulder.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.db2.luw.admin.regvars.doc/doc/r0005660.html (for Version 10.1)
For further discussion on this topic, visit this developerWorks forum thread:
https://www.ibm.com/developerworks/community/forums/html/topic?id=efaf25ec-4321-4b48-8c90-05c4a3cc3b56
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21231084