Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
By jeremy at 2007-02-05 17:05
Splice Traffic with Perlbal
Written by Jeremy Garcia
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.
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.
$ 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:
$ 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:
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
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:
CREATE SERVICE mgmt
SET role = management
SET listen = 127.0.0.1:60000
You can now start Perlbal as a background service:
$ 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.
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.