简介:
反向代理服务器,适用于对静态资源的访问,比如图片,可通过缓存提高访问速度。
官网https://www.varnish-cache.org/
试用心得:
原来项目的图片是通过tomcat来访问的,图片访问量占到所有请求的20%左右。并且图片不多,决大部分都是重复访问。于是想使用缓存来减少磁盘IO的消耗。很自然就用到了varnish,比较新、性能也很强劲的缓存服务器,squid的替换者。
不过在redhat企业版5.2(rhel5.2)上安装颇费了周折,原因就是rhel5最高只支持varnish 2.0.6。我之前安装过3.0.1和2.1.6,各种编译报错,解决不了。忽然看到官网的这么一句话:
This means that we can not update Varnish in EPEL so the latest version there is Varnish 2.0.6.
安装成功后做了一个和tomcat对比的压力测试,固定访问一张图片的性能提升60%左右。
安装:
tar xf varnish-2.0.6.tar.gz
cd varnish-2.0.6
./autogen.sh
./configure --prefix=~/varnish
make && make install
使用的是普通账号安装,安装在家目录的varnish下
配置:
vi ~/varnish/etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "28080";
}
sub vcl_recv {
if(req.url ~ "\.(png|gif|jpg)$") {
return (lookup);
}
return (pass);
}
如果是图片,先查询缓存,其他直接转发到后端服务器。
启动:
varnishd -f ~/varnish/etc/varnish/default.vcl -s malloc,128M -a 0.0.0.0:8000 -T 192.168.102.62:8001
监听端口8000,分配128m的内存
输出日志:
varnishncsa -w ~/logs/varnish/varnish.log &
访问日志输出在~/logs/varnish/varnish.log
优化Linux内核参数(使用root账号):
vi /etc/sysctl.conf
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
生效:
sysctl -p
优化参数:
参考https://www.varnish-cache.org/trac/wiki/Performance
thread_pool_add_delay=2
thread_pools=<Number of cpu cores>
thread_pool_min=<800/number of cpu cores>
thread_pool_max=4000
session_linger=100
4cpu的命令:
varnishd -f ~/varnish/etc/varnish/default.vcl -s malloc,128M -a 0.0.0.0:8000 -T 192.168.102.62:8001 -p thread_pool_add_delay=2 -p thread_pools=4 -p thread_pool_min=200 -p thread_pool_max=4000 -p session_linger=100
在我的测试中,比默认参数性能提高10%左右。
压力测试:
提升60%
线程数
|
200
|
循环次数
|
500
|
总次数
|
10w
|
|
每秒请求数
|
平均响应时间(毫秒)
|
tomcat
|
4109
|
48
|
varnish
|
6864
|
29
|
提升
|
67%
|
47%
|
线程数
|
500
|
循环次数
|
200
|
总次数
|
10w
|
|
每秒请求数
|
平均响应时间(毫秒)
|
tomcat
|
4109
|
121
|
varnish
|
6505
|
76
|
提升
|
58%
|
37%
|
线程数
|
800
|
循环次数
|
125
|
总次数
|
10w
|
|
每秒请求数
|
平均响应时间(毫秒)
|
tomcat
|
3904
|
204
|
varnish
|
6098
|
131
|
提升
|
56%
|
35%
|
参考:
http://blog.s135.com/post/313/
分享到:
相关推荐
本资源包含Varnish的安装文件varnish-3.0.5-1.el6.x86_64.rpm 和varnish-libs-3.0.5-1.el6.x86_64.rpm,是搭建cdn的高性能HTTP加速器Varnish服务器必需的安装包,下载后解压即可,具体安装配置过程清移步我的博客
varnish 安装包 varnish 安装包 varnish 安装包 varnish 安装包
linux-varnish配置
varnish+lighttpd配置
varnish 官方白皮书文档,包含配置信息,说明信息,方便查阅使用。
Getting Started with Varnish Cache: Accelerate Your Web Applications by Thijs Feryn English | 13 Mar. 2017 | ASIN: B06XP3D6Z2 | 253 Pages | AZW3 | 720.91 KB How long does it take for your website to ...
varnish测试报告
squid、varnish、ngx_cache的性能测试对比报告
laravel-varnish, 使 varnish 和 Laravel 在一起很好 使 varnish 和 Laravel 在一起很好 这个包提供了一个简单的方法,可以在 Laravel 中使用 varnish 4 ( 或者 5 ) 。 它提供了路由中间件,在应用到路由时,将确保 ...
教程名称: Varnish配置教程和学习资料合集【】HTTP加速器varnish安装部署【】varnish cache 配置使用ChinaUnix【】varnish 原理【】Varnish-vcl的配置【】varnish配置实例 资源太大,传百度网盘了,链接在附件中,...
在反向代理,web加速方面,varnish已经有足够能力代替squid。挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好。 2.作者:Poul-Henning Kamp是FreeBSD的内核开发者之一。
Varnish 2.1.2 缓存负载,做反向代理缓存优于squid
Varnish权威指南(中文)
nginx和php和varnish配置
varnish-magento
Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好。 本文档详细讲解了varnish的安装配置过程以及配置文件详解
varnish的VCL的详细解析,网上整理
varnish-5.2.1.tar.gz 为varnish缓存服务器软件包下载
varnish4,是目前varnish最新版本。
本书是介绍如何快速使用Varnish的一本电子书,英文的