{"id":746,"date":"2012-07-19T19:19:26","date_gmt":"2012-07-19T11:19:26","guid":{"rendered":"http:\/\/rmohan.com\/?p=746"},"modified":"2012-07-19T19:19:26","modified_gmt":"2012-07-19T11:19:26","slug":"operating-systems-and-network-tuning","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=746","title":{"rendered":"Operating systems and network tuning"},"content":{"rendered":"<h1>Operating systems and network tuning<\/h1>\n<p>Network tuning can reduce Transmission Control Protocol (TCP) stack delay by changing connection settings and can improve throughput by changing TCP buffers.<\/p>\n<h2>Operating systems<\/h2>\n<p>A Windows system needs the least tuning while a Solaris system needs the most tuning. The following information pertains to each system specified, and might improve WebSphere\u00ae eXtreme Scale performance. You should tune according to your network and application load.<\/p>\n<h2>Windows<\/h2>\n<pre>HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\<\/pre>\n<pre>Tcpip\\Parameters<\/pre>\n<pre>MaxFreeTcbs = dword:00011940<\/pre>\n<pre>MaxHashTableSize = dword:00010000<\/pre>\n<pre>MaxUserPort = dword:0000fffe<\/pre>\n<pre>TcpTimedWaitDelay = dword:0000001e<\/pre>\n<h2>Solaris<\/h2>\n<pre>ndd -set \/dev\/tcp tcp_time_wait_interval 60000<\/pre>\n<pre>fndd -set \/dev\/tcp tcp_keepalive_interval 15000<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_fin_wait_2_flush_interval 67500<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_conn_req_max_q 16384<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_conn_req_max_q0 16384<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_xmit_hiwat 400000<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_recv_hiwat 400000<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_cwnd_max 2097152<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_ip_abort_interval 20000<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_rexmit_interval_initial 4000<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_rexmit_interval_max 10000<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_rexmit_interval_min 3000<\/pre>\n<pre>ndd -set \/dev\/tcp tcp_max_buf 4194304<\/pre>\n<h2>AIX\u00ae<\/h2>\n<pre>\/usr\/sbin\/no -o tcp_sendspace=65536<\/pre>\n<pre>\/usr\/sbin\/no -o tcp_recvspace=65536<\/pre>\n<pre>\/usr\/sbin\/no -o udp_sendspace=65536<\/pre>\n<pre>\/usr\/sbin\/no -o udp_recvspace=65536<\/pre>\n<pre>\/usr\/sbin\/no -o somaxconn=10000<\/pre>\n<pre>\/usr\/sbin\/no -o tcp_nodelayack=1<\/pre>\n<pre>\/usr\/sbin\/no \u2013o tcp_keepinit=40<\/pre>\n<pre>\/usr\/sbin\/no \u2013o tcp_keepintvl=10<\/pre>\n<h2>LINUX<\/h2>\n<pre>sysctl -w net.ipv4.tcp_timestamps=0<\/pre>\n<pre>sysctl -w net.ipv4.tcp_tw_reuse=1<\/pre>\n<pre>sysctl -w net.ipv4.tcp_tw_recycle=1<\/pre>\n<pre>sysctl -w net.ipv4.tcp_fin_timeout=30<\/pre>\n<pre>sysctl -w net.ipv4.tcp_keepalive_time=1800<\/pre>\n<pre>sysctl -w net.ipv4.tcp_rmem=\"4096 87380 8388608\"<\/pre>\n<pre>sysctl -w net.ipv4.tcp_wmem=\"4096 87380 8388608\"<\/pre>\n<pre>sysctl -w net.ipv4.tcp_max_syn_backlog=4096<\/pre>\n<h2>HP-UX<\/h2>\n<pre>ndd -set \/dev\/tcp tcp_ip_abort_cinterval 20000<\/pre>\n<h1><\/h1>\n<h1><\/h1>\n<h1>Linux Tweaking<\/h1>\n<p>Raising netowrk limits for broadband under Linux<em><br \/>\n<\/em>2003.04.01 16:03 by <a href=\"http:\/\/forums.speedguide.net\/member.php?u=4\" target=\"_blank\">Philip<\/a><br \/>\nKeywords: <a href=\"http:\/\/www.speedguide.net\/tags.php?tag=tcpwindow\">TCP Window<\/a>, <a href=\"http:\/\/www.speedguide.net\/tags.php?tag=wan\">WAN<\/a>, <a href=\"http:\/\/www.speedguide.net\/tags.php?tag=tcpip\">TCP\/IP<\/a>, <a href=\"http:\/\/www.speedguide.net\/tags.php?tag=tweak\">tweak<\/a>, <a href=\"http:\/\/www.speedguide.net\/tags.php?tag=linux\">Linux<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The TCP\/IP parameters for tweaking a Linux-based machine for fast internet connections are located in \/proc\/sys\/net\/&#8230; (assuming 2.1+ kernel). This location is volatile, and changes are reset at reboot. There are a couple of methods for reapplying the changes at boot time, ilustrated below.<\/p>\n<p><strong>Locating the TCP\/IP related parameters<\/strong><\/p>\n<p>All TCP\/IP tunning parameters are located under \/proc\/sys\/net\/&#8230; For example, here is a list of the most important tunning parameters, along with short description of their meaning:<\/p>\n<p>\/proc\/sys\/net\/core\/rmem_max &#8211; Maximum TCP Receive Window<br \/>\n\/proc\/sys\/net\/core\/wmem_max &#8211; Maximum TCP Send Window<br \/>\n\/proc\/sys\/net\/ipv4\/tcp_rmem &#8211; memory reserved for TCP receive buffers<br \/>\n\/proc\/sys\/net\/ipv4\/tcp_wmem &#8211; memory reserved for TCP send buffers<br \/>\n\/proc\/sys\/net\/ipv4\/tcp_timestamps &#8211; timestamps (RFC 1323) add 12 bytes to the TCP header&#8230;<br \/>\n\/proc\/sys\/net\/ipv4\/tcp_sack &#8211; tcp selective acknowledgements.<br \/>\n\/proc\/sys\/net\/ipv4\/tcp_window_scaling &#8211; support for large TCP Windows (RFC 1323). Needs to be set to 1 if the Max TCP Window is over 65535.<\/p>\n<p>Keep in mind everything under \/proc is volatile, so any changes you make are lost after reboot.<\/p>\n<p>There are some additional internal memory buffers for the TCP Window, allocated for each connection:<br \/>\n\/proc\/sys\/net\/ipv4\/tcp_rmem &#8211; memory reserved for TCP rcv buffers (reserved memory per connection default)<br \/>\n\/proc\/sys\/net\/ipv4\/tcp_wmem &#8211; memory reserved for TCP snd buffers (reserved memory per connection default)<\/p>\n<p>The tcp_rmem and tcp_wmem contain arrays of three parameter values: the 3 numbers represent minimum, default and maximum memory values. Those 3 values are used to bound autotunning and balance <a href=\"http:\/\/www.speedguide.net\/articles\/linux-tweaking-121\">memory usage<\/a> while under global memory stress.<\/p>\n<p><strong>Applying TCP\/IP Parameters at System Boot<\/strong><\/p>\n<p>You can edit \/etc\/rc.local, or \/etc\/boot.local depending on your distribution so the parameters get automatically reapplied at boot time. The TCP\/IP parameters should be self-explanatory: we&#8217;re basically setting the TCP Window to 256960, disabling timestamps (to avoid 12 byte header overhead), enabling tcp window scaling, and selective acknowledgements:<\/p>\n<pre>echo 256960 &gt; \/proc\/sys\/net\/core\/rmem_default\r\necho 256960 &gt; \/proc\/sys\/net\/core\/rmem_max\r\necho 256960 &gt; \/proc\/sys\/net\/core\/wmem_default\r\necho 256960 &gt; \/proc\/sys\/net\/core\/wmem_max\r\n\r\necho 0 &gt; \/proc\/sys\/net\/ipv4\/tcp_timestamps \r\necho 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_sack \r\necho 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_window_scaling<\/pre>\n<p>Change the values above as desired, depending on your internet connection and maximum bandwidth\/latency. There are other parameters you can change from the default if you&#8217;re confident in what you&#8217;re doing &#8211; just find the correct syntax of the values in \/proc\/sys\/net\/&#8230; and add <a href=\"http:\/\/www.speedguide.net\/articles\/linux-tweaking-121\">a line<\/a> in the above code analogous to the others. To revert to the default parameters, you can just comment or delete the above code from \/etc\/rc.local and restart.<\/p>\n<p>Another method to reapply the values upon boot is to include the following in your \/etc\/sysctl.conf (adjust RWIN values as needed):<\/p>\n<pre>net.core.rmem_default = 256960\r\nnet.core.rmem_max = 256960 \r\nnet.core.wmem_default = 256960\r\nnet.core.wmem_max = 256960 \r\n\r\nnet.ipv4.tcp_timestamps = 0 \r\nnet.ipv4.tcp_sack = 1 \r\nnet.ipv4.tcp_window_scaling = 1<\/pre>\n<p><em>Notes:<\/em><em><br \/>\n<em>Execute <\/em><strong>sysctl -p<\/strong><em> to make these new settings take effect.<\/em><br \/>\n<em>To manually set the MTU value under Linux, use the command: <\/em><strong>ifconfig eth0 mtu 1500<\/strong><em> (where 1500 is the desired MTU size)<\/em><\/em><\/p>\n<p><strong>Changing Current Values without rebooting<\/strong><\/p>\n<p>The current TCP\/IP parameters can be edited without the need for reboot in the following locations:<\/p>\n<p><strong>\/proc\/sys\/net\/core\/<\/strong><strong><br \/>\n<\/strong>rmem_default = Default Receive Window<br \/>\nrmem_max = Maximum Receive Window<br \/>\nwmem_default = Default Send Window<br \/>\nwmem_max = Maximum Send Window<\/p>\n<p><strong>\/proc\/sys\/net\/ipv4\/<\/strong><strong><br \/>\n<\/strong>You&#8217;ll find timestamps, window scalling, selective acknowledgements, etc.<\/p>\n<p><em>Keep in mind the values in \/proc will be reset upon reboot. You still need to add the code in \/etc\/rc.local or \/etc\/boot.local in order to have the changes applied at boot time as described above.<\/em><\/p>\n<p><strong>Other TCP Parameters to consider<\/strong><\/p>\n<p><strong>TCP_FIN_TIMEOUT<\/strong><strong><br \/>\n<\/strong>This setting determines the time that must elapse before TCP\/IP can release a closed connection and reuse its resources. During this TIME_WAIT state, reopening the connection to the client costs less than establishing a new connection. By reducing the value of this entry, TCP\/IP can release closed connections faster, making more resources available for new connections. Addjust this in the presense of many connections sitting in the TIME_WAIT state:<\/p>\n<p><strong># echo 30 &gt; \/proc\/sys\/net\/ipv4\/tcp_fin_timeout<\/strong><strong><br \/>\n<\/strong>(default: 60 seconds, recommended 15-30 seconds)<\/p>\n<p>Notes:<br \/>\nYou can use any of the earlier described methods to reapply these settings at boot time.<br \/>\nHere is a quick way to view the number of connections and their states:<\/p>\n<p><strong>netstat -tan | grep &#8216;:80 &#8216; | awk &#8216;{print $6}&#8217; | sort | uniq -c<\/strong><\/p>\n<p><strong>TCP_KEEPALIVE_INTERVAL<\/strong><br \/>\nThis determines the wait time between isAlive interval probes. To set:<\/p>\n<p><strong>echo 30 &gt; \/proc\/sys\/net\/ipv4\/tcp_keepalive_intvl<\/strong><br \/>\n(default: 75 seconds, recommended: 15-30 seconds)<\/p>\n<p><strong>TCP_KEEPALIVE_PROBES<\/strong><br \/>\nThis determines the number of probes before <a href=\"http:\/\/www.speedguide.net\/articles\/linux-tweaking-121\">timing out<\/a>. To set:<\/p>\n<p><strong>echo 5 &gt; \/proc\/sys\/net\/ipv4\/tcp_keepalive_probes<\/strong><br \/>\n(default: 9, recommended 5)<\/p>\n<p><strong>TCP_TW_RECYCLE<\/strong><strong><br \/>\n<\/strong>It enables fast recycling of TIME_WAIT sockets. The <a href=\"http:\/\/www.speedguide.net\/articles\/linux-tweaking-121\">default value<\/a> is 0 (disabled). The sysctl documentation incorrectly states the default as enabled. It can be changed to 1 (enabled) in many cases. Known to cause some issues with hoststated (load balancing and fail over) if enabled, should be used with caution.<\/p>\n<p><strong>echo 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_tw_recycle<\/strong><br \/>\n(boolean, default: 0)<\/p>\n<p><strong>TCP_TW_REUSE<\/strong><br \/>\nThis allows reusing sockets in TIME_WAIT state for new connections when it is safe from protocol viewpoint. Default value is 0 (disabled). It is generally a safer alternative to tcp_tw_recycle<\/p>\n<p><strong>echo 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_tw_reuse<\/strong><strong><br \/>\n<\/strong>(boolean, default: 0)<\/p>\n<p>Note: The tcp_tw_reuse setting is particularly useful in environments where numerous short connections are open and left in TIME_WAIT state, such as web servers. Reusing the sockets can be very effective in reducing server load.<\/p>\n<p><strong>Kernel Recompile Option<\/strong><\/p>\n<p>There is another method one can use to set TCP\/IP parameters, involving kernel recompile&#8230; If you&#8217;re brave enough. Look for the parameters in the following files:<br \/>\n<strong>\/LINUX-SOURCE-DIR\/include\/linux\/skbuff.h<\/strong><br \/>\n<a href=\"http:\/\/www.speedguide.net\/articles\/linux-tweaking-121\">Look for<\/a> SK_WMEM_MAX &amp; SK_RMEM_MAX<br \/>\n<strong>\/LINUX-SOURCE-DIR\/include\/net\/tcp.h<\/strong><br \/>\nLook for MAX_WINDOW &amp; MIN_WINDOW<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Operating systems and network tuning <\/p>\n<p>Network tuning can reduce Transmission Control Protocol (TCP) stack delay by changing connection settings and can improve throughput by changing TCP buffers.<\/p>\n<p> Operating systems <\/p>\n<p>A Windows system needs the least tuning while a Solaris system needs the most tuning. The following information pertains to each system specified, and might improve [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/746"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=746"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/746\/revisions"}],"predecessor-version":[{"id":747,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/746\/revisions\/747"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}