Monday, November 10, 2014

Script to tune TCP parameters

#!/sbin/sh
#
# Script to tune TCP parameters.
#
#This Script should be placed in /lib/svc/method/site

. /lib/svc/share/smf_include.sh

# look if this host is backend system, because the tcp_time_wait_interval should be set to 20000 only on backend systems
host=`uname -n`
hostname_part=`echo ${host} | /usr/local/bin/egrep "^de2be|^dlbe|^rbe|^dnbe"`
if [ "$hostname_part" != "" ]
then
        Interval=60000
else
        Interval=60000
fi

case "$1" in
        'start')
                # Set optimized values
                echo "Tuning TCP/IP stack"
                /usr/sbin/ndd -set /dev/tcp tcp_fin_wait_2_flush_interval 675000
                /usr/sbin/ndd -set /dev/tcp tcp_ip_abort_cinterval 60000
                /usr/sbin/ndd -set /dev/tcp tcp_ip_abort_interval 60000
                /usr/sbin/ndd -set /dev/tcp tcp_keepalive_interval 90000
                /usr/sbin/ndd -set /dev/tcp tcp_rexmit_interval_initial 3000
                /usr/sbin/ndd -set /dev/tcp tcp_rexmit_interval_max 10000
                /usr/sbin/ndd -set /dev/tcp tcp_rexmit_interval_min 1000
                /usr/sbin/ndd -set /dev/tcp tcp_slow_start_initial 2
                /usr/sbin/ndd -set /dev/tcp tcp_time_wait_interval ${Interval}
                /usr/sbin/ndd -set /dev/tcp tcp_conn_req_max_q 4096
                /usr/sbin/ndd -set /dev/tcp tcp_conn_req_max_q0 8192
                /usr/sbin/ndd -set /dev/tcp tcp_smallest_anon_port 8192
                /usr/sbin/ndd -set /dev/tcp tcp_xmit_hiwat 64000
                /usr/sbin/ndd -set /dev/tcp tcp_recv_hiwat 64000
                /usr/sbin/ndd -set /dev/tcp tcp_cwnd_max 1048576
                /usr/sbin/ndd -set /dev/ip ip_restrict_interzone_loopback 1
                /usr/sbin/ndd -set /dev/ip ip_lso_outbound 0

                ;;
        'stop')
                # Reset to default values
                echo "Resetting TCP/IP stack to default values"
                /usr/sbin/ndd -set /dev/tcp tcp_fin_wait_2_flush_interval 675000
                /usr/sbin/ndd -set /dev/tcp tcp_ip_abort_cinterval 180000
                /usr/sbin/ndd -set /dev/tcp tcp_ip_abort_interval 480000
                /usr/sbin/ndd -set /dev/tcp tcp_keepalive_interval 900000
                /usr/sbin/ndd -set /dev/tcp tcp_rexmit_interval_initial 3000
                /usr/sbin/ndd -set /dev/tcp tcp_rexmit_interval_max 60000
                /usr/sbin/ndd -set /dev/tcp tcp_rexmit_interval_min 400
                /usr/sbin/ndd -set /dev/tcp tcp_slow_start_initial 4
                /usr/sbin/ndd -set /dev/tcp tcp_time_wait_interval 60000
                /usr/sbin/ndd -set /dev/tcp tcp_conn_req_max_q 1024
                /usr/sbin/ndd -set /dev/tcp tcp_conn_req_max_q0 8192
                /usr/sbin/ndd -set /dev/tcp tcp_smallest_anon_port 32768
                /usr/sbin/ndd -set /dev/tcp tcp_xmit_hiwat 49152
                /usr/sbin/ndd -set /dev/tcp tcp_recv_hiwat 49152
                /usr/sbin/ndd -set /dev/tcp tcp_cwnd_max 1048576
                ;;
        *)
                echo "Usage: $0 { start | stop }"
                exit 1
                ;;
  esac

exit $SMF_EXIT_OK

No comments:

Post a Comment