Still ironing out stats.

This commit is contained in:
Gregory Burd 2013-06-27 10:57:41 -04:00
parent c41e411a92
commit c7b45a7c2b
5 changed files with 27 additions and 27 deletions

View file

@ -320,6 +320,7 @@ async_nif_enqueue_req(struct async_nif_state* async_nif, struct async_nif_req_en
if (!fifo_q_full(reqs, q->reqs)) { if (!fifo_q_full(reqs, q->reqs)) {
await = __stat_mean_log2(async_nif->qwait_stat); await = __stat_mean_log2(async_nif->qwait_stat);
await_inthisq = __stat_mean_log2(q->qwait_stat); await_inthisq = __stat_mean_log2(q->qwait_stat);
//DPRINTF("q:%d %f/%f", qid, await_inthisq, await);
if (await_inthisq > await) { if (await_inthisq > await) {
enif_mutex_unlock(q->reqs_mutex); enif_mutex_unlock(q->reqs_mutex);
qid = (qid + 1) % async_nif->num_queues; qid = (qid + 1) % async_nif->num_queues;

View file

@ -99,40 +99,27 @@ __stat_mean_log2(struct stat *s)
uint64_t uint64_t
__stat_tick(struct stat *s) __stat_tick(struct stat *s)
{ {
duration_t *d;
uint64_t t; uint64_t t;
if (!s) if (!s)
return 0.0; return 0.0;
d = (duration_t*)erl_drv_tsd_get(s->duration_key); t = ts(s->d.unit);
if (!d) { s->d.then = t;
if ((d = enif_alloc(sizeof(duration_t))) == NULL)
return 0;
memset(d, 0, sizeof(duration_t));
erl_drv_tsd_set(s->duration_key, d);
}
t = ts(d->unit);
d->then = t;
return t; return t;
} }
void void
__stat_reset(struct stat *s) __stat_reset(struct stat *s)
{ {
duration_t *d;
if (!s) if (!s)
return; return;
s->min = ~0;
s->max = 0;
s->h = 0; s->h = 0;
s->d.unit = ns;
s->d.then = 0;
memset(s->histogram, 0, sizeof(uint64_t) * 64); memset(s->histogram, 0, sizeof(uint64_t) * 64);
memset(s->samples, 0, sizeof(uint64_t) * s->num_samples); memset(s->samples, 0, sizeof(uint64_t) * s->num_samples);
d = (duration_t*)erl_drv_tsd_get(s->duration_key);
if (d)
d->then = 0;
} }
uint64_t uint64_t
@ -146,10 +133,7 @@ __stat_tock(struct stat *s)
if (!s) if (!s)
return 0.0; return 0.0;
d = (duration_t*)erl_drv_tsd_get(s->duration_key); d = &s->d;
if (!d)
return 0;
now = ts(d->unit); now = ts(d->unit);
elapsed = now - d->then; elapsed = now - d->then;
i = s->h; i = s->h;
@ -160,7 +144,7 @@ __stat_tock(struct stat *s)
} }
s->h = (s->h + 1) % s->num_samples; s->h = (s->h + 1) % s->num_samples;
s->samples[i] = elapsed; s->samples[i] = elapsed;
if (elapsed < s->min) if (elapsed != 0 && elapsed < s->min)
s->min = elapsed; s->min = elapsed;
if (elapsed > s->max) if (elapsed > s->max)
s->max = elapsed; s->max = elapsed;
@ -255,6 +239,6 @@ __stat_init(uint32_t n)
s->mean = 0.0; s->mean = 0.0;
s->h = 0; s->h = 0;
s->num_samples = n; s->num_samples = n;
erl_drv_tsd_key_create(NULL, &(s->duration_key)); s->d.unit = ns;
return s; return s;
} }

View file

@ -30,7 +30,7 @@ extern "C" {
#define STAT_DEF(name) struct stat *name ## _stat; #define STAT_DEF(name) struct stat *name ## _stat;
struct stat { struct stat {
ErlDrvTSDKey duration_key; duration_t d;
uint32_t h, n, num_samples; uint32_t h, n, num_samples;
uint64_t min, max; uint64_t min, max;
double mean; double mean;

View file

@ -193,12 +193,11 @@ static inline uint32_t __log2(uint64_t x) {
static int static int
__ctx_cache_evict(WterlConnHandle *conn_handle) __ctx_cache_evict(WterlConnHandle *conn_handle)
{ {
static uint16_t ncalls = 0;
uint32_t mean, log, num_evicted, i; uint32_t mean, log, num_evicted, i;
uint64_t now, elapsed; uint64_t now, elapsed;
struct wterl_ctx *c, *n; struct wterl_ctx *c, *n;
if (conn_handle->cache_size < MAX_CACHE_SIZE && ++ncalls != 0) if (conn_handle->cache_size < MAX_CACHE_SIZE)
return 0; return 0;
now = cpu_clock_ticks(); now = cpu_clock_ticks();
@ -264,7 +263,15 @@ __ctx_cache_find(WterlConnHandle *conn_handle, const uint64_t sig)
} }
c = STAILQ_NEXT(c, entries); c = STAILQ_NEXT(c, entries);
} }
#ifdef DEBUG
uint32_t sz = 0;
struct wterl_ctx *f;
STAILQ_FOREACH(f, &conn_handle->cache, entries) {
sz++;
}
#endif
enif_mutex_unlock(conn_handle->cache_mutex); enif_mutex_unlock(conn_handle->cache_mutex);
DPRINTF("cache_find: [%u:%u] %s (%p)", sz, conn_handle->cache_size, c ? "hit" : "miss", c);
return c; return c;
} }
@ -282,7 +289,15 @@ __ctx_cache_add(WterlConnHandle *conn_handle, struct wterl_ctx *c)
c->tstamp = cpu_clock_ticks(); c->tstamp = cpu_clock_ticks();
STAILQ_INSERT_TAIL(&conn_handle->cache, c, entries); STAILQ_INSERT_TAIL(&conn_handle->cache, c, entries);
conn_handle->cache_size += 1; conn_handle->cache_size += 1;
#ifdef DEBUG
uint32_t sz = 0;
struct wterl_ctx *f;
STAILQ_FOREACH(f, &conn_handle->cache, entries) {
sz++;
}
#endif
enif_mutex_unlock(conn_handle->cache_mutex); enif_mutex_unlock(conn_handle->cache_mutex);
DPRINTF("cache_add: [%u:%u] (%p)", sz, conn_handle->cache_size, c);
} }
static inline char * static inline char *

View file

@ -604,7 +604,7 @@ insert_delete_test() ->
%% lists:sort([crypto:sha(<<X>>) || X <- lists:seq(1, 2000)])). %% lists:sort([crypto:sha(<<X>>) || X <- lists:seq(1, 2000)])).
many_open_tables_test_() -> many_open_tables_test_() ->
{timeout, 60, {timeout, 120,
fun() -> fun() ->
ConnOpts = [{create,true},{cache_size,"100MB"},{session_max, 8192}], ConnOpts = [{create,true},{cache_size,"100MB"},{session_max, 8192}],
DataDir = ?TEST_DATA_DIR, DataDir = ?TEST_DATA_DIR,