

How a little varnish changed my life
source link: https://www.devroom.io/2010/03/24/how-a-little-varnish-changed-my-life/?utm_campaign=Feed%3A+ariejan+%28ariejan%7Cdevroom.io%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How a little varnish changed my life
Posted:
2010-03-24
- Last updated:
2019-06-05
Tagged
Okay, it’s a bit of an exaggeration to say varnish changed my life, but it sure did change the speed of my site!
I got from a rotten 6 requests per second with WordPress to a whopping 9500! If you’re on Linux and running Apache, installing varnish is a breeze! Especially if you’re hosting a well cacheable site like a blog.
I’m running on a Linux Debian virtual server (provided by Kabisa) with 1 VCPU core and 512MB of memory. Nothing fancy.
Before I was running Apache 2 with PHP and WordPress. Doing the occasional test this gave me (uncached) a performance of about 6 request/second (using apache’s ab
with 10 concurrent connections). With some caching plugins I was able to crank that up to about 15-20 requests a second.
After upgrading my blog to Toto, I got quite a boost to about 30 requests/second. But, my blog doesn’t contain any dynamic elements any more and Toto + Rack give you all the handles to implement caching (ETags, Cache-Control headers, etc.). FYI: I’m running Apache2 + Passenger to run Toto.
Since I heard about Varnish a few times before I decided to give it a try and apt-get install varnish
'ed it on my Debian box (I’m running squeeze
, thank you).
Now I have a few other sites running on my vps which I don’t want to cache just yet. The problem was how do I tell Varnish to only cache ariejan.net, and skip the rest.
Here’s the entire configuration for Varnish to accomplish just that:
backend default { .host = "127.0.0.1"; .port = "8080"; }
sub vcl_recv { if (req.http.host !~ "ariejan.net") { return(pass); } }
Yes, that is just two lines! What this does is forward everything you throw at varnish to the server at port 8080. The vcl_recv
makes sure that if the hostname does not include ariejan.net varnish passes the request forward - no caching.
The second thing I had to do was configure Apache to listen on port 8080 instead of 80 in /etc/apache2/ports.conf
. Then also make sure to have all your virtual hosts (even those you don’t want cached) configured for port 8080 too in /etc/apache2/sites-available
Restart apache, restart varnish and you’re golden!
When I first ran my ab
benchmark with 10 concurrent connections I got to about 150 requests per second. But when I really pushed it to a 1000 concurrent connections (ab
couldn’t handle more), I got to a whopping 9500 requests per seconds doing 60k requests! That is epic! Oh, and my VPS didn’t even break a sweat - system load got up to 1.08 for second or so.
For the record:
$ ab -c 1000 -n 60000 http://ariejan.net/2010/03/22/shields-up-rrrack-alert/
Server Software: Apache/2.2.15
Server Hostname: ariejan.net
Server Port: 80
Document Path: /2010/03/22/shields-up-rrrack-alert/
Document Length: 5117 bytes
Concurrency Level: 1000
Time taken for tests: 6.290 seconds
Complete requests: 60000
Failed requests: 0
Write errors: 0
Total transferred: 331434376 bytes
HTML transferred: 307460062 bytes
Requests per second: 9539.34 [#/sec] (mean)
Time per request: 104.829 [ms] (mean)
Time per request: 0.105 [ms] (mean, across all concurrent requests)
Transfer rate: 51459.38 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 56 364.9 12 6209
Processing: 2 22 76.7 16 3073
Waiting: 2 19 76.6 13 3070
Total: 3 78 374.6 29 6223
Interested? Check out Varnish now or ask us at Kabisa to help you out!
Recommend
-
77
1.前端nginx做调度器及反代服务器,将用户的请求调度至后端的两台varnish,缓存调度算法使用一致性hash算法保证缓存命中率;2.两台varnish反向代理用户请求至三个(组)后端主机,分别为存储静态资源(htm,html,css,js),应用程序服务器(可以部署wordpress或Discuz!)...
-
93
(1)动静分离部署wordpress,动静都要能实现负载均衡,要注意会话的问题;(2)在haproxy和后端主机之间添加varnish进行缓存;(3)设计拓扑;(4)haproxy的设定要求:(a)statspage,要求仅能通过本地访问使用管理接口;(b)动静分离;(c)分别考虑不同的服务器组的调度算...
-
159
README.rst Varnish Cache This is Varnish Cache, the high-performance HTTP accelerator. Documentation and additional information about Varnish is available on
-
58
介绍 keepalived keepalived是一个使用C语言编写的路由软件,设计目的是为Linux系统和基于Linux的虚拟架构提供简单而强大的负载均衡和高可用设施。负载均衡依赖于广泛使用的LIinux虚拟服务器(IPVS)内核模块,提供四层的负载均衡;keepalived实现了一组检查程...
-
89
Varnish反向代理服务器Varnish是一个开源的轻量级Cache和反向代理软件,通常只为http提供缓存,与Squit相比,Varnish具有性能更高、速度更快、管理更方便等优点。Varnish的特点:基于内存进行缓存,重启后数据将丢失利用虚拟内存方式,IO性能好支持设置0-60秒的精...
-
54
VarnishSpy Overview This is a simple client/server that will monitor the varnishncsa stdout for all the urls that are coming into varnish and connected clients will get a listing of the top 50 urls b...
-
37
Notes from the Architect Once you start working with the Varnish source code, you will notice that Varnish is not your average run of the mill application. That is not a coincidence. I have sp...
-
56
README.md varnish-agent varnish-agent提供界面化的配置管理,配置信息保存于etcd中,当配置信息有更新时,自动更新配置并...
-
38
varnish-agent varnish-agent 提供界面化的配置管理,配置信息保存于 etcd 中,当配置信息有更新时,自动更新配置并重新加载,方便多实例的配置管理。 varnish-agent 设置的varnish默...
-
9
Fast charging changed my sad little lifeI hope it makes you very happyThis is adapted from Plugged In, TNW’s bi-weekly newsletter on gear and gadgets.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK