Perlbal
2010-09-13 09:54:11 阿炯

Perlbal 是一个用 Perl 编写的单线程的事件驱动服务器,可充当 Web 服务器 和 HTTP 负载均衡。Perlbal被使用在 http://www.livejournal.com/

特点
* 快,小,可管理的http web 服务器/代理
* 可以在内部进行转发
* 使用Perl开发
* 单线程,异步,基于事件,使用epoll , kqueue
* 支持Console管理与http远程管理,支持动态配置加载
* 多种模式:web服务器,反向代理,插件
* 支持插件:GIF/PNG互换?

One of the defining things about Perlbal is that almost everything can be configured or reconfigured on the fly without needing to restart the software. A basic configuration file containing a management port enables you to easily perform operations on a running instance of Perlbal.
Here is a basic list of the personalities and features that Perlbal implements at this time.

Role: Web Server
* Listen on a port, share from a directory
* Directory indexing
* Byte range support (clients can resume downloads)
* Can have directory index requests fall back to index file list
o I.e., requests for /foo/ go to /foo/index.html instead
o Multiple index files supported, tries one at a time until it finds one
* Persistent client connections (configurable)
* Almost all1 disk operations are done asynchronously as to not stall the event loop
* Configurable support for storing files (PUT, DELETE support)

Almost. When you enable PUT support, the close() operation is blocking. However, it's generally pretty fast (we've had no problems). Also, directory indexing is a synchronous operation.

Role: Reverse Proxy
* Maintains pool of connected backend connections to reduce turnover
* Gets list of nodes either from asynchronously monitored node file, or from in-server pool objects which you can add/remove nodes from using the management interface.
* Intelligent load balancing based on what backend connections are free for a new request. No unreliable "weighting" numbers required.
* Can verify (using a quick OPTIONS request) that a backend connection is talking to a webserver and not just the kernel's listen queue before sending client requests at it. Lower latency for the client.
* Has a high priority queue for sending requests through to backends quickly
o Uses cookies to determine if a request should go to fast queue (configurable)
o Highpri (high priority) plugin supports making requests high priority by URI or Host
o Can specify a relief level to let low priority requests through to prevent starvation
* Can allow X-Forwarded-For (and similar) headers from client based on client IP
* Configurable header management before sending request to backend
* Internal redirection to file or URL(s)
o Big one for us; a backend can instruct Perlbal to fetch the user's data from a completely separate server and port and URL, 100% transparent to the user
o Can actually give Perlbal a list of URLs to try. Perlbal will find one that's alive. Again, the end user sees no redirects happening.
o Can also redirect to a file, which Perlbal will serve non-blocking. See webserver mode above.
* Persistent client connections (configurable)
* Persistent backend connections (shared by multiple clients; no "backend waste")

Performance
* Event-based using epoll or kqueue to avoid the scalability problems of not-so-modern systems
* HTTP Header processing (optionally) done in C with Perlbal::XS::HTTPHeaders for maximum performance
* 100% asynchronous in all the recommended use cases
* Lightweight
* Great performance "out-of-the-box" (for both small and large sites)

Statistics and Monitoring
The management interface provides extremely detailed and powerful statistics in addition to runtime configuration. For example:

* CPU usage (user, system)
* Total requests served across all services
* Requests service by individual backends
* Perlbal uptime
* All connected sockets (and tons of info about each)
* Outstanding connections to backends
* Backends that have recently failed verification
* Pending backend connections by service
* Total of all socket states by socket type
* Size (in seconds and number of connections) of all queues
* State of reproxy engine (queued requests, outstanding requests, backends)
* Loaded plugins per service

(All statistics are in machine readable form, easy to parse and write scripts that check on the status of Perlbal!)

Plugins (Extensibility)
Perlbal supports the concept of having per-service (and global) plugins that can override many parts of request handling and behavior. We have written custom plugins that send new headers to the backends, promote requests to the fast queue, maintain more detailed statistics, do image header manipulation, and more...

For more information on how plugins work, see the plugins directory in the distribution. They're fairly self-explanatory.

开发语言: Perl
项目主页: http://www.danga.com/perlbal/