[master] 91a16493f add a trivial VRT_priv_task benchmark

Nils Goroll nils.goroll at uplex.de
Wed Oct 31 11:51:12 UTC 2018


commit 91a16493fa9fa2536278ce957a1769bf317e056a
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Oct 31 12:35:55 2018 +0100

    add a trivial VRT_priv_task benchmark

diff --git a/bin/varnishtest/tests/v00041.vtc b/bin/varnishtest/tests/v00041.vtc
index a67928ca9..533f7d246 100644
--- a/bin/varnishtest/tests/v00041.vtc
+++ b/bin/varnishtest/tests/v00041.vtc
@@ -10,7 +10,7 @@ server s1 {
 	txresp
 } -start
 
-varnish v1 -arg "-p debug=+vclrel" -vcl+backend {
+varnish v1 -arg "-p debug=+vclrel -p workspace_client=1m" -vcl+backend {
 	import debug;
 	import std;
 
@@ -26,11 +26,24 @@ varnish v1 -arg "-p debug=+vclrel" -vcl+backend {
 	}
 
 	sub vcl_recv {
+		if (req.url == "/perf") {
+			return (synth(200));
+		}
 		debug.test_priv_task(req.url);
 		set req.http.x0 = debug.test_priv_task();
 		debug.test_priv_task("bazz");
 	}
 
+	sub vcl_synth {
+		std.log("discard 100 " + debug.priv_perf(100));
+		std.log("perf    1 " + debug.priv_perf(1));
+		std.log("perf   10 " + debug.priv_perf(10));
+		std.log("perf  100 " + debug.priv_perf(100));
+		## unbearable with the list implementation - ok with rb tree
+		# std.log("perf 1000 " + debug.priv_perf(1000));
+		return (deliver);
+	}
+
 	sub vcl_deliver {
 		set resp.http.x0 = req.http.x0;
 		set resp.http.x1 = debug.test_priv_task();
@@ -109,6 +122,9 @@ client c1 {
 	expect resp.http.bx0 == "b /snafu"
 	expect resp.http.bx1 == "b /snafu"
 	expect resp.http.bo1 == "b /snafu"
+
+	txreq -url /perf
+	rxresp
 } -run
 
 shell "echo 'vcl 4.0; backend foo { .host = \"${s1_addr}\"; .port = \"${s1_port}\"; }' > ${tmpdir}/_b00014.vcl"
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index fecf9b150..ad24840da 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -201,3 +201,14 @@ Return the string formed by concatenating the given strings.
 $Function VOID sethdr(HEADER, STRANDS)
 
 Set the given header with the concatenation of the given strings.
+
+$Function DURATION priv_perf(INT size, INT rounds=10000)
+
+Benchmark VRT_priv_task() with `size` elements, iterating `rounds`
+times.
+
+Returns the average time taken for each call scaled up from nanoseconds
+to seconds - iow the value given as seconds is actually the duration
+in nanoseconds.
+
+For comparable results, a higher size run should called first and discarded.
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index a3a78975a..3a76f6c7e 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -552,3 +552,42 @@ xyzzy_sethdr(VRT_CTX, VCL_HEADER hs, VCL_STRANDS s)
 		}
 	}
 }
+
+VCL_DURATION
+xyzzy_priv_perf(VRT_CTX, VCL_INT size, VCL_INT rounds)
+{
+	vtim_mono t0, t1;
+	vtim_dur d;
+	struct vmod_priv *p;
+	VCL_INT s, r;
+	uintptr_t check = 0;
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+	for (s = 1; s <= size; s++) {
+		p = VRT_priv_task(ctx, (void *)s);
+		if (p == NULL) {
+			VRT_fail(ctx, "no priv task - out of ws?");
+			return (-1.0);
+		}
+		p->priv = NULL;
+	}
+
+	t0 = VTIM_mono();
+	for (r = 0; r < rounds; r++) {
+		for (s = 1; s <= size; s++) {
+			p = VRT_priv_task(ctx, (void *)s);
+			check += (uintptr_t)p->priv;
+			p->priv = (void *)(uintptr_t)(s * rounds + r);
+		}
+	}
+	t1 = VTIM_mono();
+
+	d = (t1 - t0) * 1e9 / size / rounds;
+
+	VSLb(ctx->vsl, SLT_Debug,
+	     "perf size %ld rounds %ld time %.9fns check %ld",
+	     size, rounds, d, check);
+
+	return (d);
+}


More information about the varnish-commit mailing list