[master] 4830d6b Make transaction limit and timeout into cmd line options

Martin Blix Grydeland martin at varnish-cache.org
Thu Oct 3 14:00:41 CEST 2013


commit 4830d6b9cbfc4b48c43702fa3f80e6372b69d96c
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Oct 3 10:36:29 2013 +0200

    Make transaction limit and timeout into cmd line options

diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index add96b4..1c1df7c 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -38,11 +38,13 @@ VUT_OPT_D
 VSL_OPT_g
 VSL_OPT_i
 VSL_OPT_I
+VSL_OPT_L
 VSM_OPT_n
 VSM_OPT_N
 VUT_OPT_P
 VUT_OPT_q
 VSL_OPT_r
+VSL_OPT_T
 VSL_OPT_u
 VSL_OPT_v
 VSL_OPT_w
diff --git a/include/vapi/vapi_options.h b/include/vapi/vapi_options.h
index fae7fdd..344b3ed 100644
--- a/include/vapi/vapi_options.h
+++ b/include/vapi/vapi_options.h
@@ -95,11 +95,29 @@
 	    VSL_iI_PS							\
 	)
 
+#define VSL_OPT_L							\
+	VOPT("L:", "[-L limit]", "Incomplete transaction limit",	\
+	    "Sets the upper limit of incomplete transactions kept"	\
+	    " before the oldest transaction is force completed. A"	\
+	    " warning record is synthesized when this happens. This"	\
+	    " setting keeps an upper bound on the memory usage of"	\
+	    " running queries. Defaults to 1000 transactions."		\
+	)
+
 #define VSL_OPT_r							\
 	VOPT("r:", "[-r filename]", "Binary file input",		\
 	    "Read log in binary file format from this file."		\
 	)
 
+#define VSL_OPT_T							\
+	VOPT("T:", "[-T seconds]", "Transaction end timeout",		\
+	    "Sets the transaction timeout in seconds. This defines the"	\
+	    " maximum number of seconds elapsed between a Begin tag"	\
+	    " and the End tag. If the timeout expires, a warning"	\
+	    " record is synthesized and the transaction is force"	\
+	    " completed. Defaults to 120 seconds."			\
+	)
+
 #define VSL_OPT_u							\
 	VOPT("u", "[-u]", "Binary file output unbuffered",		\
 	    "Unbuffered binary file output mode."			\
diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c
index 93e731a..7c5dafa 100644
--- a/lib/libvarnishapi/vsl.c
+++ b/lib/libvarnishapi/vsl.c
@@ -91,6 +91,8 @@ VSL_New(void)
 	if (vsl == NULL)
 		return (NULL);
 
+	vsl->L_opt = 1000;
+	vsl->T_opt = 120.;
 	vsl->vbm_select = vbit_init(SLT__MAX);
 	vsl->vbm_supress = vbit_init(SLT__MAX);
 	VTAILQ_INIT(&vsl->vslf_select);
diff --git a/lib/libvarnishapi/vsl_api.h b/lib/libvarnishapi/vsl_api.h
index 53984c3..40e3438 100644
--- a/lib/libvarnishapi/vsl_api.h
+++ b/lib/libvarnishapi/vsl_api.h
@@ -90,6 +90,8 @@ struct VSL_data {
 
 	int				b_opt;
 	int				c_opt;
+	int				L_opt;
+	double				T_opt;
 	int				v_opt;
 };
 
diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c
index dad558d..9370ed9 100644
--- a/lib/libvarnishapi/vsl_arg.c
+++ b/lib/libvarnishapi/vsl_arg.c
@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <limits.h>
 
 #include "miniobj.h"
 #include "vas.h"
@@ -312,6 +313,9 @@ int
 VSL_Arg(struct VSL_data *vsl, int opt, const char *arg)
 {
 	int i;
+	char *p;
+	double d;
+	long l;
 
 	CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
 	/* If first option is 'i', set all bits for supression */
@@ -324,6 +328,26 @@ VSL_Arg(struct VSL_data *vsl, int opt, const char *arg)
 	case 'c': vsl->c_opt = 1; return (1);
 	case 'i': case 'x': return (vsl_ix_arg(vsl, opt, arg));
 	case 'I': case 'X': return (vsl_IX_arg(vsl, opt, arg));
+	case 'L':
+		l = strtol(arg, &p, 0);
+		while (isspace(*p))
+			p++;
+		if (*p != '\0')
+			return (vsl_diag(vsl, "-L: Syntax error"));
+		if (l < 0 || l > INT_MAX)
+			return (vsl_diag(vsl, "-L: Range error"));
+		vsl->L_opt = (int)l;
+		return (1);
+	case 'T':
+		d = strtod(arg, &p);
+		while (isspace(*p))
+			p++;
+		if (*p != '\0')
+			return (vsl_diag(vsl, "-P: Syntax error"));
+		if (d < 0.)
+			return (vsl_diag(vsl, "-L: Range error"));
+		vsl->T_opt = d;
+		return (1);
 	case 'v': vsl->v_opt = 1; return (1);
 	default:
 		return (0);
diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c
index b6d77ff..db92c7f 100644
--- a/lib/libvarnishapi/vsl_dispatch.c
+++ b/lib/libvarnishapi/vsl_dispatch.c
@@ -1009,9 +1009,7 @@ VSLQ_Dispatch(struct VSLQ *vslq, VSLQ_dispatch_f *func, void *priv)
 
 	now = VTIM_mono();
 	while ((vtx = VTAILQ_FIRST(&vslq->incomplete)) &&
-	    now - vtx->t_start > 120.) {
-		/* XXX: Make timeout configurable through options and
-		   provide a sane default */
+	    now - vtx->t_start > vslq->vsl->T_opt) {
 		AZ(vtx->flags & VTX_F_COMPLETE);
 		vtx = vtx_force(vslq, vtx, "incomplete - timeout");
 		if (vtx) {
@@ -1026,9 +1024,7 @@ VSLQ_Dispatch(struct VSLQ *vslq, VSLQ_dispatch_f *func, void *priv)
 	if (i)
 		return (i);
 
-	while (vslq->n_incomplete > 1000) {
-		/* XXX: Make limit configurable through options and
-		   provide a sane default */
+	while (vslq->n_incomplete > vslq->vsl->L_opt) {
 		vtx = VTAILQ_FIRST(&vslq->incomplete);
 		AN(vtx);
 		AZ(vtx->flags & VTX_F_COMPLETE);



More information about the varnish-commit mailing list