Varnish 和 Squid比較到底強多少_測試

來源:互聯網
上載者:User

對於坊間流傳的:
1.varnish的效能比squid高10~20倍
2.squid 3.0的效能比2.6有提高
本次測試將會揭示結果,
是否varnish的架構真的能提升那麼多的效能
是否squid的新版本在效能上有所提升
測試中將不對平台.軟體.等等進行最佳化
由於最佳化水平的關係將極大的影響結果.
此次測試中的資料可以作為基準資料.
可以由其中個別軟體的最佳化與非最佳化結果比例係數
自行計算得出比較結果.所以個別軟體的最佳化或者系統最佳化後對整體的影響
可以由讀者自行對特定軟體進行,並使用此基準資料進行推算.
WEB網站的頁面
我將淘寶的首頁擷取到本地
作為測試對象
測試頁面下載
index_files

平台:
PROXY:
CentOS 5.1 迷你安裝
浪潮NF190
Xeon 2.8
1G RAM
73G SCSI
Squid 2.6,Squid 3.0,Varnish 1.1.2

WEB:
CentOS 5.1 迷你安裝
浪潮NF180
Xeon 2.8
1G RAM
73G SCSI
Nginx 0.6.31

CLIENT:
CentOS 5.1 迷你安裝
浪潮NF260
Xeon 2.4
512M RAM
36G SCSI
http_load-12mar2006

SWITCH:
DLINK DES 1024R+

1.Squid 2.6
編譯參數 ./ configure  -- prefix =/ usr / local / squid26

設定檔 visible_hostname   test2 . hiadmin . com
http_port   80   accel   vhost   vport
cache_peer   192.168.210.111   parent   80   0   no - query   originserver   name = test1
acl   all   src   0.0.0.0 / 0.0.0.0
http_access   allow   all
cache_log  / var / log / squid26 / cache . log

2.Squid 3.0
編譯參數 ./ configure  -- prefix =/ usr / local / squid30

設定檔 visible_hostname   test2 . hiadmin . com
http_port   80   accel   vhost   vport
cache_peer   192.168.210.111   parent   80   0   no - query   originserver   name = test1
acl   all   src   0.0.0.0 / 0.0.0.0
http_access   allow   all
cache_log  / var / log / squid30 / cache . log

3.Varnish 1.1.2
編譯參數 ./ configure  -- prefix =/ usr / local / varnish

設定檔 backend   default   {
    set   backend . host  =  " 192.168.210.111 " ;
    set   backend . port  =  " 80 " ;
}

運行參數 varnishd  - f  / usr / local / varnish / default . vcl  - a   0.0.0.0 : 80

4.Nginx 0.6.31
編譯參數 ./ configure  -- prefix =/ usr / local / nginx

設定檔 worker_processes   10 ;
events   {
    worker_connections   1024 ;
}
http   {
    include   mime . types ;
    default_type   application / octet - stream ;
    sendfile   on ;
    keepalive_timeout   65 ;
    server   {
    listen   80 ;
    server_name   localhost ;
    location  /  {
    root   html ;
    index   index . html   index . htm ;
    }
    error_page   500   502   503   504  / 50 x . html ;
    location  = / 50 x . html   {
    root   html ;
    }
    }
}

5.http_load
運行參數 ./ http_load  - parallel   1000  - seconds   10   urls . txt
urls . txt
http : //192.168.210.222/index.html

6.squid 2.7
編譯參數 ./ configure  -- prefix =/ usr / local / squid27

設定檔 visible_hostname   test2 . hiadmin . com
http_port   80   accel   vhost   vport
cache_peer   192.168.210.111   parent   80   0   no - query   originserver   name = test1
acl   all   src   0.0.0.0 / 0.0.0.0
http_access   allow   all
cache_log  / var / log / squid27 / cache . log

測試結果

點圖放大
表徵圖中標註淺黃色的為用戶端在抓取過程中只出現一次或幾次的500
橙色的為出現500抓取錯誤的頻率較多
紅色的為幾乎每次都會出現500抓取錯誤
值得注意的是squid 3.0
在500並發串連數時500出現的次數很多
但是在1000的時候反而抓取失敗率下降了.

CPU和記憶體佔用率

點圖放大
varnish一直保持良好的CPU和記憶體使用量率
但是到了1000並發數的時候
你會發現CPU使用率到了103%
沒錯.我並沒有打錯.在5次測試中,VARNISH的1000並發數測試其CPU佔用率一直徘徊在101~103之間
可能是varnish的串連池寫的不是特別好.當大於varnish處理量時,會使用更多的CPU資源去處理
squid 3.0似乎是個CPU和記憶體的佔用大戶
可能和版本比較新以及特性比較多有關(雖然這次什麼特性都沒用上)
squid 2.6保持了良好的姿態,穩定的CPU佔用率和記憶體佔用率.表明了為何市面上使用最多是它的原因.

