The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Apache2::Mogile::Dispatch - An Apache2 MogileFS Dispatcher

SYNOPSIS

Quickly and easily use MogileFS + Perlbal instead of Apache for static ( or semi-static SSI ) file serving.

  # -- httpd.conf
  MogReproxyToken old_web
  MogDirector Socklabs::MogileDirector
  MogDomain socklabs
  <MogTrackers>
    mog1 192.168.100.3:1325
    mog2 192.168.100.4:1325
  </MogTrackers>
  <MogMemcaches>
    memcache1 192.168.100.3:1425
    memcache2 192.168.100.4:1425
  </MogMemcaches>

  PerlMapToStorageHandler Apache2::Const::OK
  SetOutputFilter INCLUDES
  <LocationMatch "^/">
      SetHandler modperl
      PerlHandler Apache2::Mogile::Dispatch
  </LocationMatch>

DESCRIPTION

Apache 2.x is an excellent platform for serving content, namely dynamic content. Serving static content can become a gruesome task as your content bank becomes bigger and more diverse. Thankfully we have distributed file systems like MogileFS to easily distribute content efficiently while having good and controllable redundancy.

Because really, who doesn't want redundancy?

This module also makes it easy* to migrate to MogileFS by calling a 'director' with a few options and having it return a set of rules for Apache2::Mogile::Dispatcher to follow. Currently the rules are based on the hostname of the requested URI but could easily be modified to be based on location specific rules.

To speed things up as much as possible this module makes use of Cache::Memcached to cache as much of the decision information as possible.

* Nothing is ever easy.

CONFIGURATION

MogAlways

Don't use the director, simply use mogile or static.

  MogAlways mogile # Always use mogile
  MogAlways static # Always use static

Don't bother checking with the director -- Always try mogile.

MogReproxyToken

If a reproxy token is set and a given uri/file is not to be handled through mogile then it will issue a 'X-REPROXY-SERVICE' => TOKEN_XYZ instead of reproxying the url through one of the static servers.

Note that when this option is set the static servers directive is completely ignored.

MogDirector

The MogDirector option allows the user to set a class that handles the director functionality. Please see the example director for more information on what is expected and required.

MogDomain

This option is passed on to mogile object creation.

MogTrackers

The MogTrackers directive sets the MogileFS trackers to query.

  <MogTrackers>
    mog1 192.168.100.3:1325
    mog2 192.168.100.4:1325
    mog3 localhost:1325
    mog4 localhost:1326
    ...
  </MogTrackers>

Note that the first column indicating node names really doesn't mean or do anything.

MogMemcaches

Much like MogTrackers, this option sets the Memcache servers to query. If this option is not set than memcache will not be used. It is very strongly recommended that memcache be used.

  <MogMemcaches>
    memcache1 192.168.100.3:1425
    memcache2 192.168.100.4:1425
    memcache2 localhost:1425
    ...
  </MogMemcaches>

Note that the first column indicating node names really doesn't mean or do anything.

MogStaticServers

Much like MogTrackers and MogMemcaches, this option sets the static servers to reproxy to if a given file/uri is not handled by mogile. Note that this is completely useless if mogile handles everything, via setting MogAlways to 'mogile'.

  <MogStaticServers>
    web1 http://192.168.100.3:80
    web2 http://192.168.100.4:80
    web3 http://localhost:80
    ...
  </MogStaticServers>

If Apache2::Mogile::Dispatch handles the uri '/socklabs/index.html' and the director says that it is not infact to be handled by mogile, it will attempt to content the static servers to request the file. In this case it starts at the top and works its way through the list using the first one that returns 200 - OK. If none of them return then a 404 - Not Found is returned.

Note that the format for the reproxy is very simple:

  <static server x><uri>

handler

This function is the base handler. It does all of the work.

get_mogile_object

This function returns a mogile object used to query the mogile trackers.

get_working_path

This function attemps find a working url from a passed list of urls using HEAD requests. It returns the first good one that it finds.

MISC

MogMemcachesEND

MogStaticServersEND

MogTrackersEND

AUTHOR

Nick Gerakines, <nick at socklabs.com>

BUGS

Please report any bugs or feature requests to bug-apache2-mogile-dispatch at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Apache2-Mogile-Dispatch. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

CAVEATS

When supplied with a list of mogile or static servers it will attempt to make a HEAD request to determine if the server can serve the file or not.

TODO

Allow a header or url argument check to force mogile/static use.

Better handling directories

Add fallback support -- When servering files it should fallback to either mogile or static when it can't find what it wants.

Add more tests for per-directory configuration

Add more tests for mogile up/down situation

Add default Director class that can be subclassed

Add Apache2::Mogile::Dispatch::Cookbook with more usage examples and tips on how to get the most out of perlbal + mogile + Apache2::Mogile::Dispatch.

SUPPORT

You can find documentation for this module with the perldoc command.

  perldoc Apache2::Mogile::Dispatch

You can also look for information at:

ACKNOWLEDGEMENTS

Mark Smith Brad Fitzpatrick Brad Wittiker

COPYRIGHT & LICENSE

Copyright 2006 Nick Gerakines, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.