Jaap van Arragon
Jaap van Arragon

Reputation: 31

varnish serve old object during refresh

How can I serve an old object during the fetch of an expired object or max out connection?

I¹ve configured the grace period in both the vcl_recv as the vcl_fetch.

I even tried to use the saint mode to give me back an ³old² cached object.

Can somebody give me help in this matter?

sub vcl_recv {

# Purge through http
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
ban("req.url ~ " + req.url );
error 200 "Purged.";
}

# Unset all cookies available
if (req.http.cookie) {
unset req.http.cookie;
}

if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}

# Adding Grace period in case backend lags
set req.grace = 3d;
return (lookup);
}
....
sub vcl_fetch {
set beresp.grace = 4d;
set beresp.saintmode = 50s;
set beresp.ttl = 30s;
return (deliver);
}
#### CACHE REQUEST VARNISHLOG
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"
11 SessionOpen  c XXX.XXX.XXX.XXX 60750 XXX.XXX.XXX.XXX:2002
11 ReqStart     c XXX.XXX.XXX.XXX 60750 479090107
11 RxRequest    c GET
11 RxURL        c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 RxProtocol   c HTTP/1.0
11 RxHeader     c Host: URL
11 RxHeader     c X-Real-IP: XXX.XXX.XXX.XXX
11 RxHeader     c X-Forwarded-For: XXX.XXX.XXX.XXX
11 RxHeader     c Connection: close
11 RxHeader     c User-Agent: GraphicalHttpClient 1.0.6 (Macintosh; Mac OS X 10.6.8; en_NL)
11 VCL_call     c recv lookup
11 VCL_call     c hash
11 Hash         c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 Hash         c URL
11 VCL_return   c hash
11 Hit          c 479090015
11 VCL_call     c hit deliver
11 VCL_call     c deliver deliver
11 TxProtocol   c HTTP/1.1
11 TxStatus     c 200
11 TxResponse   c OK
11 TxHeader     c Server: nginx/1.0.11
11 TxHeader     c Content-Type: image/jpeg
11 TxHeader     c Content-Transfer-Encoding: binary
11 TxHeader     c Cache-Control: must-revalidate
11 TxHeader     c Content-Length: 125395
11 TxHeader     c Accept-Ranges: bytes
11 TxHeader     c Date: Tue, 07 Feb 2012 14:23:00 GMT
11 TxHeader     c X-Varnish: 479090107 479090015
11 TxHeader     c Age: 5693
11 TxHeader     c Via: 1.1 varnish
11 TxHeader     c Connection: close
11 Length       c 125395
11 ReqEnd       c 479090107 1328624580.355833769 1328624580.357449532 0.000084162 0.000103474 0.001512289
11 SessionClose c Connection: close
11 StatSess     c XXX.XXX.XXX.XXX 60750 0 1 1 0 0 0 29
#### CACHE REQUEST EXPIRED VARNISHLOG
12 BackendOpen  b live XXX.XXX.XXX.XXX 41945 XXX.XXX.XXX.XXX 80
12 TxRequest    b GET
12 TxURL        b /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
12 TxProtocol   b HTTP/1.1
12 TxHeader     b Host: URL
12 TxHeader     b X-Real-IP: XXX.XXX.XXX.XXX
12 TxHeader     b X-Forwarded-For: XXX.XXX.XXX.XXX
12 TxHeader     b User-Agent: GraphicalHttpClient 1.0.6 (Macintosh; Mac OS X 10.6.8; en_NL)
12 TxHeader     b X-Varnish: 479090118
12 TxHeader     b Accept-Encoding: gzip
12 RxProtocol   b HTTP/1.1
12 RxStatus     b 200
12 RxResponse   b OK
12 RxHeader     b Server: nginx/1.0.11
12 RxHeader     b Date: Tue, 07 Feb 2012 14:26:00 GMT
12 RxHeader     b Content-Type: image/jpeg
12 RxHeader     b Connection: keep-alive
12 RxHeader     b Content-Transfer-Encoding: binary
12 RxHeader     b Cache-Control: must-revalidate
12 RxHeader     b Content-Length: 125395
12 Fetch_Body   b 4(length) cls 0 mklen 1
12 Length       b 125395
12 BackendReuse b live
11 SessionOpen  c XXX.XXX.XXX.XXX 50429 XXX.XXX.XXX.XXX:2002
11 ReqStart     c XXX.XXX.XXX.XXX 50429 479090118
11 RxRequest    c GET
11 RxURL        c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 RxProtocol   c HTTP/1.0
11 RxHeader     c Host: URL
11 RxHeader     c X-Real-IP: XXX.XXX.XXX.XXX
11 RxHeader     c X-Forwarded-For: XXX.XXX.XXX.XXX
11 RxHeader     c Connection: close
11 RxHeader     c User-Agent: GraphicalHttpClient 1.0.6 (Macintosh; Mac OS X 10.6.8; en_NL)
11 VCL_call     c recv lookup
11 VCL_call     c hash
11 Hash         c /image/1156499/1601812475/45010cb14311wq1fd2da042ed599f3ad917005085c400/1181_615/crop
11 Hash         c URL
11 VCL_return   c hash
11 VCL_call     c miss fetch
11 Backend      c 12 live live
11 TTL          c 479090118 RFC 120 -1 -1 1328624761 0 1328624760 0 0
11 VCL_call     c fetch
11 TTL          c 479090118 VCL 33 -1 -1 1328624758 -3
11 TTL          c 479090118 VCL 33 40 -1 1328624758 -3
11 VCL_return   c deliver
11 ObjProtocol  c HTTP/1.1
11 ObjResponse  c OK
11 ObjHeader    c Server: nginx/1.0.11
11 ObjHeader    c Date: Tue, 07 Feb 2012 14:26:00 GMT
11 ObjHeader    c Content-Type: image/jpeg
11 ObjHeader    c Content-Transfer-Encoding: binary
11 ObjHeader    c Cache-Control: must-revalidate
11 VCL_call     c deliver deliver
11 TxProtocol   c HTTP/1.1
11 TxStatus     c 200
11 TxResponse   c OK
11 TxHeader     c Server: nginx/1.0.11
11 TxHeader     c Content-Type: image/jpeg
11 TxHeader     c Content-Transfer-Encoding: binary
11 TxHeader     c Cache-Control: must-revalidate
11 TxHeader     c Content-Length: 125395
11 TxHeader     c Accept-Ranges: bytes
11 TxHeader     c Date: Tue, 07 Feb 2012 14:26:00 GMT
11 TxHeader     c X-Varnish: 479090118
11 TxHeader     c Age: 0
11 TxHeader     c Via: 1.1 varnish
11 TxHeader     c Connection: close
11 Length       c 125395
11 ReqEnd       c 479090118 1328624757.532856941 1328624760.899299860 0.000095606 3.364968061 0.001474857
11 SessionClose c Connection: close
11 StatSess     c XXX.XXX.XXX.XXX 50429 3 1 1 0 0 1 284 125395
0 Debug        - "lurker: 0x7f244cfd1e00 30 0"

Upvotes: 2

Views: 1882

Answers (1)

Tamil
Tamil

Reputation: 5358

This is an interesting question.

From DOC

When several clients are requesting the same page Varnish will send one request to the backend and place the others on hold while fetching one copy from the back end.

So, at any point in time there will be one client blocked even if you had enabled grace. Grace informs Varnish that you can serve all other n-1 clients with stale content until the first guy comes back with some content to refresh. There is no way to unblock that one guy [technically asynchronous fetch is not possible as such]

Check out this nice article I think what you are actually asking for is a planned feature for next release I hope

Upvotes: 3

Related Questions