From 12f85bf55f342bdecf4ec3024e02302b0163a331 Mon Sep 17 00:00:00 2001 From: Dave Lambley Date: Mon, 8 Jun 2020 21:09:42 +0100 Subject: [PATCH] RT#119793 Add "nodelay" option https://github.com/cooldaemon/AnyEvent-RabbitMQ/pull/5/commits/e888205306fb49167c0dc9aa4e4dc940cc922d25 https://rt.cpan.org/Ticket/Display.html?id=119793 --- Changes | 4 ++++ dist.ini | 2 ++ lib/AnyEvent/RabbitMQ.pm | 2 ++ xt/04_anyevent.t | 29 +++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/Changes b/Changes index 02817c6..faac688 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Perl extension AnyEvent::RabbitMQ + - Add "nodelay" option to disable Nagle's algorithm. + https://rt.cpan.org/Ticket/Display.html?id=119793 + Also José Micó's e888205306fb49167c0dc9aa4e4dc940cc922d25. + 1.21 Sat 30 May 23:40:54 BST 2020 - No changes. diff --git a/dist.ini b/dist.ini index 5e6d7dc..2d41b04 100644 --- a/dist.ini +++ b/dist.ini @@ -16,6 +16,8 @@ x_contributors = Masahito Ikuta x_contributors = Rod Taylor x_contributors = Carl Hörberg x_contributors = Julio Polo +x_contributors = A.J. Ragusa +x_contributors = José Micó [InstallGuide] [CPANFile] diff --git a/lib/AnyEvent/RabbitMQ.pm b/lib/AnyEvent/RabbitMQ.pm index af88d0c..2c501b4 100644 --- a/lib/AnyEvent/RabbitMQ.pm +++ b/lib/AnyEvent/RabbitMQ.pm @@ -172,6 +172,7 @@ sub connect { }, $args{tls} ? (tls => 'connect') : (), $args{tls_ctx} ? ( tls_ctx => $args{tls_ctx} ) : (), + $args{nodelay} ? ( nodelay => $args{nodelay} ) : (), ); $self->_read_loop($args{on_close}, $args{on_read_failure}); $self->_start(%args,); @@ -689,6 +690,7 @@ AnyEvent::RabbitMQ - An asynchronous and multi channel Perl AMQP client. tls => 0, # Or 1 if you'd like SSL tls_ctx => $anyevent_tls # or a hash of AnyEvent::TLS options. tune => { heartbeat => 30, channel_max => $whatever, frame_max = $whatever }, + nodelay => 1, # Reduces latency by disabling Nagle's algorithm on_success => sub { my $ar = shift; $ar->open_channel( diff --git a/xt/04_anyevent.t b/xt/04_anyevent.t index 9cc0289..fc7b0e9 100644 --- a/xt/04_anyevent.t +++ b/xt/04_anyevent.t @@ -42,6 +42,35 @@ lives_ok sub { $ar->load_xml_spec() }, 'load xml spec'; +my @nagle = [[], [nodelay => 0], [nodelay => 1]]; + +for my $opt (@nagle) { + my $done = AnyEvent->condvar; + my $z = AnyEvent::RabbitMQ->new(verbose => $conf{verbose}); + $z->connect( + (map {$_ => $conf{$_}} qw(host port user pass vhost)), + timeout => 1, + on_success => sub { + my $ar = shift; + isa_ok($ar, 'AnyEvent::RabbitMQ'); + $done->send; + }, + on_failure => failure_cb($done), + on_return => sub { + my $method_frame = shift->method_frame; + die "return: ", $method_frame->reply_code, $method_frame->reply_text + if $method_frame->reply_code; + }, + on_close => sub { + my $method_frame = shift->method_frame; + Carp::confess "close: ", $method_frame->reply_code, $method_frame->reply_text + if $method_frame->reply_code; + }, + @{ $opt }, + ); + $done->recv; +} + my $done = AnyEvent->condvar; $ar->connect( (map {$_ => $conf{$_}} qw(host port user pass vhost)),