Subject: | UserAgent and keep_alive |
Hi Mike,
Is there any particular reason that ::Simple instantiates a new LWP::UserAgent for every request?
I've been testing a small change that caches UA instance on creation and also sets keep_alive so that we don't have to pay the connection handshake on every request.
Anecdotally, it feels faster, but also `netstat -a | grep TIME_WAIT | wc -l` doesn't go out of control when doing mass message sends etc. Without this patch TIME_WAIT needs to be lowered via OS parameters to not cause a bottleneck.
Subject: | Amazon-SQS-Simple-keep-alive.patch |
diff --git a/perl/local/lib/perl5/Amazon/SQS/Simple/Base.pm b/perl/local/lib/perl5/Amazon/SQS/Simple/Base.pm
index 001871f..60c994f 100755
--- a/perl/local/lib/perl5/Amazon/SQS/Simple/Base.pm
+++ b/perl/local/lib/perl5/Amazon/SQS/Simple/Base.pm
@@ -37,6 +37,7 @@ sub new {
Endpoint => +BASE_ENDPOINT,
SignatureVersion => 2,
Version => $DEFAULT_SQS_VERSION,
+ ua => LWP::UserAgent->new( keep_alive => 6 ),
@_,
};
@@ -67,7 +68,7 @@ sub _dispatch {
my $self = shift;
my $params = shift || {};
my $force_array = shift || [];
- my $ua = LWP::UserAgent->new();
+ my $ua = $self->{ua};
my $url = $self->{Endpoint};
my $response;
my $post_body;