更詳細的內容可以下載此表格
varnish-vs-squid3

雖然varnish有著令人吃驚的CPU佔用率(超過處理能力時也很令人吃驚)
但是其處理超大量的連結時記憶體和CPU使用率的暴漲並不令人滿意
不過其表現出的在最大負荷時的fetchs/second
確實比squid 2.6要高出大約8%
實驗表明.在需要更加穩定的生產環境中,varnish還不能替代老一代的squid 2.6
但是其對squid 3.0已經產生了很明顯的挑戰.
如果squid 3.0不能比他的上代產品提供更好的效能和穩定性的話
很有可能最佳反向 Proxy的寶座會被varnish奪走
不論如何
這次測試的主題.varnish比squid有著10倍或者20倍的效能
被證實是不可能實現的.
雖然測試資料量充滿100M頻寬可能影響到測試的準確度.
但是更高的頻寬所帶來的同時串連數,很可能會撐爆varnish主機的CPU和記憶體.

結論
1.varnish在高負載下以CPU和記憶體為代價,比squid 2.6提高8%,但是絕非10倍~20倍.
2.squid 3.0的效能比2.6更低.而非更高.相反,3.0是最不穩定以及效能最差的.
3.squid 2.7的效能比2.6低,但是CPU和記憶體佔用率控制的更好.

 

====================================================== Squid 2.6 2.7 3.0 3.1 以及 varnish 2.1.5 效能對比測試

http://www.cnblogs.com/littlehb/archive/2012/02/21/2360787.html

  說明:

 

使用壓力測試軟體siege,http_load對這幾個代理軟體進行測試,測試了不同大小的檔案和各種並發數。

 

squid的版本選擇,考慮到實際使用的一些需求,並參考了其他的一些文章(

比如:http://www.php-oa.com/2009/12/02/cache%e8%bd%af%e4%bb%b6%e7%89%88%e6%9c%ac%e9%80%89%e6%8b%a9.html

),沒有選擇比較老的squid 2.5。

 

每次測試前清除檔案快取並重啟代理軟體。

 

這個測試僅作為資料參考,並不能完全類比生產環境那麼複雜的網路請求(請求數,各種大小的檔案請求)。

 

一、測試環境:

 

硬體:Intel Xeon E5410 @ 2.33GHz * 2,16G記憶體,SATA 500G * 4(RAID 10)

 

安裝squid 2.7

 

./configure -prefix=/opt/squid2.7 -enable-xmalloc-statistics --enable-async-io=320 --with-maxfd=65536 -enable-useragent-log -enable-referer-log -enable-epoll -disable-poll -enable-large-cache-files -disable-internal-dns -enable-linux-netfilter -enable-truncate -enable-x-accelerator-vary -enable-follow-x-forwarded-for -with-large-files -with-pthreads -enable-storeio="aufs,coss,diskd,ufs" -enable-kill-parent-hack -enable-gnuregex -enable-cache-digests -enable-delay-pools -enable-stacktraces -enable-default-err-language=Simplify_Chinese -enable-err-languages="Simplify_Chinese English" --enable-auth="basic" --enable-basic-auth-helpers="NCSA" --enable-snmp

 

注意:

 

1、不要使用-enable-dlmalloc這個編譯參數,否則運行一段時間會報錯 FATAL: xcalloc: Unable to allocate 1 blocks of 4112 bytes!

 

參考:

 

http://www.mail-archive.com/squid-users@squid-cache.org/msg48804.html

 

http://www.mail-archive.com/squid-users@squid-cache.org/msg40839.html

 

大致意思是dlmalloc是squid在某些系統本身malloc太爛的情況的代替方案,dlmalloc已經很老,且不支援2G以上記憶體(比較有意思的是之前使用的squid 3.0也用了這個參數,卻正常運行,記憶體使用量有配置超過10G的,可能3.0有特殊處理相容了這種編譯配置)。

 

Squid 3的編譯參數:

 

www:/srv# /opt/squid3/sbin/squid -v

Squid Cache: Version 3.0.STABLE25

configure options: '--prefix=/opt/squid3' '--enable-dlmalloc' '--enable-gnuregex' '--enable-async-io=160' '--enable-removal-policies=heap,lru' '--enable-delay-pools' '--enable-storeio=ufs,aufs,null' '--disable-wccp' '--enable-kill-parent-hack' '--disable-select' '--enable-auth=basic' '--with-aio' '--disable-ident-lookup' '--with-filedescriptors=65536' '--enable-err-languages=Simplify_Chinese' '--enable-default-err-languages=Simplify_Chinese'

 

