A simple consumer and a HTTP-based publisher, useful for simple benchmarks

Signed-off-by: Pedro Melo <melo@simplicidade.org>
This commit is contained in:
Pedro Melo
2014-07-20 13:48:16 +01:00
parent 3271c74a0b
commit 306f8e4864
2 changed files with 50 additions and 0 deletions

23
examples/consumer.pl Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env perl
use strict;
use warnings;
use lib 'lib';
use AnyEvent;
use AnyEvent::NSQ::Reader;
my ($topic, $channel) = @ARGV;
die "Usage: consumer.pl topic channel\n" unless $topic and $channel;
my $c = 1;
my $r = AnyEvent::NSQ::Reader->new(
topic => $topic,
channel => $channel,
nsqd_tcp_addresses => '127.0.0.1',
client_id => "${channel}_consumer/pid_$$",
# message_cb => sub {print STDERR "$c: $_[1]{message}\n";$c++; return}, ## return undef => mark_as_done_msg()
message_cb => sub {return}, ## return undef => mark_as_done_msg()
);
AE::cv->recv;

27
examples/http_publisher.pl Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env perl
use strict;
use warnings;
use HTTP::Tiny;
my ($topic, $factor, $limit) = @ARGV;
die "Usage: http_publisher.pl topic [msgs_per_call]\n" unless $topic;
$factor = 1 unless $factor;
my $ua = HTTP::Tiny->new(keep_alive => 1);
my $url = "http://127.0.0.1:4151/mput?topic=$topic";
my $c = 1;
my @factors = (1 .. $factor);
my $body;
while (1) {
$body = join("\n", map {"Request $c.$_"} @factors);
my $res = $ua->post($url, { content => $body });
use DDP;
p($res) unless $res->{success};
$c++;
last if defined($limit) and --$limit == 0;
}