Why the Varnish cache sucks — with bonus Varnish dev whining about me

Dag-Erling Smørgrav thinks I’m a kook. He’s so convinced of it, he went the extra mile and published it all on the Web.

What’s this about? It’s about a rather unpleasant exchange of e-mails between the developers of Varnish and yours truly. A long tirade of e-mails showing the open source process gone bad. A discussion prompted by technical deficiencies in a product, that quickly turned into the personal and away from the professional.

Warning: technicalities ahead

Now, I apologize in advance because I’m going to dive a bit into technical matters. I must, because if I don’t do this, this entire post would amount to nothing more than unfounded accusatory drivel against the Varnish developers. If I’m going to bash them, at least I’m gonna do it soundly grounded on evidence and proof.

Why it all started

It all started a few days ago, when I was working for a customer who specifically requested an HTTP acceleration strategy for his server. Being that his site gets an average of 1 visit per second (translating into a 15-hits per second cascade on his rather powerful Web server), he was looking into this strategy as one of the alternatives to “make his site run faster”.

Varnish is marketed as an HTTP accelerator, much like Squid’s HTTP accelerator mode. What an HTTP accelerator is supposed to do is (on the surface) rather simple: it sits between the client and the Web server, inspecting HTTP requests and storing “cacheable” requests in a cache. The next time someone requests a file that is on the cache, the HTTP accelerator just serves the file from its cache, avoiding a costly trip to the Web server.

HTTP acceleration is brutally effective when done right. I myself have experienced a cascade of traffic on a rather puny server, which was weathered more or less successfully after a 15-minute outage thanks to the wonderful Squid HTTP accelerator mode. Then someone suggested I try Varnish. And so I did, because it was a reasonable alternative with a couple of unique features useful in their own right.

But Varnish is a useless piece of crap…

Until, of course, I discovered that Varnish, in its default configuration, is useless. My site wasn’t running any faster. My customer’s site wasn’t either. This was a completely out-of-whack, unexpected effect. Whereas I had experienced a tenfold increase in performance with Squid, Varnish was actually slowing our sites down.

It was time to whip out test gear.

[…after a couple hours of mind-numbing testing, reconfigurations and retries…]

And so, I discovered what the problem was. Whenever I tried hitting the Web server with my trusty wget companion, Varnish would work just fine. Whenever I used my Web browser… let’s just say Varnish was just making things slower than before.

In other words: Varnish would outperform the competition on synthetic benchmarks, but actually make the site run slower in real-life usage scenarios.

…because its default caching policy is braindead and useless…

The issue? Cookies. Once our Web sites had set cookies on my browser, Varnish would no longer cache them. In fact, every time a request was made when cookies were sent along, Varnish would just not cache the results.

For those of you who don’t know how cookies work: as soon as any resource on a Web site sets a cookie for the domain, the subsequent elements are requested using that cookie. It doesn’t matter if it’s /index.php or /something.js or /image.png that sets a cookie — all subsequently downloaded elements from the same domain are fed that cookie as well. Since Google Analytics sets the _utma and _utmz cookies on my site, no pages get cached, no images get cached, and no JavaScript scripts get cached.

Let me clear that up again: once a single resource on your site sets a cookie, all subsequent requests for that resource receive that cookie from your browser, until the cookie expires or gets cleared. This is not a crazy idea of mine — test it yourself using Firefox and Firebug — but rather an unfortunate consequence of the cookie system design that almost no one understands.

And, yep, that’s right; the default Varnish configuration does not cache requests with cookies. As you probably are already aware of, all decent medium-to-large Web sites set one or more cookies on their visitors’ browsers (think Google Analytics subscribers, for example). As a result, Varnish caches nothing on those sites. Zilch. Nada.

Picture this: an entire project devoted to providing a new, revolutionary (and admittedly sound) caching architecture… and its end product doesn’t cache shit! Talk about false advertising!

What use could I possibly find, then, for a non-caching cache?

But wait, there’s more: simply configuring Varnish to disregard cookies as caching differentiators doesn’t work, because then it eagerly caches everything, without regard to standard caching policies! So logged-in users experience all sorts of Web site malfunctions, stale pages, and related issues.

Of course, being the evil, malignant hacker that I am, always eager to find misuses of technology, I actually managed to configure Varnish (using complicated logic, pounded out of practically the thin air that Varnish documentation is) to ignore all cookies except for the login cookie. Now visitors on both my site and my customer’s site get cached pages, and logged-in users don’t experience malfunctions. And that was the absolute best compromise I could achieve, because their (utterly limited procedural) configuration language won’t allow for smart caching of static objects vs. serving fresh dynamic ones.

This strut wasn’t without cost: diagnosing and working around the problem took me three hours. Compare that to my Squid experience: fifteen minutes from installation to working cache (and that included wading through the extensive documentation!).

But I got to collect the proceeds from the customer. And my site is sort of functional, again. Who said evil hackery didn’t pay?

…and their developers act like spoiled rock star brats…

I reported this as a bug. In a matter of hours, the bug was nixed, claiming it’s a configuration problem, and diverting me to their mailing list. No engineering effort went into investigating this. And I had to subscribe to one of their lists (yes, yet another list to follow).

I reported this issue to their mailing list. They responded by saying that, basically, I was an abrasive person (they got that right), that I was wrong and deluded, that I had insulted them from the outset (not true until today) and that their software is perfect, since “they have developed it in close relation to real-world experience”.

They spent several e-mails instructing me on how wrong I was, yet never explaining why. That shouldn’t surprise anyone — they can’t possibly expect to explain why I’m wrong, because I’m not.

…and they have the audacity to call me a kook…

Adding further insult to injury, today, Dag-Erling had the audacity to insult me and call me a kook:

We’ve had our share of kooks on the Varnish mailing list. There was one who suggested that Varnish should in fact be a client-side proxy, not a server-side cache (we get the client-side proxy thing a lot, but the bit about throwing out the server-side cache was new), and another who tried to convince us that the features our users are asking for (and paying for) in 2.0 are “of no real use”. A recurring question is the one about how Varnish compares to <insert name of project with which Varnish has aboslutely zero feature overlap>. Recently, we had an unrepentent narcissist who kindly informed us that Varnish is “braindead and stupid”, and that I am a “rude thick-headed and thin-skinned individual” for trying to point out his errors and complaining about his language.

And he finishes his tirade with a particularly ridiculous omen:

In the meantime, all of these exchanges are lovingly archived for posterity by Mailman, Gmane, The Mail Archive and others. Perhaps, as the kooks grow older and wiser, they will come to regret their past indiscretions…

Oh, mighty Dag-Erling, thanks for generously pointing out the errors of my ways. I have been converted by your sacred river of knowledge.

Not.

Please note that the “unrepentent narcissist” link points to my own page. The “rude thick-headed and thin-skinned individual” phrase is mine — I’ll openly admit to it — why wouldn’t I if it weren’t true? According to Dag-Erling, I’m the equivalent of an evil, destructive person; therefore, factual statements I make have no value, because of their source. Notice how he frames the discussion in terms of “me insulting him” — when the truth is, I refrained from anything even close to insulting him up until my last e-mail, where I called him thick-headed and thin-skinned.

Hey, if I wanted to insult him, I could have told him he was a moron. I didn’t. Although in Dag-Erling’s parallel fictional universe, this paragraph could be construed as me insulting him.

The facts: why Varnish sucks (for potential implementors)

Well, Dag-Erling, guess what: I also have a blog, and with a little bit of clout, may I narcissistically remark. And here’s my very biased (yet fully grounded in fact) statement:

  1. Varnish is a remarkable feat of engineering, with the potential to be a much faster replacement for Squid in HTTP accelerator mode.
  2. However, it is muddied by a braindead and stupid configuration default policy and mechanism.
  3. Varnish provides a default configuration that results in a slower site for 99% of the sites out there. Does your site set even a single cookie? You can forget about having it accelerated unless you’re willing to dig deep into the Varnish configuration language.
  4. Varnish’s internal caching mechanism doesn’t obey even the minimum requisite client-side HTTP caching pragmas. It fails to obey other established caching headers, and support for them cannot even be implemented by end users through configuration, because there’s no mechanism to control cache behavior based on Web server HTTP headers — only on client headers. Want to prevent caching of files without an ETag response header? You’re screwed.
  5. The documentation surrounding your project sucks. The manual page for VCL is full of ambiguities, and you haven’t even bothered to provide a state flow diagram for the configuration system.
  6. Varnish refuses to start if your /tmp is mounted noexec. /es, that’s right, Varnish attempts to compile a “shared lib” and load it from /tmp (totally unexpected!). Discovering this was an excruciating experience because the startup script doesn’t give an indication, and the log files don’t either.
  7. The final nail in the coffin is Varnish’s support system. At least Dag-Erling and Poul-Henning Kamp are abrasive thin-skinned individuals who can’t bear others pointing out the deficiencies in his project. Dag-Erling sucks at public relations, and Poul-Henning isn’t that far away either. You see, they’re too busy to actually take a minute to listen to his end-users because they’re always right, so fuck the users.

As it currently stands, I strongly recommend my 1000+-a-day readership against implementing Varnish. You are much better off going with Squid:

  • Its default caching policy is sensible. It automatically caches static objects, whether cookies are sent with requests or not. It detects whether an object is cacheable by the presence of Last-Modified or Expires: headers, and uses an adaptive TTL algorithm much more suited for real-life workloads.
  • Dynamic pages aren’t eagerly cached by Squid. This provides the best mix of cached static content for maximum performance, and freshest content for maximum visitor satisfaction.
  • It’s tested, it’s reliable and it’s been used in multi-million-dollar serve farms, unlike Varnish.

Dag-Erling would like you to buy his propaganda that the Squid caching model is actually a client-side caching model, and tons of other yadda-yadda. And, you know, he might technically even be a bit right. But the bottom line is simple: if you have a dynamic site, Squid makes it go faster out-of-the-box, while Varnish doesn’t… unless you have a resident HTTP expert or many $$$ for hiring someone to set it up for you (hey, by the way, I’m for hire — after all, I did unbreak my Varnish setup sort-of-successfully). The rest of his argument is just a set of irrelevant technicalities.

You can talk architecture all you want; yes, Squid is slower, Varnish is faster. But Squid works, and Varnish is broken.

And that, in my book, is the definition of sucking. Hard.

But, hey, it’s their project. And if they stay on this path, it’ll be irrelevant.

Yes, it’s his software. He has the absolute right to steer the project where he wants. What he doesn’t understand is that contributors (kooks, as he likes to call them) have a right to voice their concerns, and that their input is valuable, no matter how narcissistic (I am) and abrasive (I’m not) their voices may be.

Dag-Erling and Poul-Henning: you’re the newcomers, the new kids on the block, and you have an obligation to excellence if you want to ever be top dogs. I’m sorry to tell you this, but a hard-to-configure HTTP accelerator that doesn’t accelerate by default… well, isn’t even wrong, and it doesn’t earn much respect from me.

Don’t expect to earn your users’ respect with that attitude, punk. Otherwise, tomorrow, when Varnish stops sucking so much, you may not have the clout to put it in the limelight.

Update: straight from the mailing lists — someone else is having the exact same problem I have, with major slowdowns as his penalty. I certainly hope his hacky fix (which is much like my own hacky fix) doesn’t cause his site to malfunction like mine did. That e-mail just confirms everything I said on this post.

Update 2: now Poul-Henning is drumming his own drum, framing me as if I had said that Varnish sucks because it doesn’t do what I want, and he’s the best thing since sliced FreeBSD, and I’m an idiot. Newsflash, Poul-Henning: Varnish doesn’t suck because it doesn’t do what I want — it sucks because it doesn’t do what it should.

Share this article!

  • Digg it!
  • Slashdot it!
  • Share on Facebook
  • Bookmark it!

Sound off!

Write your own

Opinions

  1. Anton Stonor Says:

    My experience with Varnish and its community has been the complete opposite.

    We are now using both Squid and Varnish in production. New sites run Varnish exclusively. Varnish just works for us.

    It is easy to setup and configure, predictable what gets cached and flexible.

    Caching is seldom set up and forget. You often need to apply a policy that tells the caching engine what, when and how long to cache. What I particular like about Varnish is the policy part (the configuration language). You can e.g.:

    • Let all caching be controlled by on http Cache-Control headers if your backend application spits them out

    • Add your caching rules to Varnish if you want to override what your backend says or the backend doesn’t add proper http cache headers.

    • Setup cookie policies, e.g. if your site spits out “innocent” cookies for tracking, you might want to cache, but if it sets cookie to control login sessions you probably won’t (to prevent caching personal content)

    I’ve experienced the Varnish community to be responsive to requests for new features and help.

  2. Poul-Henning Kamp Says:

    You are entitled to your opinion.

    So, of course, are we.

    Have a nice life.

    Poul-Henning

    PS: I don’t think anybody else has called me a newcomer in the last 20 years.

  3. Hasse Johansen Says:
    1. I don’t think you got a clue of who you are calling a newcomer(I’ll suggest google)

    2. Then you are comparing squid which is primarily made to be a reverse proxy(and then add’ed the feature to works as reverse proxy) to varnish which is made to be a reverse proxy. If you should compare something i think you should compare it to nginx or lighhtpd with it reverse proxy

    3. I know several who are using varnish with great success on high traffic sites(as in request per second)

  4. Rudd-O Says:

    Hasse:

    Poul-Henning may be a granddaddy when it comes to BSD, but Varnish doesn’t have 1/5th of the age that Squid does. The newcomer comment stands, don’t nitpick over semantics.

    Anton:

    Caching can be set-and-forget. With my site and Squid, it was.

    Varnish offers no mechanism to alter policy based on Cache-Control headers spit by the backend. It only offers mechanisms to control caching by client headers. See man vcl again.

    I already implemented the “innocent” cookies caching policy on my site. In fact, it’s been implemented for a week now.

    What I want is to implement a real caching policy based on backend headers. Something that will let me set separate policies for static (comes with ETag) and dynamic content (comes with no ETag, but a set of cache-control/expires headers). The Varnish devs already dismissed this request of mine, and followed it up by a comment saying “that’s something that’s yet to come”. It’s probably not as easy to implement as policy configuration based on client headers, but it’s practically a requisite feature for an HTTP acceleration engine.

    There are hundreds of millions of people using Microsoft Windows… does it mean Windows is technically superior? No. The “many sites using Varnish” is no proof that it’s superior. It’s only proof that those sites have a complexity low enough (or an URL architecture twisted around caching policies) that Varnish can effectively cache those sites.

  5. Rudd-O Says:

    But perhaps what angered me the most, and in fact what prompted this blog post, was the reaction from Dag-Erling and Poul-Henning. Which of course, continues, in the form of gratuituous insults.

    Here I go, post a bug report which got almost immediately closed without further inspection, post a couple of questions to the mailing list and what did I get? Nasty ad-hominems. And they have the audacity to claim that I insulted them.

    I guess they reserve their politeness and diplomacy for paying customers — heck, for the money I was getting paid, I could easily have hired one of them expressly for answering questions.

    Radio silence from them would have been better.

  6. Anonymous Says:

    So let me get this straight … you misunderstood what Varnish was supposed to do, insisted on contacting people through the wrong channels, and now you complain that people are not taking you seriously?

  7. Rudd-O Says:

    Anonymous:

    I’m not complaining that people aren’t taking me seriously. Where do you see that? Please point to a paragraph where I complain about that.

    I didn’t misunderstand what Varnish was supposed to do. It’s an HTTP accelerator, it states so on their front page, and yet it doesn’t accelerate sites in its default configuration. Fortunately I now have found (thanks to the fabulous help from ) a couple of VCL hacks that I can apply to actually improve Varnish behavior.

    I contacted people through all the right channels. Bug reports and mailing lists. What other channels are there?

    I gotta love how you misrepresented my entire post in just one sentence.

  8. Diego Says:

    I have worked with varnish since the pre-release alphas on production traffic that is measured in or near 300 million page views per month. The Poul-Henning, the main developer, was nothing but supportive and responsive in bug reports.

    First of all, the bad initial experience was a rightful one. However, the problem is not the software but the default VCL, their default/sample configuration. Just write your own VCL to bypass the if-client-has-cookies-don’t-cache state. They must have their reasons to implement this rule as a default but there is no reason you can’t override it as we have done.

    Varnish is not without faults but is an extremely polished and scalable software for its age. Quite frankly, I’m amazed at the quality of the work thus far.

    To knock on the developers for something that’s not a problem is beyond me.

  9. Rudd-O Says:

    Diego:

    I never said Varnish was bad. If you re-read the article, you’ll see that I said it’s an amazing piece of software. It doesn’t help if you frame the discussion in a surreptitious fashion to make it look like I’m knocking the devs because Varnish is a bad piece of software. That is not true.

    What is true, however, is the poor response I got from the devs, and the lousy default configuration which leads to slowdowns instead of speedups. Caches are supposed to cache static content and deliver fresh dynamic content. By default, Varnish doesn’t do that — it blindly caches everything unless cookies are present, in which case it doesn’t cache anything.

    You tell me how that’s right.

  10. Anonymous Says:

    Neither hold a candle to traffic server. Too bad its not around for the general public

  11. Anonymous Says:

    Neither holds a candle to traffic server. Too bad its not around for the general public

  12. spenser Says:

    To judge the quality of your thought processes, I took the time to read some articles on this site first.

    I am not impressed.

    Whereas, I am impressed by the architecture notes at the varnish site.

    You seem to care more about whining than reading docs.

    Hey, you must be one of those web 2-oh-oh people.

  13. edward Says:

    Is this the picture that tells you squid is better that varnish ?
    http://boom.net/~mike/squid_vs_varnish.GIF
    (from your “Update: straight from the mailing lists” link)

    I believe you need to look at it again.

    And maybe your lack of technical skillz can grow some…

    Sorry - but you realy suck! Just cuz you ain’t got technical foo your
    nagging on other ppl :)
    Thats the way to go right…

    Anyways, Varnish 1.1.1 is out - and I believe your issue is fixed “out
    of the box”.
    Meaning all that you say in your post about “they don’t listen to users”
    is pointing
    you out like the Big Fool - ‘that you are’.

    Or Im I wrong too?

  14. John Buswell Says:

    You might want to take a look at Issue #6 of o3 magazine before you completely dismiss Varnish Cache. Issue 6 provides a less biased look at Varnish Cache, and takes a look at how to configure it! :)

    http://www.o3magazine.com/pastissues/issue6/

    Thanks

  15. Rudd-O Says:

    I read the magazine article. I never claimed the Varnish engine was bad — it’s miles ahead from the competition. Please re-read the article and assess what exactly was that I complained about.

    Edward and Spenser: what’s with the ad hominems? Do you think that I can’t code an application like Varnish? Trust me, if I wanted, I could — coding is easy for me, and I can pick up a programming language in hours. However, I have other things to do, and a Varnish-type app wouldn’t put food on my table.

    As for Varnish beating Squid: what’s new about that? Did I ever even suggest Squid was faster? No. However, I’m going to suggest to the Big Fool that you are (because apparently you can’t interpret what you read) to R-RTFA and STFU.

  16. Enzo Says:

    Here’s my take so far. I just benchmarked Varnish vs. Squid vs. Lighttpd and Lighttpd by itself is faster then either one of those + lighttpd.

    Server is new Dual Quad-Core Intel 2.66ghz, 8gb RAM, 4 x 250gb SATA drives RAID 10.

    Three runs, take the best response time for demo.html page that is 38535 bytes in size. Both
    Varnish & Squid cache set to 1gb in size, though that should matter with just this single page test.

    ab -n 10000 -c 100 -d http://localhost/demo.html

    Varnish + Lighttpd = 9470 requests per second
    Squid + Lighttpd = 3712 requests per second
    Lighttpd alone - 11244 requests per second

    Squid + Lighttpd is dog slow, so I don’t see how or why I would ever use Squid. Lighttpd by itself is nearly 4x faster.

    Varnish could use a better config out of the box, considering there is no caching set out of the box. I’ll keep playing with both Squid & Varnish before deciding which one to deploy in production, but so far Varnish is waaay faster than Squid in my benchmarks. If everything else turns out fine, it will be Varnish all the way.

  17. Colin McCormack Says:

    I installed varnish under Debian, happened to notice the example vcl code which passes through (some) cookies, little light went on, I adapted it to pass through the cookies I need, and got it going without further hassle.

    I also took the opportunity to move all my cookies into a sub-path of the site where they were needed, instead of setting them in the default path of /.

    As far as I can tell, many intermediate proxies and even client-side caches won’t cache something with cookies - confirm this by reference to http://www.mnot.net/cache_docs/ and http://www.mnot.net/cacheability/. So it’s at least arguable that varnish’s behaviour out of the box with respect to cookies is acceptable, within spec.

    Having said that, I came to read this storm-in-a-teacup because I’ve noticed (I think) that ETag varnish behaviour doesn’t seem to be as I’d expect. Varnish doesn’t seem to be forwarding my ETags to the client, which may be a configuration problem of mine, or may be a lack in varnish.

    If it’s true that Varnish doesn’t allow you to make decisions on server-generated fields, that’s something that’d be nice to have. It’d be nice, for example, to be able to use the ETag as varnish’s hash value, can’t see why not. Some of the other things Rudd-O suggests might also be useful.

    I don’t think either side are kooks, I can see there’s a difference in perspective and priorities. Suggest that Rudd-O might have considered contributing patches … nothing speaks louder than patches.

  18. Antibuzz » Archive du blog » Reverse-Proxy de geek Says:

    […] quand même une belle daube Varnish. Et dire que j’utilise ça. Pour rendre ça vaguement compatible avec le […]