Commit 8bd6aa96 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Work over the stats while I wait for -spersistent to crash:

Move most of the stat fields used in cache_center.c into the workers
private stats, hopefully reducing the lock contention and stats
precision at the same time.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4215 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent a3e08ee3
......@@ -27,6 +27,10 @@
* SUCH DAMAGE.
*
* $Id$
*
* These are the stats we keep track of per session. They will be summed,
* via the sp->wrk->stats into the s_<name> fields in the SHM file.
* NB: Remember to mark those in stat_field.h to be included in struct dstat.
*/
ACCT(sess)
......
......@@ -105,7 +105,8 @@ cnt_wait(struct sess *sp)
i = poll(pfd, 1, params->session_linger);
if (i == 0) {
WSL(sp->wrk, SLT_Debug, sp->fd, "herding");
VSL_stats->sess_herd++;
sp->wrk->stats->sess_herd++;
SES_Charge(sp);
sp->wrk = NULL;
vca_return_session(sp);
return (1);
......@@ -254,9 +255,11 @@ cnt_done(struct sess *sp)
sp->t_resp = NAN;
WSL_Flush(sp->wrk, 0);
/* If we did an ESI include, don't mess up our state */
if (sp->esis > 0)
/* If we did an ESI include, don't mess up our state */
if (sp->esis > 0) {
SES_Charge(sp);
return (1);
}
sp->t_req = NAN;
......@@ -269,8 +272,8 @@ cnt_done(struct sess *sp)
vca_close_session(sp, sp->doclose);
}
if (sp->fd < 0) {
sp->wrk->stats->sess_closed++;
SES_Charge(sp);
VSL_stats->sess_closed++;
sp->wrk = NULL;
SES_Delete(sp);
return (1);
......@@ -281,21 +284,21 @@ cnt_done(struct sess *sp)
i = HTC_Reinit(sp->htc);
if (i == 1) {
VSL_stats->sess_pipeline++;
sp->wrk->stats->sess_pipeline++;
sp->step = STP_START;
return (0);
}
if (Tlen(sp->htc->rxbuf)) {
VSL_stats->sess_readahead++;
sp->wrk->stats->sess_readahead++;
sp->step = STP_WAIT;
return (0);
}
if (params->session_linger > 0) {
VSL_stats->sess_linger++;
sp->wrk->stats->sess_linger++;
sp->step = STP_WAIT;
return (0);
}
VSL_stats->sess_herd++;
sp->wrk->stats->sess_herd++;
SES_Charge(sp);
sp->wrk = NULL;
vca_return_session(sp);
......@@ -745,6 +748,7 @@ cnt_lookup(struct sess *sp)
* worker thread. The hash code to restart the session,
* still in STP_LOOKUP, later when the busy object isn't.
*/
AZ(sp->wrk);
return (1);
}
......@@ -753,7 +757,7 @@ cnt_lookup(struct sess *sp)
/* If we inserted a new object it's a miss */
if (oc->flags & OC_F_BUSY) {
VSL_stats->cache_miss++;
sp->wrk->stats->cache_miss++;
AZ(oc->obj);
sp->objhead = oh;
......@@ -767,7 +771,7 @@ cnt_lookup(struct sess *sp)
sp->obj = o;
if (oc->flags & OC_F_PASS) {
VSL_stats->cache_hitpass++;
sp->wrk->stats->cache_hitpass++;
WSP(sp, SLT_HitPass, "%u", sp->obj->xid);
HSH_Deref(sp->wrk, &sp->obj);
sp->objcore = NULL;
......@@ -776,7 +780,7 @@ cnt_lookup(struct sess *sp)
return (0);
}
VSL_stats->cache_hit++;
sp->wrk->stats->cache_hit++;
WSP(sp, SLT_Hit, "%u", sp->obj->xid);
sp->step = STP_HIT;
return (0);
......@@ -1045,7 +1049,7 @@ cnt_start(struct sess *sp)
AZ(sp->vcl);
/* Update stats of various sorts */
VSL_stats->client_req++; /* XXX not locked */
sp->wrk->stats->client_req++;
sp->t_req = TIM_real();
sp->wrk->lastused = sp->t_req;
sp->acct_req.req++;
......
......@@ -530,6 +530,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
if (params->diag_bitmap & 0x20)
WSP(sp, SLT_Debug,
"on waiting list <%s>", oh->hash);
SES_Charge(sp);
sp->objhead = oh;
sp->wrk = NULL;
Lck_Unlock(&oh->mtx);
......
......@@ -80,27 +80,17 @@ static struct lock stat_mtx;
/*--------------------------------------------------------------------*/
static void
ses_sum_acct(struct acct *sum, const struct acct *inc)
{
#define ACCT(foo) sum->foo += inc->foo;
#include "acct_fields.h"
#undef ACCT
}
void
SES_Charge(struct sess *sp)
{
struct acct *a = &sp->acct_req;
ses_sum_acct(&sp->acct, a);
Lck_Lock(&stat_mtx);
#define ACCT(foo) VSL_stats->s_##foo += a->foo;
#define ACCT(foo) \
sp->wrk->stats->s_##foo += a->foo; \
sp->acct.foo += a->foo; \
a->foo = 0;
#include "acct_fields.h"
#undef ACCT
Lck_Unlock(&stat_mtx);
memset(a, 0, sizeof *a);
}
/*--------------------------------------------------------------------*/
......
......@@ -27,15 +27,18 @@
* SUCH DAMAGE.
*
* $Id$
*
* 3rd argument marks fields for inclusion in the per worker-thread
* stats structure.
*/
MAC_STAT(client_conn, uint64_t, 0, 'a', "Client connections accepted")
MAC_STAT(client_drop, uint64_t, 0, 'a', "Connection dropped, no sess")
MAC_STAT(client_req, uint64_t, 0, 'a', "Client requests received")
MAC_STAT(client_req, uint64_t, 1, 'a', "Client requests received")
MAC_STAT(cache_hit, uint64_t, 0, 'a', "Cache hits")
MAC_STAT(cache_hitpass, uint64_t, 0, 'a', "Cache hits for pass")
MAC_STAT(cache_miss, uint64_t, 0, 'a', "Cache misses")
MAC_STAT(cache_hit, uint64_t, 1, 'a', "Cache hits")
MAC_STAT(cache_hitpass, uint64_t, 1, 'a', "Cache hits for pass")
MAC_STAT(cache_miss, uint64_t, 1, 'a', "Cache misses")
MAC_STAT(backend_conn, uint64_t, 0, 'a', "Backend conn. success")
MAC_STAT(backend_unhealthy, uint64_t, 0, 'a', "Backend conn. not attempted")
......@@ -75,19 +78,19 @@ MAC_STAT(n_objsendfile, uint64_t, 0, 'a', "Objects sent with sendfile")
MAC_STAT(n_objwrite, uint64_t, 0, 'a', "Objects sent with write")
MAC_STAT(n_objoverflow, uint64_t, 0, 'a', "Objects overflowing workspace")
MAC_STAT(s_sess, uint64_t, 0, 'a', "Total Sessions")
MAC_STAT(s_req, uint64_t, 0, 'a', "Total Requests")
MAC_STAT(s_pipe, uint64_t, 0, 'a', "Total pipe")
MAC_STAT(s_pass, uint64_t, 0, 'a', "Total pass")
MAC_STAT(s_fetch, uint64_t, 0, 'a', "Total fetch")
MAC_STAT(s_hdrbytes, uint64_t, 0, 'a', "Total header bytes")
MAC_STAT(s_bodybytes, uint64_t, 0, 'a', "Total body bytes")
MAC_STAT(sess_closed, uint64_t, 0, 'a', "Session Closed")
MAC_STAT(sess_pipeline, uint64_t, 0, 'a', "Session Pipeline")
MAC_STAT(sess_readahead, uint64_t, 0, 'a', "Session Read Ahead")
MAC_STAT(sess_linger, uint64_t, 0, 'a', "Session Linger")
MAC_STAT(sess_herd, uint64_t, 0, 'a', "Session herd")
MAC_STAT(s_sess, uint64_t, 1, 'a', "Total Sessions")
MAC_STAT(s_req, uint64_t, 1, 'a', "Total Requests")
MAC_STAT(s_pipe, uint64_t, 1, 'a', "Total pipe")
MAC_STAT(s_pass, uint64_t, 1, 'a', "Total pass")
MAC_STAT(s_fetch, uint64_t, 1, 'a', "Total fetch")
MAC_STAT(s_hdrbytes, uint64_t, 1, 'a', "Total header bytes")
MAC_STAT(s_bodybytes, uint64_t, 1, 'a', "Total body bytes")
MAC_STAT(sess_closed, uint64_t, 1, 'a', "Session Closed")
MAC_STAT(sess_pipeline, uint64_t, 1, 'a', "Session Pipeline")
MAC_STAT(sess_readahead, uint64_t, 1, 'a', "Session Read Ahead")
MAC_STAT(sess_linger, uint64_t, 1, 'a', "Session Linger")
MAC_STAT(sess_herd, uint64_t, 1, 'a', "Session herd")
MAC_STAT(shm_records, uint64_t, 0, 'a', "SHM records")
MAC_STAT(shm_writes, uint64_t, 0, 'a', "SHM writes")
......
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