r393 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Jul 10 10:41:27 CEST 2006


Author: phk
Date: 2006-07-10 10:41:26 +0200 (Mon, 10 Jul 2006)
New Revision: 393

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Add heritage.mem_http_headers which is the maximum number of headers
we recognize.

Add http_Init() which initializes struct http given sufficient space.

Respect heritage mem_* values in http_New() (while we still have it)

Allocate backend connections (vbe_conn) with super allocation with
space for http and workspace.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-10 08:10:30 UTC (rev 392)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-10 08:41:26 UTC (rev 393)
@@ -42,8 +42,8 @@
 	char			*status;
 	char			*response;
 	
+	unsigned		nhdr;
 	char			**hdr;
-	unsigned		nhdr;
 };
 
 /*--------------------------------------------------------------------*/
@@ -61,10 +61,12 @@
 
 struct vbe_conn {
 	TAILQ_ENTRY(vbe_conn)	list;
+	struct vbc_mem		*vbcm;
 	struct vbe		*vbe;
 	int			fd;
 	struct event		ev;
 	int			inuse;
+	struct http		*http;
 };
 
 /* Storage -----------------------------------------------------------*/
@@ -207,6 +209,7 @@
 void HSH_Init(void);
 
 /* cache_http.c */
+void http_Init(struct http *ht, void *space);
 struct http *http_New(void);
 void http_Delete(struct http *hp);
 int http_GetHdr(struct http *hp, const char *hdr, char **ptr);

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2006-07-10 08:10:30 UTC (rev 392)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2006-07-10 08:41:26 UTC (rev 393)
@@ -36,9 +36,16 @@
 #include <sys/ioctl.h>
 
 #include "libvarnish.h"
+#include "heritage.h"
 #include "shmlog.h"
 #include "cache.h"
 
