Commit dbbcaa80 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

VCL configs change relatively seldom so we can cache the requests

VCL reference in the worker thread when the request is done and
with a cheap check reuse it for the next request handled by this
thread.

This should reduce mutex contention.


git-svn-id: http://www.varnish-cache.org/svn/trunk@1032 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent aa1af25c
...@@ -113,6 +113,7 @@ struct worker { ...@@ -113,6 +113,7 @@ struct worker {
size_t liov; size_t liov;
struct acct acct; struct acct acct;
struct VCL_conf *vcl;
}; };
struct workreq { struct workreq {
...@@ -415,8 +416,9 @@ void RES_WriteObj(struct sess *sp); ...@@ -415,8 +416,9 @@ void RES_WriteObj(struct sess *sp);
/* cache_vcl.c */ /* cache_vcl.c */
void VCL_Init(void); void VCL_Init(void);
void VCL_Rel(struct VCL_conf *vc); void VCL_Refresh(struct VCL_conf **vcc);
struct VCL_conf *VCL_Get(void); void VCL_Rel(struct VCL_conf **vcc);
void VCL_Get(struct VCL_conf **vcc);
#define VCL_RET_MAC(l,u,b,n) #define VCL_RET_MAC(l,u,b,n)
#define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *);
......
...@@ -130,7 +130,9 @@ cnt_done(struct sess *sp) ...@@ -130,7 +130,9 @@ cnt_done(struct sess *sp)
vca_close_session(sp, sp->doclose); vca_close_session(sp, sp->doclose);
sp->backend = NULL; sp->backend = NULL;
if (sp->vcl != NULL) { if (sp->vcl != NULL) {
VCL_Rel(sp->vcl); if (sp->wrk->vcl != NULL)
VCL_Rel(&sp->wrk->vcl);
sp->wrk->vcl = sp->vcl;
sp->vcl = NULL; sp->vcl = NULL;
} }
...@@ -653,7 +655,9 @@ cnt_recv(struct sess *sp) ...@@ -653,7 +655,9 @@ cnt_recv(struct sess *sp)
VSL(SLT_ReqStart, sp->fd, "%s %s %u", sp->addr, sp->port, sp->xid); VSL(SLT_ReqStart, sp->fd, "%s %s %u", sp->addr, sp->port, sp->xid);
AZ(sp->vcl); AZ(sp->vcl);
sp->vcl = VCL_Get(); VCL_Refresh(&sp->wrk->vcl);
sp->vcl = sp->wrk->vcl;
sp->wrk->vcl = NULL;
AZ(sp->obj); AZ(sp->obj);
AZ(sp->vbc); AZ(sp->vbc);
......
...@@ -113,7 +113,7 @@ exp_prefetch(void *arg) ...@@ -113,7 +113,7 @@ exp_prefetch(void *arg)
sp = SES_New(NULL, 0); sp = SES_New(NULL, 0);
XXXAN(sp); XXXAN(sp);
sleep(10); /* Takes time for VCL to arrive */ sleep(10); /* Takes time for VCL to arrive */
sp->vcl = VCL_Get(); VCL_Get(&sp->vcl);
t = time(NULL); t = time(NULL);
while (1) { while (1) {
LOCK(&exp_mtx); LOCK(&exp_mtx);
...@@ -122,9 +122,9 @@ exp_prefetch(void *arg) ...@@ -122,9 +122,9 @@ exp_prefetch(void *arg)
CHECK_OBJ(o, OBJECT_MAGIC); CHECK_OBJ(o, OBJECT_MAGIC);
if (o == NULL || o->ttl > t + expearly) { if (o == NULL || o->ttl > t + expearly) {
UNLOCK(&exp_mtx); UNLOCK(&exp_mtx);
VCL_Rel(sp->vcl); VCL_Rel(&sp->vcl);
AZ(sleep(1)); AZ(sleep(1));
sp->vcl = VCL_Get(); VCL_Get(&sp->vcl);
t = time(NULL); t = time(NULL);
continue; continue;
} }
......
...@@ -218,6 +218,8 @@ wrk_thread(void *priv) ...@@ -218,6 +218,8 @@ wrk_thread(void *priv)
VSL_stats->n_wrk--; VSL_stats->n_wrk--;
UNLOCK(&tmtx); UNLOCK(&tmtx);
VSL(SLT_WorkThread, 0, "%p end", w); VSL(SLT_WorkThread, 0, "%p end", w);
if (w->vcl != NULL)
VCL_Rel(&w->vcl);
close(w->pipe[0]); close(w->pipe[0]);
close(w->pipe[1]); close(w->pipe[1]);
return (NULL); return (NULL);
......
...@@ -41,24 +41,36 @@ static MTX vcl_mtx; ...@@ -41,24 +41,36 @@ static MTX vcl_mtx;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct VCL_conf * void
VCL_Get(void) VCL_Refresh(struct VCL_conf **vcc)
{
if (*vcc == vcl_active->conf)
return;
if (*vcc != NULL)
VCL_Rel(vcc);
VCL_Get(vcc);
}
void
VCL_Get(struct VCL_conf **vcc)
{ {
struct VCL_conf *vc;
LOCK(&vcl_mtx); LOCK(&vcl_mtx);
AN(vcl_active); AN(vcl_active);
vc = vcl_active->conf; *vcc = vcl_active->conf;
AN(vc); AN(*vcc);
vc->busy++; (*vcc)->busy++;
UNLOCK(&vcl_mtx); UNLOCK(&vcl_mtx);
return (vc);
} }
void void
VCL_Rel(struct VCL_conf *vc) VCL_Rel(struct VCL_conf **vcc)
{ {
struct vcls *vcl; struct vcls *vcl;
struct VCL_conf *vc;
vc = *vcc;
*vcc = NULL;
LOCK(&vcl_mtx); LOCK(&vcl_mtx);
assert(vc->busy > 0); assert(vc->busy > 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment