我刚刚上传了 lighttpd 1.4.12 的第三个预发布版本:
www.lighttpd.net/download/lighttpd-1.4.12-20060724-0947.tar.gz。这个预发布版本应该能在大多数平台上运行,主要针对我们的
mongrel 用户进行了改进。一个小测试表明,即使在单CPU机器上,通过对2个本地实例进行负载均衡,我们也能提高 mongrel 的性能。我在这里将其用于2个 mongrel 实例。
$SERVER["socket"] == ":1446" {
proxy-core.balancer = "round-robin"
proxy-core.protocol = "http"
proxy-core.backends = ( "127.0.0.1:3000", "127.0.0.1:3001" )
}
我的小型 Rails 应用已通过 mongrel 启动
$ RAILS_ENV="production" mongrel_rails start --port 3000
$ RAILS_ENV="production" mongrel_rails start --port 3001
RR-LB 的性能使用 ab 工具进行了测试,运行了3次
$ ab -c 20 -n 500 http://127.0.0.1:1446/expenses/
Requests per second: 22.67 [#/sec] (mean)
Requests per second: 22.68 [#/sec] (mean)
Requests per second: 22.97 [#/sec] (mean)
在 top 中,CPU 时间分配得很好
PID VIRT RES SHR S %CPU %MEM TIME+ COMMAND
31104 26748 23m 2468 S 42.6 3.4 0:30.09 mongrel_rails
31168 27216 23m 2472 R 40.3 3.4 0:30.10 mongrel_rails
28509 9728 4900 2600 S 5.6 0.7 0:03.91 lighttpd
针对单个 mongrel(不使用 lighty),以衡量其原生性能
$ ab -c 20 -n 500 http://127.0.0.1:3000/expenses/
Requests per second: 20.51 [#/sec] (mean)
Requests per second: 20.42 [#/sec] (mean)
Requests per second: 20.65 [#/sec] (mean)
结论:2 个 mongrel 比 1 个更快(即使在单 CPU 机器上)。要了解更多关于 mod_proxy_core 的背景信息,请查看:*
负载均衡器 (哈希、公平、RR) *
在插件中调度而不是在内核中 * 故障转移处理 *
x-sendfile 和
x-rewrite-* * HTTP Keep-Alive * HTTP/1.1 *
头部重写