Announcing Apache::BalancerManager

At work I use Apache as it’s the best thing out there for perl on windows. One of the features of Apache when you are using it as a load balancer is it’s UI for controlling the Balancer Manager. One of my coworkers remarked that it would be nice to have an API for that so that when we restart workers we could tell the balancer manager first so that the worker would not get dispatched to until it finished restarting. Well OK!

Apache::BalancerManager

Apache::BalancerManager gives you an easy to use, object-oriented interface for interacting with Apache’s Balancer Manager. Here’s a real example from our server code:

use Apache::BalancerManager;
my $m = Apache::BalancerManager->new(
   url => 'http://127.0.0.1/balancer-manager',
);

sub restart_service {
   my $service = sprintf 'LynxWeb%02i', $_[0];
   my $member = $m->get_member_by_location(
      sprintf 'http://127.0.0.1:50%02i', $_[0]
   );

   $member->disable;
   $member->update;
   system(qw(net stop $service));

   system(qw(net start $service));
   $member->enable;
   $member->update;
}

The module automatically finds all the available members and creates objects to wrap each of them. There are a number of methods for each, for example one might modify load_factor if a server is under too much load. Ultimately though, I’m pretty sure the use case above is the best one, as the balancer manager is limited in what it can do. (Members can’t be added at runtime, for example.)

Anyway, this makes me a little bit less afraid to roll out updates to our live site, so I figured others might appreciate it too.

Caveat: I’ve only tested it with Apache 2.2. It may be broken on 2.4. Patches are welcome!

Enjoy!

Posted Fri, Jan 11, 2013

If you're interested in being notified when new posts are published, you can subscribe here; you'll get an email once a week at the most.