r564 - in trunk/varnish-cache: bin/varnishd include
phk at projects.linpro.no
phk at projects.linpro.no
Sat Jul 22 22:57:03 CEST 2006
Author: phk
Date: 2006-07-22 22:57:02 +0200 (Sat, 22 Jul 2006)
New Revision: 564
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_pool.c
trunk/varnish-cache/bin/varnishd/cache_response.c
trunk/varnish-cache/bin/varnishd/cache_session.c
trunk/varnish-cache/include/shmlog_tags.h
trunk/varnish-cache/include/stat_field.h
Log:
Add per address, per session and total statistics.
We (will) collect data in unlocked per workerthread accumulators
and whenever the workerthread leaves the session, we charge the
bill to the srcaddr (issuing a StatAddr shmrecord), to the session
and to the global counters in the stats struct.
When sessions die we issue a StatSess shmrecord.
StatAddr and StatSess has the same format:
address
port (always zero for StatAddr)
duration (seconds)
#sessions
#requests
#pipe
#pass
#fetch
#hdrbytes
#bodybytes
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-07-22 20:57:02 UTC (rev 564)
@@ -74,6 +74,19 @@
/*--------------------------------------------------------------------*/
+struct acct {
+ time_t first;
+ uint64_t sess;
+ uint64_t req;
+ uint64_t pipe;
+ uint64_t pass;
+ uint64_t fetch;
+ uint64_t hdrbytes;
+ uint64_t bodybytes;
+};
+
+/*--------------------------------------------------------------------*/
+
struct worker {
unsigned magic;
#define WORKER_MAGIC 0x6391adcf
@@ -90,6 +103,8 @@
struct iovec iov[MAX_IOVS];
unsigned niov;
size_t liov;
+
+ struct acct acct;
};
struct workreq {
@@ -189,20 +204,24 @@
struct srcaddr {
unsigned magic;
#define SRCADDR_MAGIC 0x375111db
+
+ unsigned hash;
TAILQ_ENTRY(srcaddr) list;
- unsigned nsess;
+ struct srcaddrhead *sah;
+
char addr[TCP_ADDRBUFSIZE];
- unsigned sum;
- time_t first;
+ unsigned nref;
+
time_t ttl;
- uint64_t bytes;
- struct srcaddrhead *sah;
+
+ struct acct acct;
};
struct sess {
unsigned magic;
#define SESS_MAGIC 0x2c2f9c5a
int fd;
+ int id;
unsigned xid;
struct worker *wrk;
@@ -237,6 +256,7 @@
time_t t0;
struct workreq workreq;
+ struct acct acct;
};
struct backend {
@@ -344,7 +364,7 @@
struct sess *SES_New(struct sockaddr *addr, unsigned len);
void SES_Delete(struct sess *sp);
void SES_RefSrcAddr(struct sess *sp);
-void SES_ChargeBytes(struct sess *sp, uint64_t bytes);
+void SES_Charge(struct sess *sp);
/* cache_shmlog.c */
Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-07-22 20:57:02 UTC (rev 564)
@@ -118,6 +118,7 @@
assert(sp != NULL); /* XXX handle */
sp->fd = i;
+ sp->id = i;
#ifdef SO_NOSIGPIPE /* XXX Linux */
i = 1;
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2006-07-22 20:57:02 UTC (rev 564)
@@ -89,6 +89,7 @@
VCL_Rel(sp->vcl);
sp->vcl = NULL;
+ SES_Charge(sp);
vca_return_session(sp);
return (1);
}
@@ -316,6 +317,7 @@
if (o == NULL) {
VSL(SLT_Debug, sp->fd,
"on waiting list on obj %u", sp->obj->xid);
+ SES_Charge(sp);
return (1);
}
@@ -584,7 +586,7 @@
switch (sp->step) {
#define STEP(l,u) \
case STP_##u: \
- VSL(SLT_Debug, sp->fd, "State " #u); \
+ VSL(SLT_Debug, sp->id, "State " #u); \
done = cnt_##l(sp); \
break;
#include "steps.h"
Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-07-22 20:57:02 UTC (rev 564)
@@ -105,8 +105,10 @@
AZ(pthread_mutex_unlock(&wrk_mtx));
CHECK_OBJ_NOTNULL(wrq->sess, SESS_MAGIC);
wrq->sess->wrk = w;
- if (wrq->sess->srcaddr == NULL)
+ if (wrq->sess->srcaddr == NULL) {
+ w->acct.sess++;
SES_RefSrcAddr(wrq->sess);
+ }
if (w->nobj != NULL)
CHECK_OBJ(w->nobj, OBJECT_MAGIC);
if (w->nobjhead != NULL)
Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c 2006-07-22 20:57:02 UTC (rev 564)
@@ -138,7 +138,6 @@
{
struct storage *st;
unsigned u = 0;
- uint64_t bytes = 0;
if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
return;
@@ -162,9 +161,6 @@
WRK_Reset(sp->wrk, &sp->fd);
http_Write(sp->wrk, sp->http, 1);
-#if 0 /* XXX */
- bytes += sbuf_len(sb);
-#endif
/* XXX: conditional request handling */
if (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET")) {
TAILQ_FOREACH(st, &sp->obj->store, list) {
@@ -181,7 +177,6 @@
}
assert(u == sp->obj->len);
}
- SES_ChargeBytes(sp, bytes + u);
if (WRK_Flush(sp->wrk))
vca_close_session(sp, "remote closed");
}
Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c 2006-07-22 20:57:02 UTC (rev 564)
@@ -74,10 +74,10 @@
AZ(pthread_mutex_lock(&ses_mtx));
c3 = NULL;
TAILQ_FOREACH_SAFE(c, ch, list, c2) {
- if (c->sum == u && !strcmp(c->addr, sp->addr)) {
- if (c->nsess == 0)
+ if (c->hash == u && !strcmp(c->addr, sp->addr)) {
+ if (c->nref == 0)
VSL_stats->n_srcaddr_act++;
- c->nsess++;
+ c->nref++;
c->ttl = now + CLIENT_TTL;
sp->srcaddr = c;
TAILQ_REMOVE(ch, c, list);
@@ -90,7 +90,7 @@
AZ(pthread_mutex_unlock(&ses_mtx));
return;
}
- if (c->nsess > 0 || c->ttl > now)
+ if (c->nref > 0 || c->ttl > now)
continue;
if (c3 == NULL) {
c3 = c;
@@ -111,10 +111,10 @@
if (c3 != NULL) {
memset(c3, 0, sizeof *c3);
strcpy(c3->addr, sp->addr);
- c3->sum = u;
- c3->first = now;
+ c3->hash = u;
+ c3->acct.first = now;
c3->ttl = now + CLIENT_TTL;
- c3->nsess = 1;
+ c3->nref = 1;
c3->sah = ch;
VSL_stats->n_srcaddr_act++;
TAILQ_INSERT_TAIL(ch, c3, list);
@@ -123,24 +123,42 @@
AZ(pthread_mutex_unlock(&ses_mtx));
}
+static void
+ses_sum_acct(struct acct *sum, struct acct *inc)
+{
+
+ sum->sess += inc->sess;
+ sum->req += inc->req;
+ sum->pipe += inc->pipe;
+ sum->pass += inc->pass;
+ sum->fetch += inc->fetch;
+ sum->hdrbytes += inc->hdrbytes;
+ sum->bodybytes += inc->bodybytes;
+}
+
void
-SES_ChargeBytes(struct sess *sp, uint64_t bytes)
+SES_Charge(struct sess *sp)
{
- struct srcaddr *sa;
- time_t now;
+ struct acct *a = &sp->wrk->acct;
+ struct acct *b = &sp->srcaddr->acct;
- assert(sp->srcaddr != NULL);
- sa = sp->srcaddr;
- now = time(NULL);
+ ses_sum_acct(&sp->acct, a);
+
AZ(pthread_mutex_lock(&ses_mtx));
- sa->bytes += bytes;
- sa->ttl = now + CLIENT_TTL;
- TAILQ_REMOVE(sa->sah, sa, list);
- TAILQ_INSERT_TAIL(sa->sah, sa, list);
- bytes = sa->bytes;
+ ses_sum_acct(b, a);
+ VSL(SLT_StatAddr, sp->id, "%s 0 %d %ju %ju %ju %ju %ju %ju %ju",
+ sp->srcaddr->addr, time(NULL) - b->first,
+ b->sess, b->req, b->pipe, b->pass,
+ b->fetch, b->hdrbytes, b->bodybytes);
+ VSL_stats->s_sess += a->sess;
+ VSL_stats->s_req += a->req;
+ VSL_stats->s_pipe += a->pipe;
+ VSL_stats->s_pass += a->pass;
+ VSL_stats->s_fetch += a->fetch;
+ VSL_stats->s_hdrbytes += a->hdrbytes;
+ VSL_stats->s_bodybytes += a->bodybytes;
AZ(pthread_mutex_unlock(&ses_mtx));
- VSL(SLT_SrcAddr, sp->fd, "%s %jd %d",
- sa->addr, (intmax_t)(bytes), now - sa->first);
+ memset(a, 0, sizeof *a);
}
static void
@@ -153,9 +171,9 @@
}
assert(sp->srcaddr != NULL);
AZ(pthread_mutex_lock(&ses_mtx));
- assert(sp->srcaddr->nsess > 0);
- sp->srcaddr->nsess--;
- if (sp->srcaddr->nsess == 0)
+ assert(sp->srcaddr->nref > 0);
+ sp->srcaddr->nref--;
+ if (sp->srcaddr->nref == 0)
VSL_stats->n_srcaddr_act--;
sp->srcaddr = NULL;
AZ(pthread_mutex_unlock(&ses_mtx));
@@ -183,17 +201,26 @@
assert(len < sizeof(sm->sockaddr));
memcpy(sm->sess.sockaddr, addr, len);
sm->sess.sockaddrlen = len;
+
http_Setup(&sm->http, (void *)(sm + 1), heritage.mem_workspace);
+
+ sm->sess.acct.first = time(NULL);
+
return (&sm->sess);
}
void
SES_Delete(struct sess *sp)
{
+ struct acct *b = &sp->acct;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
VSL_stats->n_sess--;
ses_relsrcaddr(sp);
+ VSL(SLT_StatSess, sp->id, "%s %s %d %ju %ju %ju %ju %ju %ju %ju",
+ sp->addr, sp->port, time(NULL) - b->first,
+ b->sess, b->req, b->pipe, b->pass,
+ b->fetch, b->hdrbytes, b->bodybytes);
CHECK_OBJ_NOTNULL(sp->mem, SESSMEM_MAGIC);
free(sp->mem);
}
Modified: trunk/varnish-cache/include/shmlog_tags.h
===================================================================
--- trunk/varnish-cache/include/shmlog_tags.h 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/include/shmlog_tags.h 2006-07-22 20:57:02 UTC (rev 564)
@@ -11,7 +11,8 @@
SLTM(Debug)
SLTM(Error)
SLTM(CLI)
-SLTM(SrcAddr)
+SLTM(StatAddr)
+SLTM(StatSess)
SLTM(SessionOpen)
SLTM(SessionReuse)
SLTM(SessionClose)
Modified: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h 2006-07-22 16:55:17 UTC (rev 563)
+++ trunk/varnish-cache/include/stat_field.h 2006-07-22 20:57:02 UTC (rev 564)
@@ -29,3 +29,11 @@
MAC_STAT(n_deathrow, uint64_t, "u", "N objects on deathrow")
MAC_STAT(losthdr, uint64_t, "u", "HTTP header overflows")
+
+MAC_STAT(s_sess, uint64_t, "u", "Total Sessions")
+MAC_STAT(s_req, uint64_t, "u", "Total Requests")
+MAC_STAT(s_pipe, uint64_t, "u", "Total pipe")
+MAC_STAT(s_pass, uint64_t, "u", "Total pass")
+MAC_STAT(s_fetch, uint64_t, "u", "Total fetch")
+MAC_STAT(s_hdrbytes, uint64_t, "u", "Total header bytes")
+MAC_STAT(s_bodybytes, uint64_t, "u", "Total body bytes")
More information about the varnish-commit
mailing list