LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Articles > Jeremy's Magazine Articles
User Name
Password

Notices


By jeremy at 2007-02-05 17:05
Splice Traffic with Perlbal
Written by Jeremy Garcia
Linux Magazine

The last few "Tech Support" columns have demonstrated how to optimize your PHP installation for maximum performance. From memcached, to decreased database load, from APC for opcode caching, to custom compilation tips, you have many options to boost the throughput of your Web server. At some point, though, you may find that your site outgrows even the best optimizations. When that happens, you'll need to scale your application in other ways. This article focuses on scaling your Web servers by spreading the load to multiple machines.

Growing Wide

If you’re a Web 2.0 startup flush with venture capital cash, you probably can afford a proper load balancer from the likes of Cisco or F5 to help multiplex Web traffic among many servers. However, if you're a Linux community site, purchasing expensive hardware is likely not a viable option.

An easy multiplexing solution is round-robin DNS, but as with most easy solutions, it's one that offers little flexibility and has many limitations. Depending on your application behavior, you may be able to utilize Squid as a caching, reverse proxy. But what if your setup isn't cache-friendly?

Enter Perlbal, a Perl-based, reverse proxy load balancer written by Danga (who also wrote memcached). Available for download from http://www.danga.com/dist/Perlbal/, Perlbal is released under the same license as Perl.

Perlbal is a single-threaded, event-based server that enables HTTP load balancing, Web serving, and a mix of the two. Perlbal maintains a pool of backend connections and does intelligent load balancing based on what backend connections are free for a new request.

You can install Perlbal and any missing dependencies via the Perl CPAN.

Code:
$ sudo perl -MCPAN -e shell
cpan> install Perlbal
Or, if you'd prefer not to use CPAN, you can download the Perlbal source and build and install the software via the standard procedure for Perl modules:

Code:
$ perl Makefile.PL && make && make test
$ sudo make install
(If you choose not to use CPAN, you'll also need to manually install the following Perl modules:
BSD::Resource, Danga::Socket, and Sys::Syscall
Optionally, you can also install:
Perlbal::XS::HTTPHeaders, IO::Socket::SSL, and IO::AIO

A Balancing Act

With Perlbal now installed as /usr/bin/perlbal, it's time to move on to configuration. Let's look at how to enable HTTP load balancing.

By default, Perlbal looks for the configuration file /etc/perlbal/perlbal.conf. Here’s a sample:

Code:
CREATE POOL my_apaches
  POOL my_apaches ADD 10.0.0.10:8080
  POOL my_apaches ADD 10.0.0.11:8080

CREATE SERVICE balancer
  SET listen          = 0.0.0.0:80
  SET role            = reverse_proxy
  SET pool            = my_apaches
  SET persist_client  = on
  SET persist_backend = on
  SET verify_backend  = on
ENABLE balancer
This simple configuration listens on port 80 of the host machine and forwards all requests to port 8080 on 10.0.0.10 and 10.0.0.11. (Remember, since Perlbal does intelligent load balancing, you won't need any "weighting" numbers that you may have seen in other solutions.)

Perlbal also has built-in statistics and monitoring to monitor CPU usage, uptime, total requests, and a variety of other useful metrics. To enable statistic collection and monitoring, add the following to your configuration file:

Code:
CREATE SERVICE mgmt
  SET role   = management
  SET listen = 127.0.0.1:60000
ENABLE mgmt
You can now start Perlbal as a background service:

Code:
$ sudo /usr/bin/perlbal --daemon
Perlbal is extensible: you can create per-service and global plug-ins that can override many parts of request handling and behavior. By writing a custom plug-in, you can adapt Perlbal to your exact environment.

More Power!

Perlbal can handle much more complex setups. Perlbal also supports SSL and virtual hosts, allows internal redirection to a file or URL, has configurable header management, and a variety of other advanced features and options. Start by browsing the docs and config directories contained in the download.

The docs directory gives a comprehensive list of supported configuration directives, shows you how to reconfigure Perlbal on-the-fly, introduces the concept of "reproxying," and even provides information on hacking the Perlbal code and writing custom plug-ins. The config directory includes sample configuration files for everything from SSL support, to a fully-dynamic virtual host setup.

If you’re on a tight budget and don’t have a cache-friendly application, Perlbal may be the ideal solution for you to conquer your Web traffic.


  



All times are GMT -5. The time now is 05:27 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration