Adding some config options

Adam Jacob adam at hjksolutions.com
Fri May 11 23:26:26 UTC 2007


Attached is a patch that adds two new config options:

1. max_idle_time

This sets the max_idle_time in the ClientHTTPBase class. We were running into
a situation where the default (30 seconds) wasn't quite long enough, causing
the ClientProxy to close the connections. It had a "FixMe:" above it anyway,
asking for a config option... so here it is. 

I had some trouble seeing how to get the value of the configuration option out
of the Service object, due to the Perlbal::Socket's _do_cleanup method calling
the sub from the class, not an object.

I worked around it by setting up an "our $MaxIdleTime = 30;" in
ClientHTTPBase, which gets set to the configuration value when an object is
instantiated.

If you let me know a better way, I'll be happy to fix it up.

2. verify_backend_path

One of our backend applications was unable to answer an OPTIONS request for '*'.  This variable allows the path of the OPTIONS request to be configurable.  It defaults to the current value of '*'.  

Thanks for a great piece of software,

Adam

-- 
HJK Solutions - We Launch Startups - http://www.hjksolutions.com
Adam Jacob, Senior Partner
T: (206) 508-4759 E: adam at hjksolutions.com
-------------- next part --------------
Index: lib/Perlbal/ClientHTTPBase.pm
===================================================================
--- lib/Perlbal/ClientHTTPBase.pm	(revision 673)
+++ lib/Perlbal/ClientHTTPBase.pm	(working copy)
@@ -62,6 +62,8 @@
                     zip   application/zip
 )};
 
+our $MaxIdleTime = 30;
+
 # ClientHTTPBase
 sub new {
     my ($class, $service, $sock, $selector_svc) = @_;
@@ -76,7 +78,8 @@
     $self->{requests}        = 0;
     $self->{scratch}         = {};
     $self->{selector_svc}    = $selector_svc;
-
+    $MaxIdleTime = $self->{service}->{max_idle_time};
+    
     $self->state('reading_headers');
 
     bless $self, ref $class || $class;
@@ -764,8 +767,9 @@
     return $self->send_response(500, $msg);
 }
 
-# FIXME: let this be configurable?
-sub max_idle_time { 30; }
+sub max_idle_time { 
+    $MaxIdleTime;
+}
 
 sub event_err {  my $self = shift; $self->close('error'); }
 sub event_hup {  my $self = shift; $self->close('hup'); }
Index: lib/Perlbal/BackendHTTP.pm
===================================================================
--- lib/Perlbal/BackendHTTP.pm	(revision 673)
+++ lib/Perlbal/BackendHTTP.pm	(working copy)
@@ -343,7 +343,7 @@
             !$self->{has_attention} && !defined $NoVerify{$self->{ipport}}) {
 
             # the backend should be able to answer this incredibly quickly.
-            $self->write("OPTIONS * HTTP/1.0\r\nConnection: keep-alive\r\n\r\n");
+            $self->write("OPTIONS " . $self->{service}->{verify_backend_path} . " HTTP/1.0\r\nConnection: keep-alive\r\n\r\n");
             $self->watch_read(1);
             $self->{waiting_options} = 1;
             $self->{content_length_remain} = undef;
Index: lib/Perlbal/Service.pm
===================================================================
--- lib/Perlbal/Service.pm	(revision 673)
+++ lib/Perlbal/Service.pm	(working copy)
@@ -40,6 +40,7 @@
             'persist_client',  # bool: persistent connections for clients
             'persist_backend', # bool: persistent connections for backends
             'verify_backend',  # bool: get attention of backend before giving it clients (using OPTIONS)
+            'verify_backend_path', # Path for the OPTIONS check
             'max_backend_uses',  # max requests to send per kept-alive backend (default 0 = unlimited)
             '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
@@ -93,6 +94,7 @@
             'enable_error_retries',  # bool: whether we should retry requests after errors
             'error_retry_schedule',  # string of comma-separated seconds (full or partial) to delay between retries
             'latency',               # int: milliseconds of latency to add to request
+            'max_idle_time',      # Time in seconds before timing out idle Proxy or Backend connections.
 
             # stats:
             '_stat_requests',       # total requests to this service
@@ -170,6 +172,12 @@
         check_type => "bool",
         check_role => "reverse_proxy",
     },
+    
+    'verify_backend_path' => {
+        des => "What path the OPTIONS request sent by verify_backend should use.  Default is '*'.",
+        default => '*',
+        check_role => "reverse_proxy",
+    },
 
     'max_backend_uses' => {
         check_role => "reverse_proxy",
@@ -464,6 +472,13 @@
         check_role => "selector",
         check_type => "int",
     },
+    
+    'max_idle_time' => {
+        des => "Maximum time (in seconds) before expiring Client Proxy and Backend HTTP connections.",
+        default => 30,
+        check_type => "int",
+        check_role => "*"
+    },
 
     'enable_ssl' => {
         des => "Enable SSL to the client.",


More information about the perlbal mailing list