3.1的編譯參數基本和3.0一樣。

 

squid幾個版本使用的基本是一樣的squid.conf,效能相關的幾個配置如下:

 

cache_mem 4000 MB

maximum_object_size_in_memory 512 KB

 

#cache_dir

cache_dir aufs /srv/squid_cache 20480 16 256

 

maximum_object_size 4096 KB

 

 

Varnish:

 

tar zxf varnish-2.1.5.tar.gz

cd varnish-2.1.5

./configure --prefix=/opt/varnish

 

運行參數:

 

/opt/varnish/sbin/varnishd -u www -g www -f /opt/varnish/etc/varnish/aipai.vcl -a 0.0.0.0:8080 -s file,/srv/varnish_cache/cache/varnish_cache.data,1G -w 1024,51200,10 -t 3600 -T 0.0.0.0:30000

 

二、測試結果:

 

每次測試60s

 

測試命令:siege -b -c 100 -t 60s URL

 

表中記錄的資料是:Transaction rate,單位:請求/s

 

典型測試結果:

 

da01:~/siege-2.69# siege -b -c 500 -t 60s http://www.aipai.com:8080/about/map.html 

** SIEGE 2.69

** Preparing 500 concurrent users for battle.

The server is now under siege...

Lifting the server siege...      done.

 

Transactions:                 653211 hits  

Availability:                 100.00 %          

Elapsed time:                  59.35 secs

Data transferred:            1238.43 MB

Response time:                  0.05 secs               //平均相應時間

Transaction rate:           11006.08 trans/sec   //平均每秒處理速度,請求/s

Throughput:                    20.87 MB/sec          //網路輸送量

Concurrency:                  498.86                         //最高並發數

Successful transactions:      653212                         //成功處理數

Failed transactions:               0                         //失敗處理數

Longest transaction:            3.01                         //最長的請求處理時間

Shortest transaction:           0.00

 

對於測試結果詳細的說明,有興趣的朋友請查閱siege的文檔,比較關鍵的幾個資料上面已經標註了。

 

測試1:

 

目標URL:http://www.aipai.com:8080/about/map.html,測試小檔案請求,檔案大小:6221 byte

 

 

並發 10

並發 100

並發 500

並發 1000

squid 2.6 STABLE23

8207

11211

11016

10451

squid 2.7 STABLE9

8261

11409

11006

10002

squid 3.0 STABLE25

8524

9762

8138

8768

squid 3.1.11

6421

6832

5990

5834

varnish 2.1.5

10875

10251

11459

11412

 

PS:siege使用超過1000個並發會報錯。

 

測試2:

 

目標URL:http://www.aipai.com:8080/c7/Pjg_KScqImgnaiYs.html,測試我們網站典型的播放頁請求,檔案大小:75356 byte

 

 

並發 10

並發 100

並發 500

並發 1000

squid 2.6 STABLE23

4554

6382

6625

6696(4 failed )

squid 2.7 STABLE9

4164

6234

6565

6588

squid 3.0 STABLE25

4366

5315

5190

5153

squid 3.1.11

3697

4217

4357

4075

varnish 2.1.5

6618

6781

6775

5714

 

 

測試1,測試2總結:

 

測試1,測試2都是對一個URL進行強壓,主要測試MEM_HIT時候軟體的處理能力。

 

1、squid 2.6在squid組中基本是最快的,在測試2並發1000的時候開始不太穩定,有4個Connection timed out。

 

2、squid 2.7的成績和2.6在一個水平線,略遜一點。

 

3、squid 從3.0開始用c++全部重寫,目前看來與2.7/2.6效能差距還很明顯,3.1從效能上來看比3.0還差(squid哥,不能為了功能損失太多的效能啊)。

 

4、varnish在大多數測試上處於領先,有些項目差一些(varnish的測試結果不是很穩定,有一些擺幅)。varnish效能比squid強一些,不過遠沒有達到某些文章宣稱的是squid的10倍。

 

 

測試3:

 

進一步類比生產環境,從實際啟動並執行squid access log中截取了5萬個url來測試。

 

每次測試延長到2分鐘。

 

 

並發 10

並發 100

並發 500

並發 1000

squid 2.6 STABLE23

2839

5485

6722

6604

squid 2.7 STABLE9

2981

5215

6789

6742

squid 3.0 STABLE25

2863

4294

4345

3859

squid 3.1.11

2682

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.