Perlbal - Perlbal and Rails

This is Interesting: Free IT Magazines  
Home > Archive > Perlbal > March 2007 > Perlbal and Rails





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Perlbal and Rails
Philip Murray

2007-02-21, 7:11 pm

Hi,

I'm looking at trying Perlbal to load-balance a cluster of Mongrel
processes running a Rails app over several machines. I'm currently
using Apache2.2 and mod_proxy_balance, but hope that Perlbal can do a
better job.

The only feature Perlbal seems to be missing that I'd need to make it
a drop-in replacement is best illustrated by the Apache config snippet:

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel-nz%{REQUEST_URI} [P,QSA,L]

Basically, if the file exists locally serve it. If it doesn't exist
locally, proxy it to one of the backends.

In a sense this is kind of combining the web_server role with the
reverse_proxy role, is it curently possible to do this with Perlbal?



Cheers
Philip Murray


Cal Henderson

2007-02-22, 1:11 am

Philip Murray <pmurray@nevada.net.nz> wrote:
: Basically, if the file exists locally serve it. If it doesn't exist
: locally, proxy it to one of the backends.
:
: In a sense this is kind of combining the web_server role with the
: reverse_proxy role, is it curently possible to do this with Perlbal?


you can fairly easily do this by adding a hook to a web server backend
(via a custom plugin) to check for 404's (the hook is called
static_get_poststat_file_missing) and then move the request over to a
proxy backend.

something like (untested):

------------------------------------------------------------------

package Perlbal::Plugin::Thinger;

use strict;
use warnings;

sub register {
my ($class, $svc) = @_;

$svc->register_hook('MyHook', 'static_get_poststat_file_missing', sub
{

my ($cb) = @_;

my $new_svc = Perlbal->service('my_proxy_service');

$new_svc->adopt_base_client($cb);

return 1;
});

return 1;
}


sub unregister {
my ($class, $svc) = @_;

$svc->unregister_hooks('MyHook');

return 1;
}

------------------------------------------------------------------


--cal


Brad Fitzpatrick

2007-03-05, 7:12 pm

If somebody could write this plugin, I'd love to include it by default, as
I think it's something a lot of people want....

- Brad


On Wed, 21 Feb 2007, Cal Henderson wrote:

> Philip Murray <pmurray@nevada.net.nz> wrote:
> : Basically, if the file exists locally serve it. If it doesn't exist
> : locally, proxy it to one of the backends.
> :
> : In a sense this is kind of combining the web_server role with the
> : reverse_proxy role, is it curently possible to do this with Perlbal?
>
>
> you can fairly easily do this by adding a hook to a web server backend
> (via a custom plugin) to check for 404's (the hook is called
> static_get_poststat_file_missing) and then move the request over to a
> proxy backend.
>
> something like (untested):
>
> ------------------------------------------------------------------
>
> package Perlbal::Plugin::Thinger;
>
> use strict;
> use warnings;
>
> sub register {
> my ($class, $svc) = @_;
>
> $svc->register_hook('MyHook', 'static_get_poststat_file_missing', sub
> {
>
> my ($cb) = @_;
>
> my $new_svc = Perlbal->service('my_proxy_service');
>
> $new_svc->adopt_base_client($cb);
>
> return 1;
> });
>
> return 1;
> }
>
>
> sub unregister {
> my ($class, $svc) = @_;
>
> $svc->unregister_hooks('MyHook');
>
> return 1;
> }
>
> ------------------------------------------------------------------
>
>
> --cal
>
>


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com