Configurable Socket Timeout

Justin Huff jjhuff at mspin.net
Wed Jun 27 18:05:40 UTC 2007


Here is a quick patch to allow the socket time out to be configured on a 
per-service basis.

Disclaimer: we aren't (yet) running this in production.

--Justin
-------------- next part --------------
Index: lib/Perlbal/ClientHTTPBase.pm
===================================================================
--- lib/Perlbal/ClientHTTPBase.pm	(revision 682)
+++ lib/Perlbal/ClientHTTPBase.pm	(working copy)
@@ -764,8 +764,10 @@
     return $self->send_response(500, $msg);
 }
 
-# FIXME: let this be configurable?
-sub max_idle_time { 30; }
+sub max_idle_time {
+    my Perlbal::ClientHTTPBase $self = shift;
+    return $self->{service}->{max_idle_time};
+}
 
 sub event_err {  my $self = shift; $self->close('error'); }
 sub event_hup {  my $self = shift; $self->close('hup'); }
Index: lib/Perlbal/Socket.pm
===================================================================
--- lib/Perlbal/Socket.pm	(revision 682)
+++ lib/Perlbal/Socket.pm	(working copy)
@@ -131,18 +131,13 @@
 
     my $now = time;
 
-    my %max_age;  # classname -> max age (0 means forever)
     my @to_close;
     while (my $k = each %$sf) {
         my Perlbal::Socket $v = $sf->{$k};
-        my $ref = ref $v;
-        unless (defined $max_age{$ref}) {
-            # eval because not all Danga::Socket connections in Perlbal
-            # must be Perlbal::Socket-derived
-            $max_age{$ref} = eval { $ref->max_idle_time } || 0;
-        }
-        next unless $max_age{$ref};
-        if ($v->{alive_time} < $now - $max_age{$ref}) {
+        my $max_age = eval { $v->max_idle_time } || 0;
+        next unless $max_age;
+
+        if ($v->{alive_time} < $now - $max_age) {
             push @to_close, $v;
         }
     }
Index: lib/Perlbal/Service.pm
===================================================================
--- lib/Perlbal/Service.pm	(revision 682)
+++ lib/Perlbal/Service.pm	(working copy)
@@ -44,6 +44,7 @@
             'connect_ahead',           # scalar: number of spare backends to connect to in advance all the time
             'buffer_size', # int: specifies how much data a ClientProxy object should buffer from a backend
             'buffer_size_reproxy_url', # int: same as above but for backends that are reproxying for us
+            'max_idle_time', #int, connection socket idle time (seconds)
             'queue_relief_size', # int; number of outstanding standard priority
                                  # connections to activate pressure relief at
             'queue_relief_chance', # int:0-100; % chance to take a standard priority
@@ -205,6 +206,12 @@
         check_role => "reverse_proxy",
     },
 
+    'max_idle_time' => {
+        default => 30,
+        check_type => "int",
+        check_role => "*",
+    },
+
     'queue_relief_size' => {
         default => 0,
         check_type => "int",


More information about the perlbal mailing list