Question

I have installed Magento 2.2.0-rc23 and now try to setup varnish FPC.

I generate VCL on BE System -> Advanced -> System -> Full Page Cache -> Varnish Configuration -> Export VCL for Varnish 5.

VCL was mounted to Varnish but during service start I getting the error:

Error:
Message from VCC-compiler:
Symbol not found: 's' (expected type DURATION):
('/etc/varnish/default.vcl' Line 203 Pos 23)
        if (obj.ttl + s > 0s) {
----------------------#--------

Running VCC-compiler failed, exited with 2
VCL compilation failed

Full section

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # Hit within TTL period
        return (deliver);
    }
    if (std.healthy(req.backend_hint)) {
        if (obj.ttl + s > 0s) {
            # Hit after TTL expiration, but within grace period
            set req.http.grace = "normal (healthy server)";
            return (deliver);
        } else {
            # Hit after TTL and grace expiration
            return (fetch);
        }
    } else {
        # server is not healthy, retrieve from cache
        set req.http.grace = "unlimited (unhealthy server)";
        return (deliver);
    }
}

Software:

  • Varnish 5.1.3
  • Magento 2.2.0-rc23

EDIT:

I look for other examples and when we add 0 to s varnish work properly

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # Hit within TTL period
        return (deliver);
    }
    if (std.healthy(req.backend_hint)) {
        if (obj.ttl + 0s > 0s) {
            # Hit after TTL expiration, but within grace period
            set req.http.grace = "normal (healthy server)";
            return (deliver);
        } else {
            # Hit after TTL and grace expiration
            return (fetch);
        }
    } else {
        # server is not healthy, retrieve from cache
        set req.http.grace = "unlimited (unhealthy server)";
        return (deliver);
    }
}
Was it helpful?

Solution

There's a UI nuance that you need to be aware of. When first selecting Varnish as the caching mechanism, you need to Save the config before exporting the VCL.

This action will pre-populate the fields with default values, and exporting the VCL from that point on will not result in an error. Specifically, the line in question will change:

If config is not saved first:

if (obj.ttl + s > 0s) {

If config is saved after Varnish is selected as cache mechanism:

if (obj.ttl + 300s > 0s) {

OTHER TIPS

It's obviously a bug with Magento's VCL generation.

Anyway, you should not use 0s. Use any positive number of seconds, i.e. 60s.

Here is the logic behind this VCL that should help you decide on proper value:

If the request came for a page which has expired from cache no more than "this number" of seconds, serve the stale cache for that page (while fetching new version in the background). Otherwise, fetch new page immediately and return to the client. This might be slow.

Essentially you allow Varnish to serve a slightly old version of the page (as old as x seconds) while refreshing it in the background. This is Varnish performance trick called grace mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top