IMPORTANT: Per accedir als fitxer de subversion: http://acacha.org/svn (sense password). Poc a poc s'aniran migrant els enllaços. Encara però funciona el subversion de la farga però no se sap fins quan... (usuari: prova i la paraula de pas 123456)

Iperf és una eina que permet fer tests de velocitat (throughput) entre un client i un servidor. Proporciona les eines tant per al client com per al servidor.

Instal·lació

$ sudo apt-get install iperf

Segons el manual:

$ man iperf
 
NAME
      iperf - perform network throughput tests

Servidor

Sintaxi:

$ iperf -s -u -l <MIDA_PAQUET> -S <DS> -i <INTERVAL> -f <FORMAT>

Exemple:

$ iperf -s -u -S0xb8 -i1 -l1472 -fk

La forma més senzilla:

$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------

També es pot executar com a Dimoni:

$ iperf -s -D

Per matar el dimoni:

$ ps aux | grep iperf
sergi     5578  0.0  0.0  19448   560 ?        Sl   19:06   0:00 iperf -s -D
sergi     6059  0.0  0.0   3044   812 pts/3    S+   19:40   0:00 grep --color=auto iperf
$ sudo kill -9 5578

Ports

El port que s'utilitza és el 5001 que no apareix a /etc/services.

Com crear un dimoni permanent

IMPORTANT: Llegiu abans Iperf#Iperf_en_mode_dimoni_.28daemon_mode.29_utilitza_el_100.25_de_la_CPU_fins_i_tot_al_no_estar_sent_utilitzat

Instal·leu iperf:

$ sudo apt-get install iperf

Creeu el fitxer /etc/init.d/iperf:

$ sudo cp /etc/init.d/skeleton /etc/init.d/iperf
$ sudo joe /etc/init.d/iperf

I ompliu les variables:

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Servidor Iperf"
NAME=iperf
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="-s -D"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
 

Feu-lo executable:

$ sudo chmod +x /etc/init.d/iperf

Arranqueu-lo

$ sudo /etc/init.d/iperf start

I ara utilitzeu:

$ sudo update-rc.d iperf defaults

Per fer que el servei s'executi per defecte al iniciar el servidor.

Client

Sintaxi:

$ iperf -c <IP_SERVIDOR> -t <TEMPS> -i <INTERVAL> -u - -b <CAUDAL> -l <MIDA_PAQUET> -f <FORMAT> -d

On:

  • -c : Indica la IP del servidor iperf amb el qual volem fer un test.
  • -d (dual): injecta el flux en les dues direccions
  • -l: MIda del paquet. Útil per a UDP, no pas per a TCP. Quan més gran sigui el paquet menys overhead de les capçaleres.
  • -f (format) : format dels resultats. -fM seria megabytes, -fk seria kilobits/s.
  • -t (time/temps): temps que s'utilitzarà per fer el test en segons (per defecte són només 10 segons)
  • -i (interval): Interval de temps entre tests
  • -u (UDP): test amb UDP. Per defecte s'utilitza TCP.


Exemples

Test simple:

$ iperf -c 10.36.253.3
------------------------------------------------------------
Client connecting to 10.36.253.3, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.126 port 57392 connected with 10.36.253.3 port 5001   

