[experimental-ims] b762016 Give struct req its own buffer for batching VSL records

Geoff Simmons geoff at varnish-cache.org
Tue Feb 14 17:49:35 CET 2012


commit b7620169552e638771676df2f57749657cf12f0b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 14 08:02:41 2012 +0000

    Give struct req its own buffer for batching VSL records
    
    Size controlled by param vsl_buffer which will replace shm_workspace.
    The space comes out of request workspace.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ad23c24..d9d9f48 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -248,6 +248,7 @@ struct exp {
 struct vsl_log {
 	uint32_t		*wlb, *wlp, *wle;
 	unsigned		wlr;
+	unsigned		wid;
 };
 
 /*--------------------------------------------------------------------*/
@@ -615,6 +616,9 @@ struct req {
 	/* First byte of storage if we free it as we go (pass) */
 	ssize_t			stream_front;
 
+	/* Transaction VSL buffer */
+	struct vsl_log		vsl[1];
+
 };
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 196cead..1bd74fe 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -318,7 +318,7 @@ SES_GetReq(struct sess *sp)
 	struct sesspool *pp;
 	uint16_t nhttp;
 	unsigned sz, hl;
-	char *p;
+	char *p, *e;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	pp = sp->sesspool;
@@ -330,27 +330,38 @@ SES_GetReq(struct sess *sp)
 	AN(sp->req);
 	sp->req->magic = REQ_MAGIC;
 
+	e = (char*)sp->req + sz;
 	p = (char*)(sp->req + 1);
-	sz -= sizeof *sp->req;
+	p = (void*)PRNDUP(p);
+	assert(p < e);
 
 	nhttp = (uint16_t)cache_param->http_max_hdr;
 	hl = HTTP_estimate(nhttp);
 
-	xxxassert(sz > 3 * hl + 128);
-
 	sp->req->http = HTTP_create(p, nhttp);
-	p += hl;		// XXX: align ?
-	sz -= hl;
+	p += hl;
+	p = (void*)PRNDUP(p);
+	assert(p < e);
 
 	sp->req->http0 = HTTP_create(p, nhttp);
-	p += hl;		// XXX: align ?
-	sz -= hl;
+	p += hl;
+	p = (void*)PRNDUP(p);
+	assert(p < e);
 
 	sp->req->resp = HTTP_create(p, nhttp);
-	p += hl;		// XXX: align ?
-	sz -= hl;
+	p += hl;
+	p = (void*)PRNDUP(p);
+	assert(p < e);
+
+	sz = cache_param->workspace_thread;
+	VSL_Setup(sp->req->vsl, p, sz);
+	sp->req->vsl->wid = sp->vsl_id;
+	p += sz;
+	p = (void*)PRNDUP(p);
+
+	assert(p < e);
 
-	WS_Init(sp->req->ws, "req", p, sz);
+	WS_Init(sp->req->ws, "req", p, e - p);
 }
 
 void
@@ -364,6 +375,7 @@ SES_ReleaseReq(struct sess *sp)
 	AN(pp->pool);
 	CHECK_OBJ_NOTNULL(sp->req, REQ_MAGIC);
 	MPL_AssertSane(sp->req);
+	WSL_Flush(sp->req->vsl, 0);
 	MPL_Free(pp->mpl_req, sp->req);
 	sp->req = NULL;
 }
diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h
index 7694435..916fad8 100644
--- a/bin/varnishd/common/params.h
+++ b/bin/varnishd/common/params.h
@@ -78,6 +78,8 @@ struct params {
 	unsigned		workspace_backend;
 	unsigned		workspace_thread;
 
+	unsigned		vsl_buffer;
+
 	unsigned		shm_workspace;
 	unsigned		http_req_size;
 	unsigned		http_req_hdr_len;
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index e2e1a3a..475806d 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -766,6 +766,18 @@ static const struct parspec input_parspec[] = {
 		"objects allocate exact space for the headers they store.\n",
 		0,
 		"64", "header lines" },
+	{ "vsl_buffer",
+		tweak_bytes_u, &mgt_param.vsl_buffer, 1024, UINT_MAX,
+		"Bytes of (req-/backend-)workspace dedicated to buffering"
+		" VSL records.\n"
+		"At a bare minimum, this must be longer than"
+		" the longest HTTP header to be logged.\n"
+		"Setting this too high costs memory, setting it too low"
+		" will cause more VSL flushes and likely increase"
+		" lock-contention on the VSL mutex.\n"
+		"Minimum is 1k bytes.",
+		0,
+		"4k", "bytes" },
 	{ "shm_workspace",
 		tweak_bytes_u, &mgt_param.shm_workspace, 4096, UINT_MAX,
 		"Bytes of shmlog workspace allocated for worker threads. "



More information about the varnish-commit mailing list