ikshwak / iperf

Automatically exported from code.google.com/p/iperf
Other
0 stars 0 forks source link

backgrounding and redirecting iperf3 server oddity #138

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. write a script that iperf as a server and redirect its output (i.e. tee) 
(only way I know to monitor report server side)
2. in the script background iperf and wait for it (to handle signals)
3. launch this script itself in background (nohup if you like)

What is the expected output? What do you see instead?

0. if I just launch the script (backgrounding iperf, but not the script)
 1. without --verbose nothing happens when redirecting
 2. with --verbose, the output is buffered on report ("iperf3 --server --verbose | tee /dev/stdout", shows two reports, no interleaved lines), maybe it is not really convenient but not a big deal
3. if I background the script too, nothing works (even on client side, which is 
blocked)

What version of the product are you using? On what operating system?

iperf version 3.0.1 (10 January 2014)
Linux sd-41347 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1 x86_64 GNU/Linux

Please provide any additional information below.

cat iperf_server.sh

#!/bin/bash

while [ 0 ];
    do
        iperf3 --server --port 22222 --verbose | tee /tmp/iperf3.log.raw | awk '{print strftime("%F %T",systime()),$0; fflush()}' | tee /tmp/iperf3.log
        wait $!
        if [ $? ];
            then
                sleep 1;
        fi;
done

# and

nohup ./iperf_server.sh > /dev/stdnull &

Original issue reported on code.google.com by stephane...@lip6.fr on 17 Feb 2014 at 11:18

GoogleCodeExporter commented 9 years ago
I acknowledge seeing this report.

In step 2 when you did a test doing tee to /dev/stdout, note that tee(1) send 
its stdin to stdout and to the file you specify, so getting two copies on 
stdout is expected.

It feels to me like you're seeing the effects of buffering of output in various 
places (particularly with the result from the test in the previous paragraph 
having non-interleaved lines of output) but I haven't actually experimented 
with this.

Original comment by bmah@es.net on 21 Feb 2014 at 9:14

GoogleCodeExporter commented 9 years ago
This is also somewhat related to Issue 119.

Original comment by bmah@es.net on 21 Feb 2014 at 10:26

GoogleCodeExporter commented 9 years ago
Hi,

I agree.

Obviously.
I wasn't clear, the issue is not that you get two reports to stdout (I wondered 
if they were other outputs).
The issue is that it seems that, when you redirect stdout, it needs --verbose 
flag to actually show message you get previously without --verbose when no 
redirection
no redirection and no --verbose ---> some message
no redirection and --verbose --->  more message
redirection and no --verbose ---> almost nothing
redirection and --verbose ---> everything (it seems) but buffered on reports

buffering on reports --> It seems to me that there is no fflush per iprintf 
call (but more likely at closing of the stream ?)
--verbose --> it seems this introduces a fflush (line 452 of iperf_server_api.c)

while my tee is line buffered:
sh -c "date; sleep 1; date" | tee -
# correctly print two identical lines then wait 1 sec before printing two 
identicals lines

maybe this has to do with some buffering options set on the fd for stdout.

I agree.

Thanks for your work.

Original comment by stephane...@lip6.fr on 23 Feb 2014 at 5:16

GoogleCodeExporter commented 9 years ago
This might be an interesting pointer
http://stackoverflow.com/questions/13932932/why-does-stdout-need-explicit-flushi
ng-when-redirected-to-file

Original comment by stephane...@lip6.fr on 23 Feb 2014 at 5:21