我想使用 Varnish 4 优化 Odoo 安装。Odoo 使用 Python/Werkzeug 来传递 HTML。Ubuntu 14.04 上安装了 Odoo 8.0rc1 和 Varnish 4.0.1-2~trusty。Odoo/Varnish 都安装在同一台服务器上。使用 ab 进行简单测试后,不使用 Varnish 时每秒收到 117 个请求(在端口 8069 上),使用 Varnish 时每秒收到 116 个请求。在服务器端,不使用 Varnish 时 Odoo 服务器的负载略高(10%)。
有任何想法吗?
这直接针对 Odoo:
aw@lian:~$ ab -n 1000 -c 20 http://myodoo.example.com:8069/web
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking xxx (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Werkzeug/0.9.4
Server Hostname:
Server Port: 8069
Document Path: /web
Document Length: 251 bytes
Concurrency Level: 20
Time taken for tests: 8.516 seconds
Complete requests: 1000
Failed requests: 0
Non-2xx responses: 1000
Total transferred: 476000 bytes
HTML transferred: 251000 bytes
Requests per second: 117.42 [#/sec] (mean)
Time per request: 170.323 [ms] (mean)
Time per request: 8.516 [ms] (mean, across all concurrent requests)
Transfer rate: 54.58 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 29 33 2.5 33 38
Processing: 43 136 28.0 133 226
Waiting: 43 135 28.0 133 225
Total: 73 169 28.3 167 259
Percentage of the requests served within a certain time (ms)
50% 167
66% 178
75% 186
80% 192
90% 209
95% 221
98% 235
99% 242
100% 259 (longest request)
这是通过 Varnish 实现的:
aw@lian:~$ ab -n 1000 -c 20 http://myodoo.example.com/web
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking xxxx (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Werkzeug/0.9.4
Server Hostname:
Server Port: 80
Document Path: /web
Document Length: 251 bytes
Concurrency Level: 20
Time taken for tests: 8.603 seconds
Complete requests: 1000
Failed requests: 0
Non-2xx responses: 1000
Total transferred: 536197 bytes
HTML transferred: 251000 bytes
Requests per second: 116.23 [#/sec] (mean)
Time per request: 172.067 [ms] (mean)
Time per request: 8.603 [ms] (mean, across all concurrent requests)
Transfer rate: 60.86 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 29 33 2.5 33 38
Processing: 66 138 31.7 132 272
Waiting: 66 137 30.1 132 255
Total: 95 171 32.1 166 305
Percentage of the requests served within a certain time (ms)
50% 166
66% 178
75% 186
80% 194
90% 212
95% 233
98% 262
99% 279
100% 305 (longest request)
aw@lian:~$
答案1
当您用自己的“vcl”替换默认的“vcl”时,Varnish 的功能将达到最强大。默认情况下,它是在 /etc/varnish/default.vcl (debian) 中配置的。
您需要确保您的启动脚本引用该文件。
如果您已打开它,则可以看到默认代码。基本上,您需要“取消设置”Cookie 标头,因为它是通过系统传入的,这样 Varnish 才能真正缓存该项目。
默认情况下,您至少需要强制使用静态媒体(图像、javascript、css),类似于如下所示:
sub vcl_recv {
if (req.url ~ "\.(css|js|ico|png|gif|jpg|swf|jpeg|zip)$" ||
req.url ~ "\.js?ver\=*$" ||
req.url ~ "\.css?ver\=*$") {
unset req.http.cookie; # Cookies not needed here
return(lookup);
}
}
varnish 文档非常详细,介绍了如何在 VCL 中完成你需要做的所有事情。我强烈建议花几个小时阅读它:
v3 文档:https://www.varnish-cache.org/docs/3.0/ v4:https://www.varnish-cache.org/docs/4.0/
具体来说,您可能需要“用户指南”。
Varnish 的威力令人吃惊,但是您使用它得到的只是您投入的!
祝你好运,如果你遇到任何事情,不要犹豫,提出更多问题!