문제

I have an application which publishes realtime market data rates. This app is invoked from the command line and has an interactive mode where the user can change various parameters on-the-fly by simply typing the parameter followed by it's corresponding value.

e.g. ur 2000

would dynamically set the update rate to 2000 updates per second.

What I need to do is perform some soak testing for several hours/days and I need to be able to change the update rate to different values at random times. I normally do all my scripting using Perl so I need a way of invoking the script (easy enough) but then having the ability for the script to randomly change any given parameter (like the update rate).

Any ideas or advice would be really appreciated.

Thanks very much

도움이 되었습니까?

해결책

You can open a pipe to your program with open my $fh, "|-", ... and then set the handle to autoflush with

select $fh;
$| = 1;

Now you have a direct line to the standard input of your system under test, as in the demonstration below.

#! /usr/bin/env perl

use strict;
use warnings;
no warnings "exec";

my @system_under_test = ("cat");

open my $fh, "|-", @system_under_test or die "$0: open @system_under_test: $!";

select $fh;
$| = 1;  # autoflush

for (map int rand 2000, 1 .. 10) {
  print $fh "ur $_\n";
  sleep int rand 10;
}

close $fh or warn "$0: close: $!";

For your soak test, you would of course want to sleep for more intervals and iterate the loop many more times.

다른 팁

You can use the command "mkfifo". This creates a named pipe. If you start your program using the fifo as input it should work.

Create a fifo:

mkfifo MyFifo

Start your application with fifo as input:

./yourAppName < MyFifo

Now all you write (e.g. using echo) to "MyFifo" will forwarded to yourAppName's stdin.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top