[experimental-ims] ad277d2 Add a facility to give each session a unique number with a minimum of locking: Each pool fetches blocks of numbers to assign, then hands them out one by one using the existing lock.
Geoff Simmons
geoff at varnish-cache.org
Tue Feb 14 17:49:35 CET 2012
commit ad277d29774e800c9a2e7059b759e50225d0e448
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Feb 14 07:36:49 2012 +0000
Add a facility to give each session a unique number with a minimum of
locking: Each pool fetches blocks of numbers to assign, then hands them
out one by one using the existing lock.
Session numbers are 32bit and start at zero on worker process startup.
Together with another 32bit number, local to the session, they will
be used to link VSL records into transactions.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index dd3b004..ad23c24 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -252,6 +252,13 @@ struct vsl_log {
/*--------------------------------------------------------------------*/
+struct vxid {
+ uint32_t next;
+ uint32_t count;
+};
+
+/*--------------------------------------------------------------------*/
+
struct wrk_accept {
unsigned magic;
#define WRK_ACCEPT_MAGIC 0x8c4b4d59
@@ -261,6 +268,7 @@ struct wrk_accept {
socklen_t acceptaddrlen;
int acceptsock;
struct listen_sock *acceptlsock;
+ uint32_t vxid;
};
/* Worker pool stuff -------------------------------------------------*/
@@ -626,6 +634,8 @@ struct sess {
enum step step;
int fd;
unsigned vsl_id;
+ uint32_t vxid;
+ uint32_t vseq;
/* Cross references ------------------------------------------*/
@@ -834,6 +844,7 @@ int HTC_Complete(struct http_conn *htc);
#undef HTTPH
/* cache_main.c */
+uint32_t VXID_Get(struct vxid *v);
extern volatile struct params * cache_param;
void THR_SetName(const char *name);
const char* THR_GetName(void);
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 9384d1c..4d7b771 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -249,6 +249,8 @@ VCA_SetupSess(struct worker *wrk)
CAST_OBJ_NOTNULL(wa, (void*)wrk->aws->f, WRK_ACCEPT_MAGIC);
sp = wrk->sp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ sp->vxid = wa->vxid;
+ sp->vseq = 0;
sp->fd = wa->acceptsock;
sp->vsl_id = wa->acceptsock | VSL_CLIENTMARKER ;
wa->acceptsock = -1;
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 48e934d..f038c9e 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -85,6 +85,33 @@ THR_GetName(void)
}
/*--------------------------------------------------------------------
+ */
+
+static uint32_t vxid_base;
+static struct lock vxid_lock;
+
+static void
+vxid_More(struct vxid *v)
+{
+
+ Lck_Lock(&vxid_lock);
+ v->next = vxid_base;
+ v->count = 32768;
+ vxid_base = v->count;
+ Lck_Unlock(&vxid_lock);
+}
+
+uint32_t
+VXID_Get(struct vxid *v)
+{
+ if (v->count == 0)
+ vxid_More(v);
+ AN(v->count);
+ v->count--;
+ return (v->next++);
+}
+
+/*--------------------------------------------------------------------
* XXX: Think more about which order we start things
*/
@@ -107,6 +134,8 @@ child_main(void)
LCK_Init(); /* Second, locking */
+ Lck_New(&vxid_lock, lck_vxid);
+
WAIT_Init();
PAN_Init();
CLI_Init();
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index be4af0a..c6253b2 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -100,6 +100,8 @@ struct pool {
struct lock herder_mtx;
pthread_t herder_thr;
+ struct vxid vxid;
+
struct lock mtx;
struct taskhead idle_queue;
struct taskhead front_queue;
@@ -182,6 +184,7 @@ pool_accept(struct worker *wrk, void *arg)
}
Lck_Lock(&pp->mtx);
+ wa->vxid = VXID_Get(&pp->vxid);
wrk2 = pool_getidleworker(pp, 0);
if (wrk2 == NULL) {
/* No idle threads, do it ourselves */
More information about the varnish-commit
mailing list