Commit ae99dfc7 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

measure cache table wait time. addresses #1483

git-svn-id: file:///svn/toku/tokudb@9633 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3e7fe1ad
...@@ -39,10 +39,16 @@ static void cachetable_reader(WORKITEM); ...@@ -39,10 +39,16 @@ static void cachetable_reader(WORKITEM);
#define WHEN_TRACE_CT(x) ((void)0) #define WHEN_TRACE_CT(x) ((void)0)
#endif #endif
#define TOKU_DO_WAIT_TIME 0
static u_int64_t cachetable_hit; static u_int64_t cachetable_hit;
static u_int64_t cachetable_miss; static u_int64_t cachetable_miss;
static u_int64_t cachetable_wait_reading; static u_int64_t cachetable_wait_reading;
static u_int64_t cachetable_wait; static u_int64_t cachetable_wait;
#if TOKU_DO_WAIT_TIME
static u_int64_t cachetable_miss_time;
static u_int64_t cachetable_wait_time;
#endif
enum ctpair_state { enum ctpair_state {
CTPAIR_INVALID = 0, // invalid CTPAIR_INVALID = 0, // invalid
...@@ -826,6 +832,12 @@ int toku_cachetable_put(CACHEFILE cachefile, CACHEKEY key, u_int32_t fullhash, v ...@@ -826,6 +832,12 @@ int toku_cachetable_put(CACHEFILE cachefile, CACHEKEY key, u_int32_t fullhash, v
return 0; return 0;
} }
#if TOKU_DO_WAIT_TIME
static u_int64_t tdelta(struct timeval *tnew, struct timeval *told) {
return (tnew->tv_sec * 1000000ULL + tnew->tv_usec) - (told->tv_sec * 1000000ULL + told->tv_usec);
}
#endif
int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t fullhash, void**value, long *sizep, int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t fullhash, void**value, long *sizep,
CACHETABLE_FLUSH_CALLBACK flush_callback, CACHETABLE_FLUSH_CALLBACK flush_callback,
CACHETABLE_FETCH_CALLBACK fetch_callback, void *extraargs) { CACHETABLE_FETCH_CALLBACK fetch_callback, void *extraargs) {
...@@ -837,13 +849,28 @@ int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t ful ...@@ -837,13 +849,28 @@ int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t ful
for (p=ct->table[fullhash&(ct->table_size-1)]; p; p=p->hash_chain) { for (p=ct->table[fullhash&(ct->table_size-1)]; p; p=p->hash_chain) {
count++; count++;
if (p->key.b==key.b && p->cachefile==cachefile) { if (p->key.b==key.b && p->cachefile==cachefile) {
#if TOKU_DO_WAIT_TIME
struct timeval t0;
int do_wait_time = 0;
#endif
if (p->rwlock.writer || p->rwlock.want_write) { if (p->rwlock.writer || p->rwlock.want_write) {
if (p->state == CTPAIR_READING) if (p->state == CTPAIR_READING)
cachetable_wait_reading++; cachetable_wait_reading++;
else else
cachetable_wait++; cachetable_wait++;
#if TOKU_DO_WAIT_TIME
do_wait_time = 1;
gettimeofday(&t0, NULL);
#endif
} }
ctpair_read_lock(&p->rwlock, ct->mutex); ctpair_read_lock(&p->rwlock, ct->mutex);
#if TOKU_DO_WAIT_TIME
if (do_wait_time) {
struct timeval tnow;
gettimeofday(&tnow, NULL);
cachetable_wait_time += tdelta(&tnow, &t0);
}
#endif
if (p->state == CTPAIR_INVALID) { if (p->state == CTPAIR_INVALID) {
ctpair_read_unlock(&p->rwlock); ctpair_read_unlock(&p->rwlock);
if (ctpair_users(&p->rwlock) == 0) if (ctpair_users(&p->rwlock) == 0)
...@@ -868,17 +895,26 @@ int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t ful ...@@ -868,17 +895,26 @@ int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t ful
p = cachetable_insert_at(ct, cachefile, key, zero_value, CTPAIR_READING, fullhash, zero_size, flush_callback, fetch_callback, extraargs, CACHETABLE_CLEAN, ZERO_LSN); p = cachetable_insert_at(ct, cachefile, key, zero_value, CTPAIR_READING, fullhash, zero_size, flush_callback, fetch_callback, extraargs, CACHETABLE_CLEAN, ZERO_LSN);
assert(p); assert(p);
ctpair_write_lock(&p->rwlock, ct->mutex); ctpair_write_lock(&p->rwlock, ct->mutex);
#if TOKU_DO_WAIT_TIME
struct timeval t0;
gettimeofday(&t0, NULL);
#endif
r = cachetable_fetch_pair(ct, cachefile, p); r = cachetable_fetch_pair(ct, cachefile, p);
if (r) { if (r) {
cachetable_unlock(ct); cachetable_unlock(ct);
return r; return r;
} }
cachetable_miss++;
#if TOKU_DO_WAIT_TIME
struct timeval tnow;
gettimeofday(&tnow, NULL);
cachetable_miss_time += tdelta(&tnow, &t0);
#endif
ctpair_read_lock(&p->rwlock, ct->mutex); ctpair_read_lock(&p->rwlock, ct->mutex);
assert(p->state == CTPAIR_IDLE); assert(p->state == CTPAIR_IDLE);
*value = p->value; *value = p->value;
if (sizep) *sizep = p->size; if (sizep) *sizep = p->size;
cachetable_miss++;
} }
r = maybe_flush_some(ct, 0); r = maybe_flush_some(ct, 0);
cachetable_unlock(ct); cachetable_unlock(ct);
......
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