r4222 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Sep 2 17:43:34 CEST 2009


Author: phk
Date: 2009-09-02 17:43:33 +0200 (Wed, 02 Sep 2009)
New Revision: 4222

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/hash_slinger.h
Log:
Try to simplify the variable structure around the decision to populate a
busy cache entry or to ditch it.

Ditch it as soon as we can, so we don't hold other clients on a busy objcore
longer than necessary.



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-09-02 09:08:24 UTC (rev 4221)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-09-02 15:43:33 UTC (rev 4222)
@@ -333,7 +333,8 @@
 	w = sp->wrk;
 	if (sp->obj == NULL) {
 		HSH_Prealloc(sp);
-		sp->obj = HSH_NewObject(sp, 1);
+		sp->wrk->cacheable = 0;
+		sp->obj = HSH_NewObject(sp);
 		sp->obj->xid = sp->xid;
 		sp->obj->entered = sp->t_req;
 	} else {
@@ -411,7 +412,7 @@
 static int
 cnt_fetch(struct sess *sp)
 {
-	int i, transient;
+	int i;
 	struct http *hp, *hp2;
 	char *b;
 	unsigned handling;
@@ -436,10 +437,12 @@
 	*sp->wrk->beresp1 = *sp->wrk->beresp;
 
 	if (i) {
-		if (sp->objhead) {
+		if (sp->objcore != NULL) {
 			CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
 			CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
 			HSH_DerefObjCore(sp);
+			AZ(sp->objhead);
+			AZ(sp->objcore);
 		}
 		AZ(sp->obj);
 		sp->wrk->bereq = NULL;
@@ -475,7 +478,7 @@
 	sp->wrk->age = 0;
 	sp->wrk->ttl = RFC2616_Ttl(sp);
 
-	if (sp->wrk->ttl == 0.)
+	if (sp->objcore == NULL)
 		sp->wrk->cacheable = 0;
 
 	sp->wrk->do_esi = 0;
@@ -490,23 +493,28 @@
 	 */
 	handling = sp->handling;
 
-	if (sp->objhead == NULL)
+	if (sp->objcore == NULL) {
 		/* This is a pass from vcl_recv */
-		transient = 1;
-	else if (sp->handling == VCL_RET_PASS)
-		/* A pass from vcl_fetch is not transient */
-		transient = 0;
-	else if (sp->handling == VCL_RET_DELIVER)
-		/* Regular object */
-		transient = 0;
-	else
-		transient = 1;
+		AZ(sp->objhead);
+		sp->wrk->cacheable = 0;
+	} else if (!sp->wrk->cacheable) {
+		if (sp->objhead != NULL)
+			HSH_DerefObjCore(sp);
+	}
 
+	if (sp->wrk->cacheable) {
+		CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
+		CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
+	} else {
+		AZ(sp->objhead);
+		AZ(sp->objcore);
+	}
+
 	/*
 	 * XXX: If we have a Length: header, we should allocate the body
 	 * XXX: also.
  	 */
-	sp->obj = HSH_NewObject(sp, transient);
+	sp->obj = HSH_NewObject(sp);
 
 	if (sp->objhead != NULL) {
 		CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
@@ -558,7 +566,7 @@
 		return (0);
 	}
 
-	if (!transient)
+	if (sp->wrk->cacheable)
 		HSH_Object(sp);
 
 	if (sp->wrk->do_esi)
@@ -594,7 +602,7 @@
 	}
 
 	sp->obj->cacheable = 1;
-	if (!transient) {
+	if (sp->wrk->cacheable) {
 		VRY_Create(sp);
 		EXP_Insert(sp->obj);
 		AN(sp->obj->ban);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-09-02 09:08:24 UTC (rev 4221)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-09-02 15:43:33 UTC (rev 4222)
@@ -82,13 +82,13 @@
 }
 
 struct object *
-HSH_NewObject(struct sess *sp, int transient)
+HSH_NewObject(struct sess *sp)
 {
 	struct object *o;
 	struct storage *st;
 	void *p;
 
-	if (transient) {
+	if (!sp->wrk->cacheable) {
 		p = malloc(sizeof *o + params->obj_workspace);
 		XXXAN(p);
 		o = p;

Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-09-02 09:08:24 UTC (rev 4221)
+++ trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-09-02 15:43:33 UTC (rev 4222)
@@ -50,7 +50,7 @@
 };
 
 /* cache_hash.c */
-struct object *HSH_NewObject(struct sess *sp, int transient);
+struct object *HSH_NewObject(struct sess *sp);
 void HSH_Object(const struct sess *sp);
 void HSH_Prealloc(const struct sess *sp);
 void HSH_Cleanup(struct worker *w);



More information about the varnish-commit mailing list