No Description

avidmq-prod.pl 1.2KB

    #!/usr/bin/perl -w use strict; use warnings; use FindBin; use lib $FindBin::Bin."/../lib"; use AvidMQ::Client; use Getopt::Long; my $config=$FindBin::Bin."/../etc/avidmq-prod.conf"; my $queue="/numbers/random/"; my $node=qx{hostname}; chomp $node; GetOptions( "configfile=s" => \$config, ); our $statstime=time()+10; our $inittime=time(); our $count=0; our $avg=0; our $tot=0; AvidMQ::Client->new( configfile => $config, Idle => \&generate_random, )->run(); sub generate_random { my $avidmq=shift; my $number=rand(); our ($statstime,$inittime,$count,$avg,$tot); $avg=($avg*$count+$number)/++$count; $tot+=$number; if (time() > $statstime) { my $tottime=time()-$inittime; my $avgsec=$count/$tottime; print STDERR <<EOS; Runned for: $tottime [since $inittime] Generated Numbers: $count [$avgsec por sec] Avg number: $avg Sum of all numbers: $tot EOS $statstime=time()+10; } $avidmq->publish($queue,{node=>$node, number=>$number}); if ($count>=100000) { my $tottime=time()-$inittime; my $avgsec=$count/$tottime; print STDERR <<EOS; Runned for: $tottime [since $inittime] Generated Numbers: $count [$avgsec por sec] Avg number: $avg Sum of all numbers: $tot EOS $statstime=time()+10; exit 0; } }