[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.1 sec  6.66 MBytes  5.52 Mbits/sec

Un altre exemple:

$ iperf -c 192.168.1.1 -t60 -i1 -u -S0xb8 -b3M -l1472 -fk -d

Múltiples test al mateix temps (-P)

$ iperf -c 10.228.130.162 -P 5 

Fitxers

$ dpkg -L iperf
/.
/usr
/usr/bin
/usr/bin/iperf
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/iperf.1.gz
/usr/share/doc
/usr/share/doc/iperf
/usr/share/doc/iperf/README
/usr/share/doc/iperf/AUTHORS
/usr/share/doc/iperf/copyright
/usr/share/doc/iperf/changelog.gz
/usr/share/doc/iperf/html
/usr/share/doc/iperf/html/dast.gif
/usr/share/doc/iperf/html/index.html
/usr/share/doc/iperf/html/ui_license.html
/usr/share/doc/iperf/changelog.Debian.gz
/usr/share/doc-base
/usr/share/doc-base/iperf

Exemples

UDP

Al client:

# iperf -c 10.1.1.1 -u -b 10m 

Al servidor:

# iperf -s -u -i 1 

Vegeu:

TCP Window Size

El TCP Window Size s'indica amb l'opció -w.

Al servidor:

#iperf -s -w 4000
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 3.91 KByte
------------------------------------------------------------
[852] local 10.1.1.1 port 5001 connected with 10.6.2.5 port 51400
[ ID]   Interval          Transfer       Bandwidth
[852]   0.0-10.1 sec   704 KBytes   570 Kbits/sec

Al client:

$ iperf -c 10.1.1.1 -w 2000
WARNING: TCP window size set to 2000 bytes. A small window size
will give poor performance. See the Iperf documentation.
------------------------------------------------------------
Client connecting to 10.1.1.1, TCP port 5001
TCP window size: 3.91 KByte (WARNING: requested 1.95 KByte)
------------------------------------------------------------
[ 3] local 10.6.2.5 port 51400 connected with 10.1.1.1 port 5001
[ 3]   0.0-10.1 sec   704 KBytes   572 Kbits/sec


Exemples de test

Localhost

Interfície de loopback:

$ iperf -c localhost -P 1 -i 1 -p 5001 -f m -t 10
------------------------------------------------------------
Client connecting to localhost, TCP port 5001
TCP window size: 0.05 MByte (default)
------------------------------------------------------------
[  3] local 127.0.0.1 port 47370 connected with 127.0.0.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec  1290 MBytes  10823 Mbits/sec
[  3]  1.0- 2.0 sec  1280 MBytes  10737 Mbits/sec
[  3]  2.0- 3.0 sec  1357 MBytes  11381 Mbits/sec
[  3]  3.0- 4.0 sec  1351 MBytes  11333 Mbits/sec
[  3]  4.0- 5.0 sec  1322 MBytes  11087 Mbits/sec
[  3]  5.0- 6.0 sec  1289 MBytes  10810 Mbits/sec
[  3]  6.0- 7.0 sec  1330 MBytes  11159 Mbits/sec
[  3]  7.0- 8.0 sec  1339 MBytes  11229 Mbits/sec
[  3]  8.0- 9.0 sec  1346 MBytes  11291 Mbits/sec
[  3]  9.0-10.0 sec  1370 MBytes  11495 Mbits/sec
[  3]  0.0-10.0 sec  13274 MBytes  11135 Mbits/sec

Interfície local ethernet

$ iperf -c 192.168.111.2 -P 1 -i 1 -p 5001 -f m -t 10
------------------------------------------------------------
Client connecting to 192.168.111.2, TCP port 5001
TCP window size: 0.05 MByte (default)
------------------------------------------------------------
[  3] local 192.168.111.2 port 43144 connected with 192.168.111.2 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec  1201 MBytes  10072 Mbits/sec
[  3]  1.0- 2.0 sec  1222 MBytes  10254 Mbits/sec
[  3]  2.0- 3.0 sec  1291 MBytes  10832 Mbits/sec
[  3]  3.0- 4.0 sec  1194 MBytes  10018 Mbits/sec
[  3]  4.0- 5.0 sec  1233 MBytes  10343 Mbits/sec
[  3]  5.0- 6.0 sec  1328 MBytes  11141 Mbits/sec
[  3]  6.0- 7.0 sec  1244 MBytes  10436 Mbits/sec
[  3]  7.0- 8.0 sec  1274 MBytes  10687 Mbits/sec
[  3]  8.0- 9.0 sec  1316 MBytes  11041 Mbits/sec
[  3]  9.0-10.0 sec  1336 MBytes  11205 Mbits/sec
[  3]  0.0-10.0 sec  12640 MBytes  10603 Mbits/sec

Màquina de la mateixa xarxa a 1G

Switch DLINK: DGS-1008D Green Ethernet:

$ iperf -c 192.168.111.3 -P 1 -i 1 -p 5001 -f m -t 10
------------------------------------------------------------
Client connecting to 192.168.111.3, TCP port 5001
TCP window size: 0.02 MByte (default)
------------------------------------------------------------
[  3] local 192.168.111.2 port 47040 connected with 192.168.111.3 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec    113 MBytes    952 Mbits/sec
[  3]  1.0- 2.0 sec    112 MBytes    942 Mbits/sec
[  3]  2.0- 3.0 sec    112 MBytes    942 Mbits/sec
[  3]  3.0- 4.0 sec    112 MBytes    937 Mbits/sec
[  3]  4.0- 5.0 sec    113 MBytes    948 Mbits/sec
[  3]  5.0- 6.0 sec    112 MBytes    941 Mbits/sec
[  3]  6.0- 7.0 sec    113 MBytes    944 Mbits/sec
[  3]  7.0- 8.0 sec    112 MBytes    938 Mbits/sec
[  3]  8.0- 9.0 sec    113 MBytes    945 Mbits/sec
[  3]  9.0-10.0 sec  93.2 MBytes    782 Mbits/sec
[  3]  0.0-10.1 sec  1112 MBytes    927 Mbits/sec

Comprovar velocitat de transferència de la RB750G de Mikrotik

  • Per comprovar la velocitat del nostre router hem connectat directament un servidor i un client on hem fet servir el iperf, per veure-la el client ha executat la següent comanda:
$ iperf -c 192.168.202.203
------------------------------------------------------------
Client connecting to 192.168.202.203, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.88.3 port 42206 connected with 192.168.202.203 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec    336 MBytes    282 Mbits/sec
  • Observem que la velocitat de transferència és de 336 MB i l'ample de banda és de 282Mbits/segon(En teoria hauría de ser de 1GB).Tot seguit per comprovar la transferència d'arxius en el servidor hem creat per línia de comandes un fitxer que es d'una grandària de 15 GB:
# dd if=/dev/zero of=15G count=15000 bs=1024K
15000+0 registres llegits
15000+0 registres escrits
15728640000 octets (16 GB) copiats, 213,476 s, 73,7 MB/s
  • I per últim des de el client amb la comanda scp hem copiat el fitxer de 15 GB i així hem comprovat la velocitat transferència i el temps que ha tardat:
$ sudo scp [email protected]:15G /media/David/15G
[email protected]'s password: 
15G                                           100%   15GB  30.1MB/s   08:18
  • També hem provat de descarregar-lo per web amb el servidor desde el client, hem penjat el fitxer al servidor i desde el navegador web m'he connectat posant l'IP i l'he descarregat:

Hotspot1212.png

  • Hem posa que tarda 3 minuts i 21 segons però mes o menys m'ha tardat un minut menys:

Hotspot121212.png

Jumbo frames

Monitorització

Nagios. check_iperf

Vegeu també Nagios#iperf

Resol·lució de problemes. Troubleshooting

Iperf en mode dimoni (daemon mode) utilitza el 100% de la CPU fins i tot al no estar sent utilitzat

Versió del fitxer iperf init sense el modi dimoni:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          iperf
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: iperf server
### END INIT INFO
 
# Author: Robert Veznaver

# Do NOT "set -e"
 
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="iperf server"
NAME=iperf
DAEMON=/usr/bin/$NAME
# warning: iperf in daemon mode (-D) consumes 100% CPU (so don't use it)
DAEMON_ARGS="-s -x CDMSV"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
 # Return
 #   0 if daemon has been started
 #   1 if daemon was already running
 #   2 if daemon could not be started
 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
   || return 1
 start-stop-daemon --background --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
   $DAEMON_ARGS \
   || return 2
 # Add code here, if necessary, that waits for the process to be ready
 # to handle requests from services started subsequently which depend
 # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
 # Return
 #   0 if daemon has been stopped
 #   1 if daemon was already stopped
 #   2 if daemon could not be stopped
 #   other if a failure occurred
 start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --name $NAME
 RETVAL="$?"
 [ "$RETVAL" = 2 ] && return 2
 # Wait for children to finish too if this is a daemon that forks
 # and if the daemon is only ever run from this initscript.
 # If the above conditions are not satisfied then add some other code
 # that waits for the process to drop all resources that could be
 # needed by services started subsequently.  A last resort is to
 # sleep for some time.
 start-stop-daemon --stop --quiet --oknodo --retry=0/10/KILL/5 --exec $DAEMON
 [ "$?" = 2 ] && return 2
 # Many daemons don't delete their pidfiles when they exit.
 rm -f $PIDFILE
 return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
 #
 # If the daemon can reload its configuration without
 # restarting (for example, when it is sent a SIGHUP),
 # then implement that here.
 #
 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
 return 0
}

case "$1" in
 start)
 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 do_start
 case "$?" in
   0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
   2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 esac
 ;;
 stop)
 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 do_stop
 case "$?" in
   0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
   2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 esac
 ;;
 #reload|force-reload)
 #
 # If do_reload() is not implemented then leave this commented out
 # and leave 'force-reload' as an alias for 'restart'.
 #
 #log_daemon_msg "Reloading $DESC" "$NAME"
 #do_reload
 #log_end_msg $?
 #;;
 restart|force-reload)
 #
 # If the "reload" option is implemented then remove the
 # 'force-reload' alias
 #
 log_daemon_msg "Restarting $DESC" "$NAME"
 do_stop
 case "$?" in
   0|1)
   do_start
   case "$?" in
     0) log_end_msg 0 ;;
     1) log_end_msg 1 ;; # Old process is still running
     *) log_end_msg 1 ;; # Failed to start
   esac
   ;;
   *)
     # Failed to stop
   log_end_msg 1
   ;;
 esac
 ;;
 *)
 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
 exit 3
 ;;
esac

:

Vegeu també

Enllaços externs