r3884 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Thu Mar 5 11:30:56 CET 2009


Author: phk
Date: 2009-03-05 11:30:56 +0100 (Thu, 05 Mar 2009)
New Revision: 3884

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_session.c
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/mgt_param.c
   trunk/varnish-cache/include/shmlog_tags.h
   trunk/varnish-cache/include/stat_field.h
Log:
Remove the client source address accounting, it is unused and a performance
bottleneck.

The original idea was anti-DoS measures along the lines of
	sub vcl_recv {
		if (client.bandwith > 1 mbit/s) {
			delay (100 ms);
		}
	}

But there are does not seem to be a pressing need, wherefore it has
never been completed, and even if it was, it would not solve the
problem across a server farm.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-03-05 10:30:56 UTC (rev 3884)
@@ -211,7 +211,6 @@
 	ssize_t			liov;
 
 	struct VCL_conf		*vcl;
-	struct srcaddr		*srcaddr;
 
 	unsigned char		*wlb, *wlp, *wle;
 	unsigned		wlr;
@@ -352,7 +351,6 @@
 	/* formatted ascii client address */
 	char			*addr;
 	char			*port;
-	struct srcaddr		*srcaddr;
 
 	/* HTTP request */
 	const char		*doclose;
@@ -579,7 +577,6 @@
 void SES_Init(void);
 struct sess *SES_New(const struct sockaddr *addr, unsigned len);
 void SES_Delete(struct sess *sp);
-void SES_RefSrcAddr(struct sess *sp);
 void SES_Charge(struct sess *sp);
 void SES_ResetBackendTimeouts(struct sess *sp);
 void SES_InheritBackendTimeouts(struct sess *sp);

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-03-05 10:30:56 UTC (rev 3884)
@@ -581,7 +581,6 @@
 	HTC_Init(sp->htc, sp->ws, sp->fd);
 	sp->wrk->lastused = sp->t_open;
 	sp->acct_req.sess++;
-	SES_RefSrcAddr(sp);
 	do
 		i = HTC_Rx(sp->htc);
 	while (i == 0);

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2009-03-05 10:30:56 UTC (rev 3884)
@@ -372,8 +372,6 @@
 	if (w->vcl != NULL)
 		VCL_Rel(&w->vcl);
 	AZ(pthread_cond_destroy(&w->cond));
-	if (w->srcaddr != NULL)
-		free(w->srcaddr);
 	HSH_Cleanup(w);
 	WRK_SumStat(w);
 	return (NULL);

Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c	2009-03-05 10:30:56 UTC (rev 3884)
@@ -30,14 +30,6 @@
  *
  * Session and Client management.
  *
- * The srcaddr structures are kept around only as a convenience feature to
- * make it possible to track down offenders and misconfigured caches.
- * As such it is pure overhead and we do not want to spend too much time
- * on maintaining it.
- *
- * We identify srcaddrs instead of full addr+port because the desired level
- * of granularity is "whois is abuse@ or tech-c@ in the RIPE database.
- *
  * XXX: The two-list session management is actually not a good idea
  * XXX: come to think of it, because we want the sessions reused in
  * XXX: Most Recently Used order.
@@ -83,134 +75,11 @@
 
 /*--------------------------------------------------------------------*/
 
-struct srcaddr {
-	unsigned		magic;
-#define SRCADDR_MAGIC		0x375111db
-
-	unsigned		hash;
-	VTAILQ_ENTRY(srcaddr)	list;
-	struct srcaddrhead	*sah;
-
-	char			addr[TCP_ADDRBUFSIZE];
-	unsigned		nref;
-
-	/* How long to keep entry around.  Inherits timescale from t_open */
-	double			ttl;
-
-	struct acct		acct;
-};
-
-static struct srcaddrhead {
-	unsigned		magic;
-#define SRCADDRHEAD_MAGIC	0x38231a8b
-	VTAILQ_HEAD(,srcaddr)	head;
-	struct lock		mtx;
-} *srchash;
-
-static unsigned			nsrchash;
 static struct lock 		stat_mtx;
 
