Mailing List Archive

r86 - in trunk/varnish-cache: bin/varnishd include lib/libvcl
Author: phk
Date: 2006-03-30 11:26:34 +0200 (Thu, 30 Mar 2006)
New Revision: 86

Added:
trunk/varnish-cache/bin/varnishd/cache_backend.c
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_main.c
trunk/varnish-cache/bin/varnishd/cache_pool.c
trunk/varnish-cache/bin/varnishd/varnishd.c
trunk/varnish-cache/include/vcl_lang.h
trunk/varnish-cache/lib/libvcl/vcl_compile.c
trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
Log:
Add the beginning of a backend connection pool


Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2006-03-30 09:26:34 UTC (rev 86)
@@ -6,6 +6,7 @@

varnishd_SOURCES = \
cache_acceptor.c \
+ cache_backend.c \
cache_httpd.c \
cache_main.c \
cache_pool.c \

Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-03-30 09:26:34 UTC (rev 86)
@@ -5,6 +5,9 @@
/* cache_acceptor.c */
void *vca_main(void *arg);

+/* cache_backend.c */
+void VBE_Init(void);
+
/* cache_httpd.c */
void HttpdAnalyze(struct sess *sp);


Added: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2006-03-30 09:26:34 UTC (rev 86)
@@ -0,0 +1,92 @@
+/*
+ * $Id$
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+#include "libvarnish.h"
+#include "vcl_lang.h"
+
+/*
+ * The internal backend structure for managing connection pools per
+ * backend. We need to shadow the backend stucture from the VCL
+ * in order let connections live across VCL switches.
+ */
+
+struct vbe_conn {
+ TAILQ_ENTRY(vbe_conn) list;
+ struct vbe *vbe;
+ int fd;
+};
+
+struct vbe {
+ unsigned ip;
+ TAILQ_ENTRY(vbe) list;
+ TAILQ_HEAD(,vbe_conn) fconn;
+ TAILQ_HEAD(,vbe_conn) bconn;
+ unsigned nconn;
+};
+
+static TAILQ_HEAD(,vbe) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head);
+
+static pthread_mutex_t vbemtx;
+
+/*--------------------------------------------------------------------*/
+void
+connect_to_backend(struct vbe_conn *vc, struct backend *bp)
+{
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VBE_GetFd(struct backend *bp)
+{
+ struct vbe *vp;
+ struct vbe_conn *vc;
+
+ AZ(pthread_mutex_lock(&vbemtx));
+ vp = bp->vbe;
+ if (vp == NULL) {
+ TAILQ_FOREACH(vp, &vbe_head, list)
+ if (vp->ip == bp->ip)
+ break;
+ }
+ if (vp == NULL) {
+ vp = calloc(sizeof *vp, 1);
+ assert(vp != NULL);
+ TAILQ_INIT(&vp->fconn);
+ TAILQ_INIT(&vp->bconn);
+ vp->ip = bp->ip;
+ bp->vbe = vp;
+ TAILQ_INSERT_TAIL(&vbe_head, vp, list);
+ }
+ /* XXX: check nconn vs backend->maxcon */
+ vc = TAILQ_FIRST(&vp->fconn);
+ if (vc != NULL) {
+ TAILQ_REMOVE(&vp->fconn, vc, list);
+ TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
+ AZ(pthread_mutex_unlock(&vbemtx));
+ return (vc->fd);
+ }
+ vc = calloc(sizeof *vc, 1);
+ assert(vc != NULL);
+ vc->vbe = vp;
+ TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
+ AZ(pthread_mutex_unlock(&vbemtx));
+ connect_to_backend(vc, bp);
+
+ /* XXX */
+ return (-1);
+}
+
+
+
+
+void
+VBE_Init(void)
+{
+
+ AZ(pthread_mutex_init(&vbemtx, NULL));
+}

Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c 2006-03-30 09:26:34 UTC (rev 86)
@@ -103,6 +103,7 @@
printf("Child starts\n");

AZ(pthread_mutex_init(&sessmtx, NULL));
+ VBE_Init();
VSL_Init();
CacheInitPool();


Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-03-30 09:26:34 UTC (rev 86)
@@ -33,6 +33,7 @@

HttpdAnalyze(sp);

+ sp->backend = sp->vcl->default_backend;
/* Call the VCL program */
sp->vcl->main_func(sp);


Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2006-03-30 09:26:34 UTC (rev 86)
@@ -68,7 +68,7 @@

buf = NULL;
asprintf(&buf,
- "backend default { set backend.ip = %s; }\n"
+ "backend default { set backend.host = \"%s\"; }\n"
"sub main {\n"
" pass;\n"
#if 0

Modified: trunk/varnish-cache/include/vcl_lang.h
===================================================================
--- trunk/varnish-cache/include/vcl_lang.h 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/include/vcl_lang.h 2006-03-30 09:26:34 UTC (rev 86)
@@ -53,6 +53,7 @@

TAILQ_ENTRY(sess) list;

+ struct backend *backend;
struct VCL_conf *vcl;

/* Various internal stuff */
@@ -60,21 +61,18 @@
struct sessmem *mem;
};

-struct be_conn {
- TAILQ_ENTRY(be_conn) list;
- int fd;
-};
-
struct backend {
+ const char *hostname;
+ const char *portname;
+ struct addrinfo *addr;
unsigned ip;
double responsetime;
double timeout;
double bandwidth;
int down;

- /* Internals */
- TAILQ_HEAD(,be_conn) bec_head;
- unsigned nbec;
+ /* internal stuff */
+ struct vbe *vbe;
};

#define VCL_FARGS struct sess *sess

Modified: trunk/varnish-cache/lib/libvcl/vcl_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_compile.c 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/lib/libvcl/vcl_compile.c 2006-03-30 09:26:34 UTC (rev 86)
@@ -109,6 +109,9 @@


static struct var vars[] = {
+ { "backend.host", STRING, 0, "backend->hostname" },
+ { "backend.port", STRING, 0, "backend->portname" },
+#if 0
{ "req.ttlfactor", FLOAT, 0, "req->ttlfactor" },
{ "req.url.host", STRING, 0, "req->url.host" },
{ "req.url.path", STRING, 0, "req->url.path" },
@@ -116,7 +119,6 @@
{ "req.backend", BACKEND, 0, "req->backend" },
{ "client.ip", IP, 0, "client->ip" },
{ "backend.response_time", TIME, 0, "backend->responsetime" },
- { "backend.ip", IP, 0, "backend->ip" },
{ "backend.down", BOOL, 0, "backend->down" },
{ "backend.timeout", TIME, 0, "backend->timeout" },
{ "backend.bandwidth", RATE, 0, "backend->bandwidth" },
@@ -125,6 +127,7 @@
{ "obj.result", INT, 0, "obj->result" },
{ "obj.size", SIZE, 0, "obj->size" },
{ "obj.usage", INT, 0, "obj->usage" },
+#endif
{ NULL, INT, 0, "NULL" }
};


Modified: trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c 2006-03-30 08:05:11 UTC (rev 85)
+++ trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c 2006-03-30 09:26:34 UTC (rev 86)
@@ -434,6 +434,7 @@
fputs("\n", f);
fputs(" TAILQ_ENTRY(sess) list;\n", f);
fputs("\n", f);
+ fputs(" struct backend *backend;\n", f);
fputs(" struct VCL_conf *vcl;\n", f);
fputs("\n", f);
fputs(" /* Various internal stuff */\n", f);
@@ -441,21 +442,18 @@
fputs(" struct sessmem *mem;\n", f);
fputs("};\n", f);
fputs("\n", f);
- fputs("struct be_conn {\n", f);
- fputs(" TAILQ_ENTRY(be_conn) list;\n", f);
- fputs(" int fd;\n", f);
- fputs("};\n", f);
- fputs("\n", f);
fputs("struct backend {\n", f);
+ fputs(" const char *hostname;\n", f);
+ fputs(" const char *portname;\n", f);
+ fputs(" struct addrinfo *addr;\n", f);
fputs(" unsigned ip;\n", f);
fputs(" double responsetime;\n", f);
fputs(" double timeout;\n", f);
fputs(" double bandwidth;\n", f);
fputs(" int down;\n", f);
fputs("\n", f);
- fputs(" /* Internals */\n", f);
- fputs(" TAILQ_HEAD(,be_conn) bec_head;\n", f);
- fputs(" unsigned nbec;\n", f);
+ fputs(" /* internal stuff */\n", f);
+ fputs(" struct vbe *vbe;\n", f);
fputs("};\n", f);
fputs("\n", f);
fputs("#define VCL_FARGS struct sess *sess\n", f);