Created
July 3, 2018 19:48
-
-
Save rezan/5fce9cc520d01f636bb7c9bf91cdb8d0 to your computer and use it in GitHub Desktop.
Use aggregate.vcl to get the true response time in VCL for slow responses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| varnishtest "Test using Varnish to aggregate headers and body" | |
| server s1 { | |
| rxreq | |
| expect req.url == "/1" | |
| txresp -nolen -hdr "Content-Length: 3" | |
| delay 3 | |
| send "abc" | |
| rxreq | |
| expect req.url == "/2" | |
| txresp -nolen -hdr "Content-Length: 3" | |
| delay 3 | |
| send "123" | |
| } -start | |
| varnish v1 -arg "-a ${s1_addr}:18089" -vcl+backend { | |
| # Point loop back to this VTC | |
| backend loop { | |
| .host = "${s1_addr}"; | |
| .port = "18089"; | |
| } | |
| import std; | |
| include "aggregate.vcl"; | |
| sub vcl_recv { | |
| if (req.url == "/2") { | |
| set req.http.X-aggregate = "true"; | |
| } | |
| } | |
| sub vcl_backend_fetch { | |
| set bereq.http.X-start = now; | |
| } | |
| sub vcl_backend_response { | |
| set beresp.http.X-start = bereq.http.X-start; | |
| set beresp.http.X-end = now; | |
| set beresp.http.X-diff = std.time(beresp.http.X-end, now) - std.time(beresp.http.X-start, now); | |
| } | |
| } -start | |
| client c1 { | |
| # No aggregation, VCL cannot detect response time | |
| txreq -url "/1" | |
| rxresp | |
| expect resp.status == 200 | |
| expect resp.http.X-diff == "0.000" | |
| expect resp.body == "abc" | |
| # Aggregation, VCL can time complete response | |
| txreq -url "/2" | |
| rxresp | |
| expect resp.status == 200 | |
| expect resp.http.X-diff == "3.000" | |
| expect resp.body == "123" | |
| } -run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment