Commit 7c310be9 authored by Olav Kvittem's avatar Olav Kvittem
Browse files

kill better, external pipe_size hangs, debug=s

parent 8aee0bfd
Pipeline #45953 passed with stages
in 55 seconds
......@@ -17,7 +17,7 @@ logdir=$logpath/$date
PIPE=$logdir/crude.pipe
if test ! -p $PIPE ; then
mkfifo $PIPE
$root/bin/set-pipe-size $PIPE 1048576
# $root/bin/set-pipe-size $PIPE 1048576 # hangs on writer to connect ..
fi
# kill command and all children
......@@ -45,7 +45,7 @@ else
gzip -c $PIPE >> $logdir/crude-`date +%T`.gz &
fi
if ! pgrep -u $USER -f "bin/crude-ana-gz " > /dev/null; then
if ! pgrep -u $USER -f "bin/crude-ana-gz" > /dev/null; then
# make sure that qstream-gapa-ana deos not run already
if ! pgrep -u $USER -f "bin/qstream-gap-ana " > /dev/null; then
$root/bin/crude-ana-gz &
......
......@@ -17,7 +17,7 @@ my $usage="Usage\n$0 --cmd <command> --cmd ...
-v - print summary stats at end
$0 index output-directory [data-file]..\n
";
GetOptions('cmd=s'=> \@opt_cmd, 'pipe_size=s'=>\$pipe_size, 'debug' => \$opt_debug, 'v'=>\$opt_v, 'h'=>\$opt_h) or die "$usage : $!" ;
GetOptions('cmd=s'=> \@opt_cmd, 'pipe_size=s'=>\$pipe_size, 'debug=s' => \$opt_debug, 'v'=>\$opt_v, 'h'=>\$opt_h) or die "$usage : $!" ;
die $usage if $opt_h;
......@@ -40,13 +40,12 @@ if ( $#opt_cmd >= 0 ){ # externally spec'd commands
my $ext=`date +%T`;
chomp $ext;
@cmds = (
"nice perl $bin/qstream-gap-ana -v -minloss 5 -head -win 50 -jitter 600 -addresses $root/etc/mp-address.txt -rtp 5" .
"perl $bin/qstream-gap-ana -v -minloss 5 -head -win 50 -jitter 600 -addresses $root/etc/mp-address.txt -rtp 5" .
" -json $lager/gap-ana-$ext.json" .
" >> $lager/gap-ana-$ext.txt 2>> $lager/gap-log-$ext.txt",
"gzip >> $lager/crude-$ext.gz" );
# only done at central site - mostly for debug purposes :
# "nice perl $bin/qstream-gap-list >> $lager/gap-list-$ext.txt";
$opt_v=1;
}
$SIG{INT} = 'final_summary';
......@@ -57,6 +56,9 @@ my @fh=();
my @blocked=();
my $n_slept=();
my $t_slept=();
my @would_block=();
my @partial_write=();
my @normal_write=();
foreach $i ( 0.. $#cmds ){
......@@ -68,11 +70,15 @@ foreach $i ( 0.. $#cmds ){
}
while(<>){
$nbytes+=length $_;
my $diff= $nbytes - tell STDIN;
printf "diff %d " if $diff !=0;
foreach $i ( 0.. $#cmds ){
push ( @{$queues[$i]}, $_);
$qmax[$i]=$#{$queues[$i]} if ! $qmax[$i] || $qmax[$i] < $#{$queues[$i]};
while ( $#{$queues[$i]} >= 0 ){
if ( $blocked[$i] > 0 ){
if ( $blocked[$i] < 0 ){ # never
printf "blocked index %d for %d\n", $i, $blocked[$i] if $opt_debug && $blocked[$i] > 1;
usleep(100 * $blocked[$i]); # additive increase in sleep_time
$n_slept[$i] ++;
......@@ -82,15 +88,16 @@ while(<>){
my $rv = syswrite( $fh[$i], $line, length $line);
if (!defined($rv) && $!{EAGAIN}) { # would block
unshift @{$queues[$i]}, $line;
$would_block++;
$would_block[$i]++;
$blocked[$i]++;
break;
} elsif ($rv != length $buffer) { # incomplete write
} elsif ($rv != length $line) { # incomplete write
unshift @{$queues[$i]}, substr( $line, $rv );
$partial_write++;
$partial_write[$i]++;
$blocked[$i]++;
break;
} else { # successfully wrote
$normal_write++;
$normal_write[$i]++;
$blocked[$i]=0;
}
}
......@@ -104,10 +111,13 @@ exit (0);
sub summary{
printf "summary: would_block %d partial_write %d normal_write %d \n",
$would_block, $partial_write, $normal_write ;
foreach $i(0..$#cmds){
printf "%8d %8dms %s\n", $n_slept[$i], $t_slept[$id], $cmds[$i];
if ( $opt_v){
foreach $i(0..$#cmds){
printf "summary:\n";
printf "%15s %15s %15s %15s %15s %15s\n", qw /would_block partial_write normal_write n_slept t_slept qmax/;
printf "%15d %15d %15d %15d %15d %15d %s\n", $would_block[$i], $partial_write[$i], $normal_write[$i],
$n_slept[$i], $t_slept[$id], $qmax[$i], $cmds[$i];
}
}
}
......
......@@ -10,12 +10,16 @@ fi
if pgrep -u $USER -f "bin/crude " >/dev/null; then
pkill -u $USER -f "bin/crude " || echo crude kill failed
fi
if pgrep -u $USER -f "bin/crude-ana-gz " >/dev/null; then
pkill -u $USER -f "bin/crude-ana-gz "|| echo crude-ana-gz kill failed
if pgrep -u $USER -f "bin/crude-ana-gz" >/dev/null; then
pkill -u $USER -f "bin/crude-ana-gz"|| echo crude-ana-gz kill failed
fi
if pgrep -u $USER -f "bin/qstream-gap-ana " >/dev/null; then
pkill -u $USER -f "bin/qstream-gap-ana " # to be sure if it does not die by the above
if pgrep -u $USER -f "bin/qstream-gap-ana" >/dev/null; then
pkill -u $USER -f "bin/qstream-gap-ana" # to be sure if it does not die by the above
fi
if pgrep -u $USER -f 'tail.*crude-.*gz' >/dev/null; then
pkill -u $USER -f 'tail.*crude-.*gz'
fi
### kill yesterdays solutions
if pgrep -u $USER -f "bin/crude-spread-queue " >/dev/null; then
pkill -u $USER -f "bin/crude-spread-queue "|| echo crude-spread-queue kill failed
......
#!/usr/bin/perl
# usage: name-of-open-fifo size-in-bytes
# will hang on writer to connect to pipe
# modeled after : http://unix.stackexchange.com/a/353761/119298
use strict;
use Fcntl;
# debian 8++ does not have Fcntl::F_GETPIPE_SZ
use constant F_GETPIPE_SZ => 1024+7;
use constant F_SETPIPE_SZ => 1024+8;
my $fifo = shift @ARGV or die "usage: fifo size";
my $size = shift @ARGV or die "usage: fifo size";
my $verbose = shift @ARGV or 0;
open(FD, "<", $fifo) or die "### set-pipe-size cannot open $fifo : $!";
printf "old size %d\n", fcntl(\*FD, Fcntl::F_GETPIPE_SZ, 0) if $verbose > 0 ;
printf "old size %d\n", fcntl(\*FD, F_GETPIPE_SZ, 0) if $verbose > 0 ;
my $new=5;
my $new = fcntl(\*FD, Fcntl::F_SETPIPE_SZ, int($size));
my $new = fcntl(\*FD, F_SETPIPE_SZ, int($size));
printf "new size %d\n",fcntl(\*FD, Fcntl::F_GETPIPE_SZ, 0) if $verbose > 0 ;
printf "new size %d\n",fcntl(\*FD, F_GETPIPE_SZ, 0) if $verbose > 0 ;
die "### set-pipe-size for $fifo failed: new size $new" if $new<$size;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment