MiniQuark
MiniQuark

Reputation: 48535

When does it make sense to use memcached in a Varnish + ESI architecture?

I'm very new to Varnish, but after reading the documentation, it seems to me that the ESI functionality removes most of the need for a memcached server: a web page can be dynamically constructed from several ESI includes, each of which will be cached appropriately by Varnish (for example, a home page may be built from a fairly static layout that will be cached for a long time, and a more dynamic part with today's news, cached only for a few hours).

I guess that the performance benefit of building a web page out of several parts in Varnish rather than in the App server (using memcached) would probably be great, although I have not tested yet.

Am I missing something? In what case would you recommend still using memcached for Web Page generation? Perhaps as a database cache if multiple Web pages use the same heavy database requests but don't render the results in the same way? Any other idea?

Thanks for your insights.

Upvotes: 0

Views: 369

Answers (1)

Ketola
Ketola

Reputation: 2767

Usually it's the dynamic parts of the pages, i.e. the ones you would be loading through ESI requests, that are the heaviest on the page. That is why you will most likely need to cache the dynamic portions of the page on the App server as well. The static portions of your App are probably quick to load even without Varnish in front.

Whether to use memcached or some other type of caching (for instance a file cache) is pretty much a matter of taste. As always, before starting to cache content you need to profile your queries, optimize them, and make sure indexes are working properly. If some queries are still too heavy and cause significant delays for the first page load, it might be worth the effort to move them to a scheduled task that stores the results in a summary table, and serve the content from there in the App.

In any case you can (and should) cache the ESI includes as well using Varnish, as shown by Varnish wiki:

sub vcl_fetch {
    if (req.url == "/test.html") {
        esi;  /* Do ESI processing */
        set obj.ttl = 24 h;
    } elseif (req.url == "/cgi-bin/date.cgi") {
        set obj.ttl = 1m;
    }
}

Upvotes: 2

Related Questions