[master] 333e6da Finish range delivery processing when the range is delivered.

Martin Blix Grydeland martin at varnish-software.com
Mon Dec 5 13:02:05 CET 2016


commit 333e6da19e8e57ca318d03dd10dcf68ae43ab2b4
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Nov 22 16:38:33 2016 +0100

    Finish range delivery processing when the range is delivered.
    
    When doing range delivery, make the delivery processing finish early
    when all of the bytes of the requested range has been delivered. This
    to avoid waiting around for a slow fetch to finish before handling the
    next request on the connection.
    
    Fixes: #2035

diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index 8b3e0f1..0af1a08 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -80,7 +80,8 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
 	else if (act > VDP_NULL)
 		retval = VDP_bytes(req, act, p, 0);
 	vrg_priv->range_off += len;
-	return (retval);
+	return (retval ||
+	    vrg_priv->range_off >= vrg_priv->range_high ? 1 : 0);
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishtest/tests/r02035.vtc b/bin/varnishtest/tests/r02035.vtc
new file mode 100644
index 0000000..cca0ce4
--- /dev/null
+++ b/bin/varnishtest/tests/r02035.vtc
@@ -0,0 +1,36 @@
+varnishtest "Streaming range early finish"
+
+barrier b1 cond 2
+
+server s1 {
+	non-fatal
+	rxreq
+	txresp -nolen -hdr "Content-Length: 11"
+	# Delay to get around Nagle. Without the delay the body bytes
+	# would be in the same packet as the headers, and would end
+	# up as pipelined data. Pipelined data wouldn't create a streaming
+	# data event, breaking the test case.
+	delay 1
+	send_n 10 "A"
+	# Sema r1 halts the backend thread until client c1 is finished.
+	barrier b1 sync
+	send "B"
+} -start
+
+varnish v1 -vcl+backend {
+} -start
+
+client c1 {
+	txreq -hdr "Range: bytes=0-4"
+	rxresp
+	expect resp.status == 206
+	expect resp.bodylen == 5
+
+	# The client thread should be ready to accept another request:
+	txreq -hdr "Range: bytes=5-9"
+	rxresp
+	expect resp.status == 206
+	expect resp.bodylen == 5
+
+	barrier b1 sync
+} -run



More information about the varnish-commit mailing list