-/*--------------------------------------------------------------------
- * Assign a srcaddr to this session.
- *
- * Each hash bucket is sorted in least recently used order and if we
- * need to make a new entry we recycle the first expired entry we find.
- * If we find more expired entries during our search, we delete them.
- */
-
-void
-SES_RefSrcAddr(struct sess *sp)
-{
-	unsigned u, v;
-	struct srcaddr *c, *c2, *c3;
-	struct srcaddrhead *ch;
-	double now;
-
-	if (params->srcaddr_ttl == 0) {
-		sp->srcaddr = NULL;
-		return;
-	}
-	AZ(sp->srcaddr);
-	u = crc32_l(sp->addr, strlen(sp->addr));
-	v = u % nsrchash;
-	ch = &srchash[v];
-	CHECK_OBJ(ch, SRCADDRHEAD_MAGIC);
-	now = sp->t_open;
-	if (sp->wrk->srcaddr == NULL) {
-		sp->wrk->srcaddr = calloc(sizeof *sp->wrk->srcaddr, 1);
-		XXXAN(sp->wrk->srcaddr);
-	}
-
-	Lck_Lock(&ch->mtx);
-	c3 = NULL;
-	VTAILQ_FOREACH_SAFE(c, &ch->head, list, c2) {
-		if (c->hash == u && !strcmp(c->addr, sp->addr)) {
-			if (c->nref == 0)
-				VSL_stats->n_srcaddr_act++;
-			c->nref++;
-			c->ttl = now + params->srcaddr_ttl;
-			sp->srcaddr = c;
-			VTAILQ_REMOVE(&ch->head, c, list);
-			VTAILQ_INSERT_TAIL(&ch->head, c, list);
-			if (c3 != NULL) {
-				VTAILQ_REMOVE(&ch->head, c3, list);
-				VSL_stats->n_srcaddr--;
-			}
-			Lck_Unlock(&ch->mtx);
-			if (c3 != NULL)
-				free(c3);
-			return;
-		}
-		if (c->nref > 0 || c->ttl > now)
-			continue;
-		if (c3 == NULL)
-			c3 = c;
-	}
-	if (c3 == NULL) {
-		c3 = sp->wrk->srcaddr;
-		sp->wrk->srcaddr = NULL;
-		VSL_stats->n_srcaddr++;
-	} else
-		VTAILQ_REMOVE(&ch->head, c3, list);
-	AN(c3);
-	memset(c3, 0, sizeof *c3);
-	c3->magic = SRCADDR_MAGIC;
-	strcpy(c3->addr, sp->addr);
-	c3->hash = u;
-	c3->acct.first = now;
-	c3->ttl = now + params->srcaddr_ttl;
-	c3->nref = 1;
-	c3->sah = ch;
-	VSL_stats->n_srcaddr_act++;
-	VTAILQ_INSERT_TAIL(&ch->head, c3, list);
-	sp->srcaddr = c3;
-	Lck_Unlock(&ch->mtx);
-}
-
 /*--------------------------------------------------------------------*/
 
 static void
-ses_relsrcaddr(struct sess *sp)
-{
-	struct srcaddrhead *ch;
-
-	if (sp->srcaddr == NULL)
-		return;
-	CHECK_OBJ(sp->srcaddr, SRCADDR_MAGIC);
-	ch = sp->srcaddr->sah;
-	CHECK_OBJ(ch, SRCADDRHEAD_MAGIC);
-	Lck_Lock(&ch->mtx);
-	assert(sp->srcaddr->nref > 0);
-	sp->srcaddr->nref--;
-	if (sp->srcaddr->nref == 0)
-		VSL_stats->n_srcaddr_act--;
-	sp->srcaddr = NULL;
-	Lck_Unlock(&ch->mtx);
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
 ses_sum_acct(struct acct *sum, const struct acct *inc)
 {
 
@@ -223,22 +92,8 @@
 SES_Charge(struct sess *sp)
 {
 	struct acct *a = &sp->acct_req;
-	struct acct b;
 
 	ses_sum_acct(&sp->acct, a);
-	if (sp->srcaddr != NULL) {
-		/* XXX: only report once per second ? */
-		CHECK_OBJ(sp->srcaddr, SRCADDR_MAGIC);
-		Lck_Lock(&sp->srcaddr->sah->mtx);
-		ses_sum_acct(&sp->srcaddr->acct, a);
-		b = sp->srcaddr->acct;
-		Lck_Unlock(&sp->srcaddr->sah->mtx);
-		WSL(sp->wrk, SLT_StatAddr, 0,
-		    "%s 0 %.0f %ju %ju %ju %ju %ju %ju %ju",
-		    sp->srcaddr->addr, sp->t_end - b.first,
-		    b.sess, b.req, b.pipe, b.pass,
-		    b.fetch, b.hdrbytes, b.bodybytes);
-	}
 	Lck_Lock(&stat_mtx);
 #define ACCT(foo)	VSL_stats->s_##foo += a->foo;
 #include "acct_fields.h"
@@ -335,7 +190,6 @@
 	AZ(sp->obj);
 	AZ(sp->vcl);
 	VSL_stats->n_sess--;
-	ses_relsrcaddr(sp);
 	assert(!isnan(b->first));
 	assert(!isnan(sp->t_end));
 	VSL(SLT_StatSess, sp->id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju",
@@ -357,16 +211,7 @@
 void
 SES_Init()
 {
-	int i;
 
-	nsrchash = params->srcaddr_hash;
-	srchash = calloc(sizeof *srchash, nsrchash);
-	XXXAN(srchash);
-	for (i = 0; i < nsrchash; i++) {
-		srchash[i].magic = SRCADDRHEAD_MAGIC;
-		VTAILQ_INIT(&srchash[i].head);
-		Lck_New(&srchash[i].mtx);
-	}
 	Lck_New(&stat_mtx);
 	Lck_New(&ses_mem_mtx);
 }

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2009-03-05 10:30:56 UTC (rev 3884)
@@ -125,10 +125,6 @@
 	/* Listen depth */
 	unsigned		listen_depth;
 
-	/* Srcaddr hash */
-	unsigned		srcaddr_hash;
-	unsigned		srcaddr_ttl;
-
 	/* HTTP proto behaviour */
 	unsigned		backend_http11;
 	unsigned		client_http11;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2009-03-05 10:30:56 UTC (rev 3884)
@@ -576,16 +576,6 @@
 		"Listen queue depth.",
 		MUST_RESTART,
 		"1024", "connections" },
-	{ "srcaddr_hash", tweak_uint, &master.srcaddr_hash, 63, UINT_MAX,
-		"Number of source address hash buckets.\n"
-		"Powers of two are bad, prime numbers are good.",
-		EXPERIMENTAL | MUST_RESTART,
-		"1049", "buckets" },
-	{ "srcaddr_ttl", tweak_uint, &master.srcaddr_ttl, 0, UINT_MAX,
-		"Lifetime of srcaddr entries.\n"
-		"Zero will disable srcaddr accounting entirely.",
-		EXPERIMENTAL,
-		"30", "seconds" },
 	{ "backend_http11", tweak_bool, &master.backend_http11, 0, 0,
 		"Force all backend requests to be HTTP/1.1.\n"
 		"By default we copy the protocol version from the "

Modified: trunk/varnish-cache/include/shmlog_tags.h
===================================================================
--- trunk/varnish-cache/include/shmlog_tags.h	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/include/shmlog_tags.h	2009-03-05 10:30:56 UTC (rev 3884)
@@ -41,7 +41,6 @@
 SLTM(Debug)
 SLTM(Error)
 SLTM(CLI)
-SLTM(StatAddr)
 SLTM(StatSess)
 SLTM(ReqEnd)
 SLTM(SessionOpen)

Modified: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h	2009-03-05 10:24:04 UTC (rev 3883)
+++ trunk/varnish-cache/include/stat_field.h	2009-03-05 10:30:56 UTC (rev 3884)
@@ -45,8 +45,6 @@
 MAC_STAT(backend_recycle,	uint64_t, 0, 'a', "Backend connections recycles")
 MAC_STAT(backend_unused,	uint64_t, 0, 'a', "Backend connections unused")
 
-MAC_STAT(n_srcaddr,		uint64_t, 0, 'i', "N struct srcaddr")
-MAC_STAT(n_srcaddr_act,		uint64_t, 0, 'i', "N active struct srcaddr")
 MAC_STAT(n_sess_mem,		uint64_t, 0, 'i', "N struct sess_mem")
 MAC_STAT(n_sess,		uint64_t, 0, 'i', "N struct sess")
 MAC_STAT(n_object,		uint64_t, 1, 'i', "N struct object")



More information about the varnish-commit mailing list