HAProxy -> Mongrel -> Rails

April 24th, 2007

这是一个高性能、高伸缩性的Rails部署方案。有一组性能数据可供参考。

首先接收到HTTP请求的是HAProxy。HAProxy会把请求反向代理给其后的多个Mongrel实例。每个Mongrel实例同一时间只处理一个请求。只要Rails应用本身贯彻无共享架构,就可以直接通过增加服务器和改变HAProxy配置得到线性的性能提升。另外可以用Monit来管理Mongrel实例的开启和关闭,并且在异常状况发生时及时采取措施。这样一来,企业级超复杂所暗含的性能、伸缩性、可管理性等等要求都满足了。

“HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications.”
“Mongrel is a fast HTTP library and server for Ruby that is intended for hosting Ruby web applications of any kind using plain HTTP rather than FastCGI or SCGI.”
“monit is a utility for managing and monitoring, processes, files, directories and devices on a UNIX system.”

(今天下午和George讨论的主题:我们已经听厌了“企业级”这样的大帽子。我们需要做的是弄明白所谓“企业级”究竟代表什么,然后把解决方案拿出来。基本上——如果真的喜欢“企业级”的话——这就是所谓的“企业级Rails”了。)