There are times in life when you find yourself with tuits. Use them while you can, because often what follows is a period when you are without them. I like to hack Perl, and do so as much as I can, but sometimes bills, family, friends' websites, and other nuances get in the way. Work gets in the way too, but I get to hack Perl at work, albeit it doesn't always have the freedom and rewards of working on open source software.
So I had some tuits about a month ago, I started hacking, and then my tuits got re-alloc'd. Tonight I can finally reclaim them, as my free music trading site is finally back online. It runs Slash, and uses Perlbal to deliver http content to hungry clients. I configured Perlbal to proxy requests to the Slash server, and if the request was for a music file, mod_perl passed the request back to Perlbal with a 'x-reproxy-file' header, and Perlbal served the file asynchronously. Today the server was pushing over 40 megabits per second and Perlbal was using about 8% cpu on a PIII 1Ghz Coppermine. Whew.
Time to get to work with the reclaimed tuits on open source. And I'll start with the handler code I used to do this. This works with Perlbal 1.41 and Slash 2.2.6.
package Music;
use Apache::Constants qw( :common );
sub handler {
my $r = shift;
my $file = $r->document_root . $r->uri();
return DECLINED if -d $file;
if (-e $file) {
$r->log_error("Setting X-REPROXY for $file");
$r->err_header_out('X-REPROXY-FILE' => $file);
$r->send_http_header('text/plain');
return OK;
}
if ( ! -e $file ) { return NOT_FOUND };
}
1;
CREATE SERVICE balancers
SET listen = 0.0.0.0:80
SET role = reverse_proxy
SET pool = my_apaches
SET enable_reproxy = true
SET persist_client=off
SET persist_backend=off
SET verify_backend = on
ENABLE balancer
# always good to keep an internal management port open:
CREATE SERVICE mgmt
SET role = management
SET listen = 127.0.0.1:60000
ENABLE mgmt
SetHandler perl-script
PerlHandler Music
Options Includes Indexes Multiviews FollowSymLinks
AllowOverride All
IndexOptions FancyIndexing SuppressHTMLPreamble DescriptionWidth=*
HeaderName /HEADER.html