+struct vbc_mem {
+	struct vbe_conn		vbe;
+	struct http		http;
+	char			*http_hdr;
+};
+
 /* A backend IP */
 
 struct vbe {
@@ -57,6 +64,36 @@
 static struct event_base *vbe_evb;
 static int vbe_pipe[2];
 
+/*--------------------------------------------------------------------*/
+
+static struct vbe_conn *
+vbe_new_conn(void)
+{
+	struct vbc_mem *vbcm;
+
+	vbcm = calloc(
+	    sizeof *vbcm +
+	    heritage.mem_http_headers * sizeof vbcm->http_hdr +
+	    heritage.mem_http_headerspace +
+	    heritage.mem_workspace,
+	    1);
+	if (vbcm == NULL)
+		return (NULL);
+	VSL_stats->n_vbe_conn++;
+	vbcm->vbe.vbcm = vbcm;
+	vbcm->vbe.http = &vbcm->http;
+	http_Init(&vbcm->http, (void *)(vbcm + 1));
+	return (&vbcm->vbe);
+}
+
+static void
+vbe_delete_conn(struct vbe_conn *vb)
+{
+
+	VSL_stats->n_vbe_conn--;
+	free(vb->vbcm);
+}
+
 /*--------------------------------------------------------------------
  * XXX: we should not call getaddrinfo() every time, we should cache
  * and apply round-robin with blacklisting of entries that do not respond
@@ -128,8 +165,7 @@
 	TAILQ_REMOVE(&vc->vbe->bconn, vc, list);
 	if (vc->fd < 0) {
 		vc->vbe->nconn--;
-		free(vc);
-		VSL_stats->n_vbe_conn--;
+		vbe_delete_conn(vc);
 	} else {
 		vc->inuse = 0;
 		event_add(&vc->ev, NULL);
@@ -165,8 +201,7 @@
 	AZ(pthread_mutex_unlock(&vbemtx));
 	event_del(&vc->ev);
 	close(vc->fd);
-	free(vc);
-	VSL_stats->n_vbe_conn--;
+	vbe_delete_conn(vc);
 }
 
 /* Backend monitoring thread -----------------------------------------*/
@@ -217,7 +252,6 @@
 	if (vp == NULL) {
 		vp = calloc(sizeof *vp, 1);
 		assert(vp != NULL);
-		VSL_stats->n_vbe++;
 		TAILQ_INIT(&vp->fconn);
 		TAILQ_INIT(&vp->bconn);
 		vp->ip = bp->ip;
@@ -232,14 +266,16 @@
 		TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
 		AZ(pthread_mutex_unlock(&vbemtx));
 	} else {
-		vc = calloc(sizeof *vc, 1);
-		VSL_stats->n_vbe_conn++;
-		assert(vc != NULL);
+		vc = vbe_new_conn();
+		if (vc == NULL) {
+			AZ(pthread_mutex_unlock(&vbemtx));
+			return (NULL);
+		}
+		vp->nconn++;
 		vc->vbe = vp;
 		vc->fd = -1;
 		vc->inuse = 1;
 		TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
-		vp->nconn++;
 		AZ(pthread_mutex_unlock(&vbemtx));
 		connect_to_backend(vc, bp);
 		if (vc->fd < 0) {
@@ -247,16 +283,15 @@
 			TAILQ_REMOVE(&vc->vbe->bconn, vc, list);
 			vp->nconn--;
 			AZ(pthread_mutex_unlock(&vbemtx));
-			free(vc);
-			vc = NULL;
-		} else {
-			VSL_stats->backend_conn++;
-			event_set(&vc->ev, vc->fd, EV_READ | EV_PERSIST, vbe_rdf, vc);
-			event_base_set(vbe_evb, &vc->ev);
+			vbe_delete_conn(vc);
+			return (NULL);
 		}
+		VSL_stats->backend_conn++;
+		event_set(&vc->ev, vc->fd,
+		    EV_READ | EV_PERSIST, vbe_rdf, vc);
+		event_base_set(vbe_evb, &vc->ev);
 	}
-	if (vc != NULL)
-		VSL(SLT_BackendXID, vc->fd, "%u", xid);
+	VSL(SLT_BackendXID, vc->fd, "%u", xid);
 	return (vc);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-10 08:10:30 UTC (rev 392)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-10 08:41:26 UTC (rev 393)
@@ -13,11 +13,23 @@
 
 #include "libvarnish.h"
 #include "shmlog.h"
+#include "heritage.h"
 #include "cache.h"
 
-static unsigned		http_bufsize	= 4096;
-static unsigned		http_nhdr	= 128;
+/*--------------------------------------------------------------------*/
 
+void
+http_Init(struct http *hp, void *space)
+{
+	char *sp = space;
+
+	memset(hp, 0, sizeof *hp);
+	hp->hdr = (void *)sp;
+	sp += heritage.mem_http_headers * sizeof hp->hdr;
+	hp->s = sp;
+	hp->e = hp->s + heritage.mem_http_headerspace;
+}
+
 /*--------------------------------------------------------------------*/
 
 struct http *
@@ -29,14 +41,14 @@
 	assert(hp != NULL);
 	VSL_stats->n_http++;
 
-	hp->s = malloc(http_bufsize);
+	hp->s = malloc(heritage.mem_http_headerspace);
 	assert(hp->s != NULL);
 
-	hp->e = hp->s + http_bufsize;
+	hp->e = hp->s + heritage.mem_http_headerspace;
 	hp->v = hp->s;
 	hp->t = hp->s;
 
-	hp->hdr = malloc(sizeof *hp->hdr * http_nhdr);
+	hp->hdr = malloc(sizeof *hp->hdr * heritage.mem_http_headers);
 	assert(hp->hdr != NULL);
 
 	return (hp);
@@ -280,7 +292,7 @@
 		if (p == q)
 			break;
 
-		if (hp->nhdr < http_nhdr) {
+		if (hp->nhdr < heritage.mem_http_headers) {
 			hp->hdr[hp->nhdr++] = p;
 			VSLR(SLT_Header, fd, p, q);
 		} else {

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2006-07-10 08:10:30 UTC (rev 392)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2006-07-10 08:41:26 UTC (rev 393)
@@ -41,7 +41,8 @@
 
 	/* Memory allocation hints */
 	unsigned		mem_http_1_line;
-	unsigned		mem_http_header;
+	unsigned		mem_http_headerspace;
+	unsigned		mem_http_headers;
 	unsigned		mem_workspace;
 };
 

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2006-07-10 08:10:30 UTC (rev 392)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2006-07-10 08:41:26 UTC (rev 393)
@@ -458,7 +458,8 @@
 	heritage.wthread_min = 5;
 	heritage.wthread_max = 5;
 	heritage.mem_http_1_line= 512;
-	heritage.mem_http_header= 4096;
+	heritage.mem_http_headerspace= 4096;
+	heritage.mem_http_headers= 32;
 	heritage.mem_workspace = 0;
 
 	while ((o = getopt(argc, argv, "b:df:h:p:s:t:w:")) != -1)




More information about the varnish-commit mailing list