技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> 系统架构 --> Varnish VS Nginx测试报告

Varnish VS Nginx测试报告

浏览:3797次  出处信息

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;
}

    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故障了,需要有备份服务器。

        

  • 建议继续学习:

    1. 配置Nginx+uwsgi更方便地部署python应用    (阅读:105399)
    2. 搜狐闪电邮箱的 Nginx/Postfix 使用模式    (阅读:32524)
    3. 解析nginx负载均衡    (阅读:14506)
    4. Nginx模块开发入门    (阅读:9871)
    5. 检查nginx配置,重载配置以及重启的方法    (阅读:9093)
    6. Cacti 添加 Nginx 监控    (阅读:8918)
    7. Nginx+FastCgi+Php 的工作机制    (阅读:8851)
    8. nginx的配置文件    (阅读:8821)
    9. 奇怪的 Nginx 的 upstream timed out 引起响应 502    (阅读:8139)
    10. 解决IE6从Nginx服务器下载图片不Cache的Bug    (阅读:7099)
    QQ技术交流群:445447336,欢迎加入!
    扫一扫订阅我的微信号:IT技术博客大学习
    << 前一篇:深入浅出REST
    © 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

    京ICP备15002552号-1