From: phk Date: Mon, 10 Jul 2006 08:41:26 +0000 (+0000) Subject: Add heritage.mem_http_headers which is the maximum number of headers X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9aed308e92b87356ce342da85595156a76aec1a6;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@393 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index f1f49df3..366b8d52 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -42,8 +42,8 @@ struct http { char *status; char *response; - char **hdr; unsigned nhdr; + char **hdr; }; /*--------------------------------------------------------------------*/ @@ -61,10 +61,12 @@ struct worker { 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_Deref(struct object *o); 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); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 3b4cbf03..536f15ce 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -36,9 +36,16 @@ #include #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 pthread_t vbe_thread; 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 @@ vbe_rdp(int fd, short event, void *arg) 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 @@ vbe_rdf(int fd, short event, void *arg) 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 @@ VBE_GetFd(struct backend *bp, unsigned xid) 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 @@ VBE_GetFd(struct backend *bp, unsigned xid) 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 @@ VBE_GetFd(struct backend *bp, unsigned xid) 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); } diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 46a0ee31..79b8a7ec 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -13,10 +13,22 @@ #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; +} /*--------------------------------------------------------------------*/ @@ -29,14 +41,14 @@ http_New(void) 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 @@ http_Dissect(struct http *hp, int fd, int rr) 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 { diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index ae8bf099..622487ac 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -41,7 +41,8 @@ struct heritage { /* Memory allocation hints */ unsigned mem_http_1_line; - unsigned mem_http_header; + unsigned mem_http_headerspace; + unsigned mem_http_headers; unsigned mem_workspace; }; diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index b04e89b3..751c86d7 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -458,7 +458,8 @@ main(int argc, char *argv[]) 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)