{"id":1008,"date":"2009-11-29T20:56:00","date_gmt":"2009-11-29T12:56:00","guid":{"rendered":"\/?p=1008"},"modified":"2009-11-29T20:56:00","modified_gmt":"2009-11-29T20:56:00","slug":"1008","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/architecture\/1008.html","title":{"rendered":"Varnish vs Squid"},"content":{"rendered":"

\u5bf9\u4e8e\u574a\u95f4\u6d41\u4f20\u7684:
1.varnish\u7684\u6027\u80fd\u6bd4squid\u9ad810~20\u500d
2.squid 3.0\u7684\u6027\u80fd\u6bd42.6\u6709\u63d0\u9ad8
\u672c\u6b21\u6d4b\u8bd5\u5c06\u4f1a\u63ed\u793a\u7ed3\u679c,
\u662f\u5426varnish\u7684\u67b6\u6784\u771f\u7684\u80fd\u63d0\u5347\u90a3\u4e48\u591a\u7684\u6027\u80fd
\u662f\u5426squid\u7684\u65b0\u7248\u672c\u5728\u6027\u80fd\u4e0a\u6709\u6240\u63d0\u5347
\u6d4b\u8bd5\u4e2d\u5c06\u4e0d\u5bf9\u5e73\u53f0.\u8f6f\u4ef6.\u7b49\u7b49\u8fdb\u884c\u4f18\u5316
\u7531\u4e8e\u4f18\u5316\u6c34\u5e73\u7684\u5173\u7cfb\u5c06\u6781\u5927\u7684\u5f71\u54cd\u7ed3\u679c.
\u6b64\u6b21\u6d4b\u8bd5\u4e2d\u7684\u6570\u636e\u53ef\u4ee5\u4f5c\u4e3a\u57fa\u51c6\u6570\u636e.
\u53ef\u4ee5\u7531\u5176\u4e2d\u4e2a\u522b\u8f6f\u4ef6\u7684\u4f18\u5316\u4e0e\u975e\u4f18\u5316\u7ed3\u679c\u6bd4\u4f8b\u7cfb\u6570
\u81ea\u884c\u8ba1\u7b97\u5f97\u51fa\u6bd4\u8f83\u7ed3\u679c.\u6240\u4ee5\u4e2a\u522b\u8f6f\u4ef6\u7684\u4f18\u5316\u6216\u8005\u7cfb\u7edf\u4f18\u5316\u540e\u5bf9\u6574\u4f53\u7684\u5f71\u54cd
\u53ef\u4ee5\u7531\u8bfb\u8005\u81ea\u884c\u5bf9\u7279\u5b9a\u8f6f\u4ef6\u8fdb\u884c,\u5e76\u4f7f\u7528\u6b64\u57fa\u51c6\u6570\u636e\u8fdb\u884c\u63a8\u7b97.
WEB\u7ad9\u70b9\u7684\u9875\u9762
\u6211\u5c06\u6dd8\u5b9d\u7684\u9996\u9875\u83b7\u53d6\u5230\u672c\u5730
\u4f5c\u4e3a\u6d4b\u8bd5\u5bf9\u8c61
\u6d4b\u8bd5\u9875\u9762\u4e0b\u8f7d
index_files<\/font><\/a><\/p>\n

\u5e73\u53f0:
PROXY:
CentOS 5.1 \u6700\u5c0f\u5316\u5b89\u88c5
\u6d6a\u6f6eNF190
Xeon 2.8
1G RAM
73G SCSI
Squid 2.6,Squid 3.0,Varnish 1.1.2<\/p>\n

WEB:
CentOS 5.1 \u6700\u5c0f\u5316\u5b89\u88c5
\u6d6a\u6f6eNF180
Xeon 2.8
1G RAM
73G SCSI
Nginx 0.6.31<\/p>\n

CLIENT:
CentOS 5.1 \u6700\u5c0f\u5316\u5b89\u88c5
\u6d6a\u6f6eNF260
Xeon 2.4
512M RAM
36G SCSI
http_load-12mar2006<\/p>\n

SWITCH:
DLINK DES 1024R+<\/p>\n

1.Squid 2.6
\u7f16\u8bd1\u53c2\u6570<\/p>\n

\n
.\/<\/span>configure<\/span> —<\/span>prefix<\/span>=\/<\/span>usr<\/span>\/<\/span>local<\/span>\/<\/span>squid26<\/span><\/div>\n<\/div>\n

\u914d\u7f6e\u6587\u4ef6<\/p>\n

\n
visible_hostname<\/span> <\/span>test2<\/span>.<\/span>hiadmin<\/span>.<\/span>com<\/span>
<\/span>http_port<\/span> <\/span>80<\/span> <\/span>accel<\/span> <\/span>vhost<\/span> <\/span>vport<\/span>
<\/span>cache_peer<\/span> <\/span>192.168.210.111<\/span> <\/span>parent<\/span> <\/span>80<\/span> <\/span>0<\/span> <\/span>no<\/span>–<\/span>query<\/span> <\/span>originserver<\/span> <\/span>name<\/span>=<\/span>test1<\/span>
<\/span>acl<\/span> <\/span>all<\/span> <\/span>src<\/span> <\/span>0.0.0.0<\/span>\/<\/span>0.0.0.0<\/span>
<\/span>http_access<\/span> <\/span>allow<\/span> <\/span>all<\/span>
<\/span>cache_log<\/span> \/<\/span>var<\/span>\/<\/span>log<\/span>\/<\/span>squid26<\/span>\/<\/span>cache<\/span>.<\/span>log<\/span><\/div>\n<\/div>\n

2.Squid 3.0
\u7f16\u8bd1\u53c2\u6570<\/p>\n

\n
.\/<\/span>configure<\/span> —<\/span>prefix<\/span>=\/<\/span>usr<\/span>\/<\/span>local<\/span>\/<\/span>squid30<\/span><\/div>\n<\/div>\n

\u914d\u7f6e\u6587\u4ef6<\/p>\n

\n
visible_hostname<\/span> <\/span>test2<\/span>.<\/span>hiadmin<\/span>.<\/span>com<\/span>
<\/span>http_port<\/span> <\/span>80<\/span> <\/span>accel<\/span> <\/span>vhost<\/span> <\/span>vport<\/span>
<\/span>cache_peer<\/span> <\/span>192.168.210.111<\/span> <\/span>parent<\/span> <\/span>80<\/span> <\/span>0<\/span> <\/span>no<\/span>–<\/span>query<\/span> <\/span>originserver<\/span> <\/span>name<\/span>=<\/span>test1<\/span>
<\/span>acl<\/span> <\/span>all<\/span> <\/span>src<\/span> <\/span>0.0.0.0<\/span>\/<\/span>0.0.0.0<\/span>
<\/span>http_access<\/span> <\/span>allow<\/span> <\/span>all<\/span>
<\/span>cache_log<\/span> \/<\/span>var<\/span>\/<\/span>log<\/span>\/<\/span>squid30<\/span>\/<\/span>cache<\/span>.<\/span>log<\/span><\/div>\n<\/div>\n

3.Varnish 1.1.2
\u7f16\u8bd1\u53c2\u6570<\/p>\n

\n
.\/<\/span>configure<\/span> —<\/span>prefix<\/span>=\/<\/span>usr<\/span>\/<\/span>local<\/span>\/<\/span>varnish<\/span><\/div>\n<\/div>\n

\u914d\u7f6e\u6587\u4ef6<\/p>\n

\n
backend<\/span> <\/span>default<\/span> <\/span>{<\/span>
  <\/span>set<\/span> <\/span>backend<\/span>.<\/span>host<\/span> = <\/span>"<\/span>192.168.210.111<\/span>"<\/span>;
  <\/span>set<\/span> <\/span>backend<\/span>.<\/span>port<\/span> = <\/span>"<\/span>80<\/span>"<\/span>;
<\/span>}<\/span><\/div>\n<\/div>\n

\u8fd0\u884c\u53c2\u6570<\/p>\n

\n
varnishd<\/span>–<\/span>f<\/span> \/<\/span>usr<\/span>\/<\/span>local<\/span>\/<\/span>varnish<\/span>\/<\/span>default<\/span>.<\/span>vcl<\/span> –<\/span>a<\/span> <\/span>0.0.0.0<\/span>:<\/span>80<\/span><\/div>\n<\/div>\n

4.Nginx 0.6.31
\u7f16\u8bd1\u53c2\u6570<\/p>\n

\n
.\/<\/span>configure<\/span> —<\/span>prefix<\/span>=\/<\/span>usr<\/span>\/<\/span>local<\/span>\/<\/span>nginx<\/span><\/div>\n<\/div>\n

\u914d\u7f6e\u6587\u4ef6<\/p>\n

\n
worker_processes<\/span><\/span>10<\/span>;
<\/span>events<\/span> <\/span>{<\/span>
  <\/span>worker_connections<\/span><\/span>1024<\/span>;
<\/span>}<\/span>
<\/span>http<\/span> <\/span>{<\/span>
  <\/span>include<\/span><\/span>mime<\/span>.<\/span>types<\/span>;
  <\/span>default_type<\/span><\/span>application<\/span>\/<\/span>octet<\/span>–<\/span>stream<\/span>;
  <\/span>sendfile<\/span><\/span>on<\/span>;
  <\/span>keepalive_timeout<\/span><\/span>65<\/span>;
  <\/span>server<\/span> <\/span>{<\/span>
  <\/span>listen<\/span><\/span>80<\/span>;
  <\/span>server_name<\/span><\/span>localhost<\/span>;
  <\/span>location<\/span> \/ <\/span>{<\/span>
  <\/span>root<\/span><\/span>html<\/span>;
  <\/span>index<\/span><\/span>index<\/span>.<\/span>html<\/span> <\/span>index<\/span>.<\/span>htm<\/span>;
  <\/span>}<\/span>
  <\/span>error_page<\/span><\/span>500<\/span> <\/span>502<\/span> <\/span>503<\/span> <\/span>504<\/span>\/<\/span>50<\/span>x<\/span>.<\/span>html<\/span>;
  <\/span>location<\/span> = \/<\/span>50<\/span>x<\/span>.<\/span>html<\/span> <\/span>{<\/span>
  <\/span>root<\/span><\/span>html<\/span>;
  <\/span>}<\/span>
  <\/span>}<\/span>
<\/span>}<\/span><\/div>\n<\/div>\n

5.http_load
\u8fd0\u884c\u53c2\u6570<\/p>\n

\n
.\/<\/span>http_load<\/span> –<\/span>parallel<\/span> <\/span>1000<\/span> –<\/span>seconds<\/span> <\/span>10<\/span> <\/span>urls<\/span>.<\/span>txt<\/span>
<\/span>urls<\/span>.<\/span>txt<\/span>
<\/span>http<\/span>:<\/span>\/\/192.168.210.222\/index.html<\/span><\/div>\n<\/div>\n

6.squid 2.7
\u7f16\u8bd1\u53c2\u6570<\/p>\n

\n
.\/<\/span>configure<\/span> —<\/span>prefix<\/span>=\/<\/span>usr<\/span>\/<\/span>local<\/span>\/<\/span>squid27<\/span><\/div>\n<\/div>\n

\u914d\u7f6e\u6587\u4ef6<\/p>\n

\n
visible_hostname<\/span> <\/span>test2<\/span>.<\/span>hiadmin<\/span>.<\/span>com<\/span>
<\/span>http_port<\/span> <\/span>80<\/span> <\/span>accel<\/span> <\/span>vhost<\/span> <\/span>vport<\/span>
<\/span>cache_peer<\/span> <\/span>192.168.210.111<\/span> <\/span>parent<\/span> <\/span>80<\/span> <\/span>0<\/span> <\/span>no<\/span>–<\/span>query<\/span> <\/span>originserver<\/span> <\/span>name<\/span>=<\/span>test1<\/span>
<\/span>acl<\/span> <\/span>all<\/span> <\/span>src<\/span> <\/span>0.0.0.0<\/span>\/<\/span>0.0.0.0<\/span>
<\/span>http_access<\/span> <\/span>allow<\/span> <\/span>all<\/span>
<\/span>cache_log<\/span> \/<\/span>var<\/span>\/<\/span>log<\/span>\/<\/span>squid27<\/span>\/<\/span>cache<\/span>.<\/span>log<\/span><\/div>\n<\/div>\n

\u6d4b\u8bd5\u7ed3\u679c
<\/a>
\u70b9\u56fe\u653e\u5927
\u56fe\u6807\u4e2d\u6807\u6ce8\u6d45\u9ec4\u8272\u7684\u4e3a\u5ba2\u6237\u7aef\u5728\u6293\u53d6\u8fc7\u7a0b\u4e2d\u53ea\u51fa\u73b0\u4e00\u6b21\u6216\u51e0\u6b21\u7684500
\u6a59\u8272\u7684\u4e3a\u51fa\u73b0500\u6293\u53d6\u9519\u8bef\u7684\u9891\u7387\u8f83\u591a
\u7ea2\u8272\u7684\u4e3a\u51e0\u4e4e\u6bcf\u6b21\u90fd\u4f1a\u51fa\u73b0500\u6293\u53d6\u9519\u8bef
\u503c\u5f97\u6ce8\u610f\u7684\u662fsquid 3.0
\u5728500\u5e76\u53d1\u8fde\u63a5\u6570\u65f6500\u51fa\u73b0\u7684\u6b21\u6570\u5f88\u591a
\u4f46\u662f\u57281000\u7684\u65f6\u5019\u53cd\u800c\u6293\u53d6\u5931\u8d25\u7387\u4e0b\u964d\u4e86.<\/p>\n

CPU\u548c\u5185\u5b58\u5360\u7528\u7387
<\/a>
\u70b9\u56fe\u653e\u5927
varnish\u4e00\u76f4\u4fdd\u6301\u826f\u597d\u7684CPU\u548c\u5185\u5b58\u4f7f\u7528\u7387
\u4f46\u662f\u5230\u4e861000\u5e76\u53d1\u6570\u7684\u65f6\u5019
\u4f60\u4f1a\u53d1\u73b0CPU\u4f7f\u7528\u7387\u5230\u4e86103%
\u6ca1\u9519.\u6211\u5e76\u6ca1\u6709\u6253\u9519.\u57285\u6b21\u6d4b\u8bd5\u4e2d,VARNISH\u76841000\u5e76\u53d1\u6570\u6d4b\u8bd5\u5176CPU\u5360\u7528\u7387\u4e00\u76f4\u5f98\u5f8a\u5728101~103\u4e4b\u95f4
\u53ef\u80fd\u662fvarnish\u7684\u8fde\u63a5\u6c60\u5199\u7684\u4e0d\u662f\u7279\u522b\u597d.\u5f53\u5927\u4e8evarnish\u5904\u7406\u91cf\u65f6,\u4f1a\u4f7f\u7528\u66f4\u591a\u7684CPU\u8d44\u6e90\u53bb\u5904\u7406
squid 3.0\u4f3c\u4e4e\u662f\u4e2aCPU\u548c\u5185\u5b58\u7684\u5360\u7528\u5927\u6237
\u53ef\u80fd\u548c\u7248\u672c\u6bd4\u8f83\u65b0\u4ee5\u53ca\u7279\u6027\u6bd4\u8f83\u591a\u6709\u5173(\u867d\u7136\u8fd9\u6b21\u4ec0\u4e48\u7279\u6027\u90fd\u6ca1\u7528\u4e0a)
squid 2.6\u4fdd\u6301\u4e86\u826f\u597d\u7684\u59ff\u6001,\u7a33\u5b9a\u7684CPU\u5360\u7528\u7387\u548c\u5185\u5b58\u5360\u7528\u7387.\u8868\u660e\u4e86\u4e3a\u4f55\u5e02\u9762\u4e0a\u4f7f\u7528\u6700\u591a\u662f\u5b83\u7684\u539f\u56e0.<\/p>\n

\u66f4\u8be6\u7ec6\u7684\u5185\u5bb9\u53ef\u4ee5\u4e0b\u8f7d\u6b64\u8868\u683c
varnish-vs-squid3<\/font><\/a><\/p>\n

\u867d\u7136varnish\u6709\u7740\u4ee4\u4eba\u5403\u60ca\u7684CPU\u5360\u7528\u7387(\u8d85\u8fc7\u5904\u7406\u80fd\u529b\u65f6\u4e5f\u5f88\u4ee4\u4eba\u5403\u60ca)
\u4f46\u662f\u5176\u5904\u7406\u8d85\u5927\u91cf\u7684\u94fe\u63a5\u65f6\u5185\u5b58\u548cCPU\u4f7f\u7528\u7387\u7684\u66b4\u6da8\u5e76\u4e0d\u4ee4\u4eba\u6ee1\u610f
\u4e0d\u8fc7\u5176\u8868\u73b0\u51fa\u7684\u5728\u6700\u5927\u8d1f\u8377\u65f6\u7684fetchs\/second
\u786e\u5b9e\u6bd4squid 2.6\u8981\u9ad8\u51fa\u5927\u7ea68%
\u5b9e\u9a8c\u8868\u660e.\u5728\u9700\u8981\u66f4\u52a0\u7a33\u5b9a\u7684\u751f\u4ea7\u73af\u5883\u4e2d,varnish\u8fd8\u4e0d\u80fd\u66ff\u4ee3\u8001\u4e00\u4ee3\u7684squid 2.6
\u4f46\u662f\u5176\u5bf9squid 3.0\u5df2\u7ecf\u4ea7\u751f\u4e86\u5f88\u660e\u663e\u7684\u6311\u6218.
\u5982\u679csquid 3.0\u4e0d\u80fd\u6bd4\u4ed6\u7684\u4e0a\u4ee3\u4ea7\u54c1\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u7684\u8bdd
\u5f88\u6709\u53ef\u80fd\u6700\u4f73\u53cd\u5411\u4ee3\u7406\u7684\u5b9d\u5ea7\u4f1a\u88abvarnish\u593a\u8d70
\u4e0d\u8bba\u5982\u4f55
\u8fd9\u6b21\u6d4b\u8bd5\u7684\u4e3b\u9898.varnish\u6bd4squid\u6709\u774010\u500d\u6216\u800520\u500d\u7684\u6027\u80fd
\u88ab\u8bc1\u5b9e\u662f\u4e0d\u53ef\u80fd\u5b9e\u73b0\u7684.
\u867d\u7136\u6d4b\u8bd5\u6570\u636e\u91cf\u5145\u6ee1100M\u5e26\u5bbd\u53ef\u80fd\u5f71\u54cd\u5230\u6d4b\u8bd5\u7684\u51c6\u786e\u5ea6.
\u4f46\u662f\u66f4\u9ad8\u7684\u5e26\u5bbd\u6240\u5e26\u6765\u7684\u540c\u65f6\u8fde\u63a5\u6570,\u5f88\u53ef\u80fd\u4f1a\u6491\u7206varnish\u4e3b\u673a\u7684CPU\u548c\u5185\u5b58.<\/p>\n

\u7ed3\u8bba
1.varnish\u5728\u9ad8\u8d1f\u8f7d\u4e0b\u4ee5CPU\u548c\u5185\u5b58\u4e3a\u4ee3\u4ef7,\u6bd4squid 2.6\u63d0\u9ad88%,\u4f46\u662f\u7edd\u975e10\u500d~20\u500d.
2.squid 3.0\u7684\u6027\u80fd\u6bd42.6\u66f4\u4f4e.\u800c\u975e\u66f4\u9ad8.\u76f8\u53cd,3.0\u662f\u6700\u4e0d\u7a33\u5b9a\u4ee5\u53ca\u6027\u80fd\u6700\u5dee\u7684.
3.squid 2.7\u7684\u6027\u80fd\u6bd42.6\u4f4e,\u4f46\u662fCPU\u548c\u5185\u5b58\u5360\u7528\u7387\u63a7\u5236\u7684\u66f4\u597d.<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5bf9\u4e8e\u574a\u95f4\u6d41\u4f20\u7684:
1.varnish\u7684\u6027\u80fd\u6bd4squid\u9ad810~20\u500d
2.squid 3.0\u7684\u6027\u80fd\u6bd42.6\u6709\u63d0\u9ad8
\u672c\u6b21\u6d4b\u8bd5\u5c06\u4f1a\u63ed\u793a\u7ed3\u679c,
\u662f\u5426varnish\u7684\u67b6\u6784\u771f\u7684\u80fd\u63d0\u5347\u90a3\u4e48\u591a\u7684\u6027\u80fd
\u662f\u5426squid\u7684\u65b0\u7248\u672c\u5728\u6027\u80fd\u4e0a\u6709\u6240\u63d0\u5347
\u6d4b\u8bd5\u4e2d\u5c06\u4e0d\u5bf9\u5e73\u53f0.\u8f6f\u4ef6.\u7b49\u7b49\u8fdb\u884c\u4f18\u5316
\u7531\u4e8e\u4f18\u5316\u6c34\u5e73\u7684\u5173\u7cfb\u5c06\u6781\u5927\u7684\u5f71\u54cd\u7ed3\u679c.
\u6b64\u6b21\u6d4b\u8bd5\u4e2d\u7684\u6570\u636e\u53ef\u4ee5\u4f5c\u4e3a\u57fa\u51c6\u6570\u636e.
\u53ef\u4ee5\u7531\u5176\u4e2d\u4e2a\u522b\u8f6f\u4ef6\u7684\u4f18\u5316\u4e0e\u975e\u4f18\u5316\u7ed3\u679c\u6bd4\u4f8b\u7cfb\u6570
\u81ea\u884c\u8ba1\u7b97\u5f97\u51fa\u6bd4\u8f83\u7ed3\u679c.\u6240\u4ee5\u4e2a\u522b\u8f6f\u4ef6\u7684\u4f18\u5316\u6216\u8005\u7cfb\u7edf\u4f18\u5316\u540e\u5bf9\u6574\u4f53\u7684\u5f71\u54cd
\u53ef\u4ee5\u7531\u8bfb\u8005\u81ea\u884c\u5bf9\u7279\u5b9a\u8f6f\u4ef6\u8fdb\u884c,\u5e76\u4f7f\u7528\u6b64\u57fa\u51c6\u6570\u636e\u8fdb\u884c\u63a8\u7b97.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1008"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1008"}],"version-history":[{"count":0,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1008\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}