Varnish VS Nginx测试报告
1:配置情况
nginx机器配置:
CPU: E7500 @ 2.93GHz (双核)
内存:4G
varnish机器配置:
CPU: E3300 @ 2.50GHz (双核)
内存:2G
测试脚本执行机器配置:
CPU: AMD Phenom(tm) II X4 925 Processor
内存:2G
2:测试准备工作
2.1:安装siege
使用压力测试工具siege(http://www.joedog.org/index/siege-home) 来验证。可以根据路径来并发重复压力测试。安装方式:
下载:wget ftp://sid.joedog.org/pub/siege/siege-latest.tar.gz
安装:
#./configure
#make && make install
[root@localhost test] siege -c 100 -r 100 -f varnish_url.txt
[root@localhost test] siege -c 100 -r 100 -f nginx_url.txt
参数说明:
-c 100 并发100个用户
-r 100 重复循环100次
-f varnish_url.txt 任务列表:URL列表
2.2:构造URL
构造了536个url测试,其中1个是错误的url。
到测试机器上,
[root@localhost test] cd /data/htdocs/resources/web
[root@localhost test] find . -name "*.jpg" -print > varnish_url.txt
2.3:开启nginx页面缓存方法
开启nginx的缓存图片的方法,在nginx的conf中添加:
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
expires 30d;
access_log off;
}
感谢鱼哥 @smallfishxy 指导
3:运行后测试结果:
3.1.1:nginx开启页面缓存的情况
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 65.83 secs
Data transferred: 260.83 MB
Response time: 0.01 secs
Transaction rate: 151.91 trans/sec
Throughput: 3.96 MB/sec
Concurrency: 2.06
Successful transactions: 9900
Failed transactions: 0
Longest transaction: 3.03
Shortest transaction: 0.00
3.1.2:nginx不开启页面缓存的情况
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 63.90 secs
Data transferred: 266.10 MB
Response time: 0.01 secs
Transaction rate: 156.49 trans/sec
Throughput: 4.16 MB/sec
Concurrency: 2.18
Successful transactions: 9900
Failed transactions: 0
Longest transaction: 0.35
Shortest transaction: 0.00
3.1.3:nginx开启页面缓存第二次测试的情况
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 63.05 secs
Data transferred: 266.10 MB
Response time: 0.01 secs
Transaction rate: 158.60 trans/sec
Throughput: 4.22 MB/sec
Concurrency: 2.06
Successful transactions: 9900
Failed transactions: 0
Longest transaction: 0.34
Shortest transaction: 0.00
3.2.1:varnish清空缓存第一次测试情况
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 62.87 secs
Data transferred: 266.10 MB
Response time: 0.01 secs
Transaction rate: 159.06 trans/sec
Throughput: 4.23 MB/sec
Concurrency: 1.95
Successful transactions: 9900
Failed transactions: 0
Longest transaction: 0.37
Shortest transaction: 0.00
3.2.2:varnish有缓存测试
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 61.91 secs
Data transferred: 266.10 MB
Response time: 0.01 secs
Transaction rate: 161.52 trans/sec
Throughput: 4.30 MB/sec
Concurrency: 1.78
Successful transactions: 9900
Failed transactions: 0
Longest transaction: 0.34
Shortest transaction: 0.00
3.2.3:varnish负责均衡性能
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 59.75 secs
Data transferred: 266.10 MB
Response time: 0.01 secs
Transaction rate: 167.36 trans/sec
Throughput: 4.45 MB/sec
Concurrency: 1.98
Successful transactions: 9900
Failed transactions: 0
Longest transaction: 3.01
Shortest transaction: 0.00
4:结论
- 在varnish机器性能较差的情况下,在高并发情况下,能够跑出比nginx更好的性能。
- 线上是读取了单台图片服务器,使用varnish能够解决图片服务负责均衡的问题,减少了nginx对内存的存储双份造成浪费的问题。
- 有varnish负载均衡,单台img服务器故障时能让服务继续。当然varnish故障了,需要有备份服务器。