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)) {
await = __stat_mean_log2(async_nif->qwait_stat);
await_inthisq = __stat_mean_log2(q->qwait_stat);
//DPRINTF("q:%d %f/%f", qid, await_inthisq, await);
if (await_inthisq > await) {
enif_mutex_unlock(q->reqs_mutex);
qid = (qid + 1) % async_nif->num_queues;

View file

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

View file

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

View file

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

View file

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