diff --git a/Changes b/Changes index 09b5406..ddf4112 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ 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. - Assign a version number to all modules in package. 1.21 Sat 30 May 23:40:54 BST 2020 diff --git a/dist.ini b/dist.ini index e9b4109..297915f 100644 --- a/dist.ini +++ b/dist.ini @@ -17,6 +17,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 81a3ebd..3488045 100644 --- a/lib/AnyEvent/RabbitMQ.pm +++ b/lib/AnyEvent/RabbitMQ.pm @@ -173,6 +173,7 @@ sub connect { peername => $args{host}, $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,); @@ -690,6 +691,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)),