Commit 0331f421 authored by Olav Kvittem's avatar Olav Kvittem
Browse files

set pipe_buffer_size (512kb)

parent f328ae42
......@@ -9,12 +9,14 @@ use FileHandle;
use File::Basename;
use Getopt::Long;
my $pipe_size=2**19; # 0.5MB
my (@opt_cmd, $opt_v, $opt_h);
my $usage="Usage\n$0 --cmd <command> --cmd ...
-pipe_size - buffering output to commands ($pipe_size)
-v - print summary stats at end
$0 index output-directory [data-file]..\n
";
GetOptions('cmd=s'=> \@opt_cmd, 'v'=>\$opt_v, 'h'=>\$opt_h) or die "$usage : $!" ;
GetOptions('cmd=s'=> \@opt_cmd, 'pipe_size=s'=>\$pipe_size, 'v'=>\$opt_v, 'h'=>\$opt_h) or die "$usage : $!" ;
die $usage if $opt_h;
......@@ -30,7 +32,6 @@ if ( $#opt_cmd >= 0 ){ # externally spec'd commands
my $index=shift;
my $lager=shift;
my $pipe_size=2**20; # 1MB
my $bin = dirname(__FILE__);
my $root = "$bin/..";
......@@ -87,6 +88,7 @@ sub writer{
my ($cmd, $q)=@_;
my $n=0;
my $fh = IO::File->new();
set_pipe_size( $fh, $pipe_size);
$fh->open( "|$cmd" or die "Could not open cmd : $! :\n$cmd");
# $0=$cmd; - changes name of parent process in ps/pkill so don't use
......@@ -117,3 +119,18 @@ sub gather_results(){
}
print @lines if $opt_v;
}
sub set_pipe_size{
my $fh = shift;
my $pipe_size = shift;
if ($debug and -p $fh ) {
printf "fh %d is pipe\n", $fh;
printf "pipe size was %d\n", fcntl($fh, Fcntl::F_GETPIPE_SZ, 0);
}
my $new = fcntl( $fh, Fcntl::F_SETPIPE_SZ, int($pipe_size))
|| die "### could not set pipe size $pipe_size for $cmd: $!\n";
warn sprintf "### set-pipe-size for $cmd failed: new size $new, got: %d",
fcntl($fh, Fcntl::F_GETPIPE_SZ, 0)
if $new < $pipe_size;
return $fh;
}
......@@ -258,7 +258,8 @@ sub handle_signals(){
make_summary();
# while ( $#ARGV >= 0) { printf "Got signal %s\n", shift @ARGV }
# die "Caught a signal $!";
exit(0);
close JSON if $opt_json;
exit(1);
}
......
Markdown is supported
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