From 306f8e486419105438227720f829c0c7f4b13072 Mon Sep 17 00:00:00 2001 From: Pedro Melo Date: Sun, 20 Jul 2014 13:48:16 +0100 Subject: [PATCH] A simple consumer and a HTTP-based publisher, useful for simple benchmarks Signed-off-by: Pedro Melo --- examples/consumer.pl | 23 +++++++++++++++++++++++ examples/http_publisher.pl | 27 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 examples/consumer.pl create mode 100755 examples/http_publisher.pl diff --git a/examples/consumer.pl b/examples/consumer.pl new file mode 100755 index 0000000..a7726a4 --- /dev/null +++ b/examples/consumer.pl @@ -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; diff --git a/examples/http_publisher.pl b/examples/http_publisher.pl new file mode 100755 index 0000000..d9b0bc3 --- /dev/null +++ b/examples/http_publisher.pl @@ -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; +}