]> err.no Git - varnish/commitdiff
Add heritage.mem_http_headers which is the maximum number of headers
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 10 Jul 2006 08:41:26 +0000 (08:41 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 10 Jul 2006 08:41:26 +0000 (08:41 +0000)
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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_backend.c
varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/varnishd.c

index f1f49df37e64de49abe8fdc8d6364ddb95c28144..366b8d52b1876725763ca875ea9090dc0142ec52 100644 (file)
@@ -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);
index 3b4cbf03b44c4a958c7797f9c7ac2f4920ea6f99..536f15cef51220b64c7a563371634832fc16cb47 100644 (file)
 #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 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);
 }
 
index 46a0ee310865a67ea2044d51f8eea98da8410aa9..79b8a7ecf5bfd30a3d9a66fd7afd207c9f046725 100644 (file)
 
 #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 {
index ae8bf0991088effd4679f91cf062816ca190dba7..622487ac26df927eb68f898a0ac61de3945d5c25 100644 (file)
@@ -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;
 };
 
index b04e89b351e60f56f075fdc6bee4f64d31ae3c68..751c86d78db8f673543fad768eff4036dadfbd1a 100644 (file)
@@ -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)