[master] f75b694dc New MAIN.n_pipe gauge

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Apr 15 07:57:07 UTC 2019


commit f75b694dc8453c94a514d6dd2bf2a42a65e2ef61
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Apr 11 19:21:33 2019 +0200

    New MAIN.n_pipe gauge
    
    This allows users to keep track of the number of ongoing pipe
    transactions at any time.

diff --git a/bin/varnishd/VSC_main.vsc b/bin/varnishd/VSC_main.vsc
index 0c22fead5..91d17fc8b 100644
--- a/bin/varnishd/VSC_main.vsc
+++ b/bin/varnishd/VSC_main.vsc
@@ -394,6 +394,11 @@
 	:oneliner:	Total sessions seen
 
 
+.. varnish_vsc:: n_pipe
+	:type:	gauge
+	:oneliner:	Number of ongoing pipe sessions
+
+
 .. varnish_vsc:: s_pipe
 	:group: wrk
 	:oneliner:	Total pipe sessions seen
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 6a367bed7..fd4940167 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -44,6 +44,7 @@
 #include "cache_transport.h"
 
 #include "hash/hash_slinger.h"
+#include "http1/cache_http1.h"
 #include "storage/storage.h"
 #include "common/heritage.h"
 #include "vcl.h"
@@ -704,11 +705,13 @@ cnt_pipe(struct worker *wrk, struct req *req)
 		nxt = REQ_FSM_MORE;
 		break;
 	case VCL_RET_PIPE:
+		XXXAZ(V1P_Enter());
 		AZ(bo->req);
 		bo->req = req;
 		bo->wrk = wrk;
 		SES_Close(req->sp, VDI_Http1Pipe(req, bo));
 		nxt = REQ_FSM_DONE;
+		V1P_Leave();
 		break;
 	default:
 		WRONG("Illegal return from vcl_pipe{}");
diff --git a/bin/varnishd/http1/cache_http1.h b/bin/varnishd/http1/cache_http1.h
index a6558a22f..f642046cf 100644
--- a/bin/varnishd/http1/cache_http1.h
+++ b/bin/varnishd/http1/cache_http1.h
@@ -50,6 +50,8 @@ struct v1p_acct {
 	uint64_t        out;
 };
 
+int V1P_Enter(void);
+void V1P_Leave(void);
 void V1P_Process(const struct req *, int fd, struct v1p_acct *);
 void V1P_Charge(struct req *, const struct v1p_acct *, struct VSC_vbe *);
 
diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c
index 224298b01..b3c6e6e25 100644
--- a/bin/varnishd/http1/cache_http1_pipe.c
+++ b/bin/varnishd/http1/cache_http1_pipe.c
@@ -62,6 +62,26 @@ rdf(int fd0, int fd1, uint64_t *pcnt)
 	return (0);
 }
 
+int
+V1P_Enter(void)
+{
+
+	Lck_Lock(&pipestat_mtx);
+	VSC_C_main->n_pipe++;
+	Lck_Unlock(&pipestat_mtx);
+	return (0);
+}
+
+void
+V1P_Leave(void)
+{
+
+	Lck_Lock(&pipestat_mtx);
+	assert(VSC_C_main->n_pipe > 0);
+	VSC_C_main->n_pipe--;
+	Lck_Unlock(&pipestat_mtx);
+}
+
 void
 V1P_Charge(struct req *req, const struct v1p_acct *a, struct VSC_vbe *b)
 {
diff --git a/bin/varnishtest/tests/v00059.vtc b/bin/varnishtest/tests/v00059.vtc
new file mode 100644
index 000000000..0cb4dc868
--- /dev/null
+++ b/bin/varnishtest/tests/v00059.vtc
@@ -0,0 +1,55 @@
+varnishtest "n_pipe gauge"
+
+barrier b1 cond 2
+barrier b2 cond 2
+barrier b3 cond 2
+barrier b4 cond 2
+
+server s1 {
+	rxreq
+	barrier b1 sync
+	barrier b2 sync
+	txresp
+} -start
+
+server s2 {
+	rxreq
+	barrier b3 sync
+	barrier b4 sync
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		if (req.url == "/c1") {
+			set req.backend_hint = s1;
+		}
+		elsif (req.url == "/c2") {
+			set req.backend_hint = s2;
+		}
+		return (pipe);
+	}
+} -start
+
+varnish v1 -expect MAIN.n_pipe == 0
+
+client c1 {
+	txreq -url "/c1"
+	rxresp
+} -start
+
+barrier b1 sync
+
+varnish v1 -expect MAIN.n_pipe == 1
+
+client c2 {
+	txreq -url "/c2"
+	rxresp
+} -start
+
+barrier b3 sync
+varnish v1 -expect MAIN.n_pipe == 2
+barrier b2 sync
+varnish v1 -expect MAIN.n_pipe == 1
+barrier b4 sync
+varnish v1 -expect MAIN.n_pipe == 0


More information about the varnish-commit mailing list