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:
23
examples/consumer.pl
Executable file
23
examples/consumer.pl
Executable 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
27
examples/http_publisher.pl
Executable 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;
|
||||
}
|
||||
Reference in New Issue
Block a user