From 84b1de40a4ea025f08966573ed29f0a7c51260aa Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 14 Jun 2008 14:26:59 +0000 Subject: [PATCH] Change defaults: Make Grace mode the default with 10 seconds (param: default_grace) Make the thread idle timeout 300 seconds (param: thread_pool_timeout) Max one new thread per 20 msec (param: thread_pool_add_delay) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2665 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_hash.c | 14 ++++++++++++-- varnish-cache/bin/varnishd/cache_session.c | 1 + varnish-cache/bin/varnishd/cache_vrt.c | 5 +++++ varnish-cache/bin/varnishd/heritage.h | 3 +++ varnish-cache/bin/varnishd/mgt_param.c | 10 ++++++++-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 439e0a21..4f736ae2 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -56,6 +56,7 @@ #include #include +#include #include #include #include @@ -66,6 +67,14 @@ static struct hash_slinger *hash; +static double +HSH_Grace(double g) +{ + if (isnan(g)) + return (double)(params->default_grace); + return (g); +} + /* Precreate an objhead and object for later use */ void HSH_Prealloc(struct sess *sp) @@ -99,6 +108,7 @@ HSH_Prealloc(struct sess *sp) w->nobj->http->magic = HTTP_MAGIC; w->nobj->busy = 1; w->nobj->refcnt = 1; + w->nobj->grace = NAN; VTAILQ_INIT(&w->nobj->store); VTAILQ_INIT(&w->nobj->esibits); VSL_stats->n_object++; @@ -221,7 +231,7 @@ HSH_Lookup(struct sess *sp) break; /* Remember any matching objects inside their grace period */ - if (o->ttl + o->grace >= sp->t_req) + if (o->ttl + HSH_Grace(o->grace) >= sp->t_req) grace_o = o; } @@ -231,7 +241,7 @@ HSH_Lookup(struct sess *sp) */ if (o == NULL && grace_o != NULL && grace_o->child != NULL && - grace_o->ttl + sp->grace >= sp->t_req) + grace_o->ttl + HSH_Grace(sp->grace) >= sp->t_req) o = grace_o; if (o != NULL) { diff --git a/varnish-cache/bin/varnishd/cache_session.c b/varnish-cache/bin/varnishd/cache_session.c index 53511e44..268904a7 100644 --- a/varnish-cache/bin/varnishd/cache_session.c +++ b/varnish-cache/bin/varnishd/cache_session.c @@ -304,6 +304,7 @@ SES_New(const struct sockaddr *addr, unsigned len) sp->t_req = NAN; sp->t_resp = NAN; sp->t_end = NAN; + sp->grace = NAN; assert(len <= sp->sockaddrlen); if (addr != NULL) { diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index b15d3277..d0f76d96 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -326,6 +327,8 @@ VRT_r_obj_grace(const struct sess *sp) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ + if (isnan(sp->obj->grace)) + return ((double)params->default_grace); return (sp->obj->grace); } @@ -446,6 +449,8 @@ double VRT_r_req_grace(struct sess *sp) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + if (isnan(sp->grace)) + return ((double)params->default_grace); return (sp->grace); } diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 694b5ebb..41d8a73d 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -156,6 +156,9 @@ struct params { /* Control diagnostic code */ unsigned diag_bitmap; + + /* Default grace period */ + unsigned default_grace; }; extern volatile struct params *params; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index e6e13f85..091c30ab 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -503,7 +503,7 @@ static const struct parspec parspec[] = { "\n" "Minimum is 1 second.", EXPERIMENTAL | DELAYED_EFFECT, - "120", "seconds" }, + "300", "seconds" }, { "thread_pool_purge_delay", tweak_timeout, &master.wthread_purge_delay, 100, 0, "Wait this long between purging threads.\n" @@ -532,7 +532,7 @@ static const struct parspec parspec[] = { "Setting this too short increases the risk of worker " "thread pile-up.\n", EXPERIMENTAL, - "10", "milliseconds" }, + "20", "milliseconds" }, { "thread_pool_fail_delay", tweak_timeout, &master.wthread_fail_delay, 100, UINT_MAX, "Wait at least this long after a failed thread creation " @@ -581,6 +581,12 @@ static const struct parspec parspec[] = { "Minimum is 1024 bytes.", DELAYED_EFFECT, "8192", "bytes" }, + { "default_grace", tweak_uint, &master.default_grace, 0, UINT_MAX, + "Default grace period. We will deliver an object " + "this long after it has expired, provided another thread " + "is attempting to get a new copy.", + DELAYED_EFFECT, + "10" "seconds" }, { "sess_timeout", tweak_timeout, &master.sess_timeout, 0, 0, "Idle timeout for persistent sessions. " "If a HTTP request has not been received in this many " -- 2.39.5