#!/usr/bin/perl # Name: # Tweak # Tweak parameters to tune tcp buffers # # Author: # Börje Josefsson 2003-03-04 # # Function: # Calculate RTT, and compute buffer size needed for TCP # # Revision history: # Date Who Comment # 2003-03-04 bj@sunet.se Initial version # # Parameters: # -v Verbose # -s Set values locally # -b Bandwidth (in Mbit/sec) # -d Duration of ttcp test (in seconds) ########## # Initializion values ########## $numpings = 4; # Number of pings per probing $buflen = 61440; # 15 * pagesize on FreeBSD require "getopts.pl"; &Getopts('vsb:d:') || die "Illegal option(s), see manual!\n"; ############### # Main program ############### $server = $ARGV[0]; $verbose = $opt_v; $bitrate = $opt_b; # in Mbit/sec $duration = $opt_d; $duration = 10 if ($duration < 10); $duration = 60 if ($duration > 60); $bitrate = 10 if ($bitrate < 10); $bitrate = 2000 if ($bitrate > 2000); &ping; $buf=($RTTmax/1e+3) * $bitrate * 1e+6/8; # bitrate -> bytes/sec * RTT $mbuf=$buf/(1024*1024); printf "RTTmax = %5.2f ms. Buffer size needed = %d bytes (%5.2f Mbytes)\n\n", $RTTmax, $buf, $mbuf; $buf = int($buf * 1.25); # Add 25% just in case... print "The following settings can be used on the remote system:\n"; print "\tSyntax for NetBSD/FreeBSD, Your mileage may vary...\n\n"; print "sysctl -w net.inet.tcp.sendspace=$buf\n"; print "sysctl -w net.inet.tcp.recvspace=$buf\n"; print "\n\n"; if ($opt_s) { system "sysctl net.inet.tcp.sendspace=$buf"; system "sysctl net.inet.tcp.recvspace=$buf"; } $bytes_to_send = (($bitrate * 1e+6) / 8) * $duration; $numbufs = int ($bytes_to_send / $buflen); print "\tTTCP parameters, calculated for $duration seconds on $bitrate Mbit/sec:\n"; print "Sender:\n"; print "ttcp -s -t -f m -l $buflen -n $numbufs $server\n"; print "Receiver:\n"; print "ttcp -s -r -f m -l $buflen -n $numbufs\n"; ############### # Subroutines ############### sub ping { # Run 'ping' to calculate RTT print "RTT ping start\n" if $verbose; foreach (`/sbin/ping -n -q -c $numpings $server`) { # Note - command syntax for FreeBSD, needs to be tweaked for other OS:es!! if (/^round-trip.*= (.*)\/(.*)\/(.*)\/.* ms/) { $RTTmin = $1; $RTTavg = $2; $RTTmax = $3; $RTT = sprintf "%5.2f/%5.2f/%5.2f", $RTTmin, $RTTavg, $RTTmax; } } print "RTT ping finished = $RTT\n" if $verbose; }