diff options
author | Keith Bostic <keith@wiredtiger.com> | 2014-09-13 09:23:52 -0400 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2014-09-13 09:23:52 -0400 |
commit | 031e80a87a8bbf986e7f4665a91196785ba4c52d (patch) | |
tree | 68610bc5b93ab9a4e4ad96e425d2340ada5b9d79 /bench | |
parent | ef58f295c74f94f9612851628da26336088469c7 (diff) | |
download | mongo-031e80a87a8bbf986e7f4665a91196785ba4c52d.tar.gz |
Make random number generation be per session in the WiredTiger library,
and per thread in wtperf and test/checkpoint, reference #1223.
Diffstat (limited to 'bench')
-rw-r--r-- | bench/wtperf/wtperf.c | 49 | ||||
-rw-r--r-- | bench/wtperf/wtperf.h | 2 |
2 files changed, 29 insertions, 22 deletions
diff --git a/bench/wtperf/wtperf.c b/bench/wtperf/wtperf.c index 002c1327e01..785f81ce668 100644 --- a/bench/wtperf/wtperf.c +++ b/bench/wtperf/wtperf.c @@ -83,7 +83,7 @@ static int execute_workload(CONFIG *); static int find_table_count(CONFIG *); static void *monitor(void *); static void *populate_thread(void *); -static void randomize_value(CONFIG *, char *); +static void randomize_value(CONFIG_THREAD *, char *); static int start_all_runs(CONFIG *); static int start_run(CONFIG *); static int start_threads(CONFIG *, @@ -91,7 +91,7 @@ static int start_threads(CONFIG *, static int stop_threads(CONFIG *, u_int, CONFIG_THREAD *); static void *thread_run_wtperf(void *); static void *worker(void *); -static uint64_t wtperf_rand(CONFIG *); +static uint64_t wtperf_rand(CONFIG_THREAD *); static uint64_t wtperf_value_range(CONFIG *); #define HELIUM_NAME "dev1" @@ -100,11 +100,12 @@ static uint64_t wtperf_value_range(CONFIG *); #define HELIUM_CONFIG ",type=helium" /* - * wtperf uses a couple of internal WiredTiger library routines for timing - * and generating random numbers. + * wtperf uses internal WiredTiger library routines for timing and generating + * random numbers. */ extern int __wt_epoch(void *, struct timespec *); -extern uint32_t __wt_random(void); +extern uint32_t __wt_random(uint32_t *); +extern void __wt_random_init(uint32_t *); /* Retrieve an ID for the next insert operation. */ static inline uint64_t @@ -130,7 +131,7 @@ generate_key(CONFIG *cfg, char *key_buf, uint64_t keyno) } static void -randomize_value(CONFIG *cfg, char *value_buf) +randomize_value(CONFIG_THREAD *thread, char *value_buf) { uint8_t *vb; uint32_t i; @@ -140,13 +141,13 @@ randomize_value(CONFIG *cfg, char *value_buf) * randomly chosen byte (other than the trailing NUL). * Make sure we don't write a NUL: keep the value the same length. */ - i = __wt_random() % (cfg->value_sz - 1); + i = __wt_random(thread->rnd) % (thread->cfg->value_sz - 1); while (value_buf[i] == '\0' && i > 0) --i; if (i > 0) { vb = (uint8_t *)value_buf; - vb[0] = (__wt_random() % 255) + 1; - vb[i] = (__wt_random() % 255) + 1; + vb[0] = (__wt_random(thread->rnd) % 255) + 1; + vb[i] = (__wt_random(thread->rnd) % 255) + 1; } } @@ -317,13 +318,13 @@ worker_async(void *arg) case WORKER_INSERT: case WORKER_INSERT_RMW: if (cfg->random_range) - next_val = wtperf_rand(cfg); + next_val = wtperf_rand(thread); else next_val = cfg->icount + get_next_incr(cfg); break; case WORKER_READ: case WORKER_UPDATE: - next_val = wtperf_rand(cfg); + next_val = wtperf_rand(thread); /* * If the workload is started without a populate phase @@ -361,14 +362,14 @@ worker_async(void *arg) goto op_err; case WORKER_INSERT: if (cfg->random_value) - randomize_value(cfg, value_buf); + randomize_value(thread, value_buf); asyncop->set_value(asyncop, value_buf); if ((ret = asyncop->insert(asyncop)) == 0) break; goto op_err; case WORKER_UPDATE: if (cfg->random_value) - randomize_value(cfg, value_buf); + randomize_value(thread, value_buf); asyncop->set_value(asyncop, value_buf); if ((ret = asyncop->update(asyncop)) == 0) break; @@ -455,7 +456,7 @@ worker(void *arg) case WORKER_INSERT_RMW: trk = &thread->insert; if (cfg->random_range) - next_val = wtperf_rand(cfg); + next_val = wtperf_rand(thread); else next_val = cfg->icount + get_next_incr(cfg); break; @@ -465,7 +466,7 @@ worker(void *arg) case WORKER_UPDATE: if (*op == WORKER_UPDATE) trk = &thread->update; - next_val = wtperf_rand(cfg); + next_val = wtperf_rand(thread); /* * If the workload is started without a populate phase @@ -532,7 +533,7 @@ worker(void *arg) /* FALLTHROUGH */ case WORKER_INSERT: if (cfg->random_value) - randomize_value(cfg, value_buf); + randomize_value(thread, value_buf); cursor->set_value(cursor, value_buf); if ((ret = cursor->insert(cursor)) == 0) break; @@ -556,7 +557,7 @@ worker(void *arg) else value_buf[0] = 'a'; if (cfg->random_value) - randomize_value(cfg, value_buf); + randomize_value(thread, value_buf); cursor->set_value(cursor, value_buf); if ((ret = cursor->update(cursor)) == 0) break; @@ -812,7 +813,7 @@ populate_thread(void *arg) } cursor->set_key(cursor, key_buf); if (cfg->random_value) - randomize_value(cfg, value_buf); + randomize_value(thread, value_buf); cursor->set_value(cursor, value_buf); if ((ret = cursor->insert(cursor)) != 0) { lprintf(cfg, ret, 0, "Failed inserting"); @@ -941,7 +942,7 @@ populate_async(void *arg) generate_key(cfg, key_buf, op); asyncop->set_key(asyncop, key_buf); if (cfg->random_value) - randomize_value(cfg, value_buf); + randomize_value(thread, value_buf); asyncop->set_value(asyncop, value_buf); if ((ret = asyncop->insert(asyncop)) != 0) { lprintf(cfg, ret, 0, "Failed inserting"); @@ -2112,6 +2113,7 @@ start_threads(CONFIG *cfg, for (i = 0; i < num; ++i, ++thread) { thread->cfg = cfg; + __wt_random_init(thread->rnd); thread->workload = workp; /* @@ -2129,7 +2131,7 @@ start_threads(CONFIG *cfg, */ memset(thread->value_buf, 'a', cfg->value_sz - 1); if (cfg->random_value) - randomize_value(cfg, thread->value_buf); + randomize_value(thread, thread->value_buf); /* * Every thread gets tracking information and is initialized @@ -2190,16 +2192,19 @@ wtperf_value_range(CONFIG *cfg) } static uint64_t -wtperf_rand(CONFIG *cfg) +wtperf_rand(CONFIG_THREAD *thread) { + CONFIG *cfg; double S1, S2, U; uint64_t rval; + cfg = thread->cfg; + /* * Use WiredTiger's random number routine: it's lock-free and fairly * good. */ - rval = (uint64_t)__wt_random(); + rval = (uint64_t)__wt_random(thread->rnd); /* Use Pareto distribution to give 80/20 hot/cold values. */ if (cfg->pareto) { diff --git a/bench/wtperf/wtperf.h b/bench/wtperf/wtperf.h index fa5994b7bcf..2845762f50b 100644 --- a/bench/wtperf/wtperf.h +++ b/bench/wtperf/wtperf.h @@ -191,6 +191,8 @@ typedef struct { struct __config_thread { /* Per-thread structure */ CONFIG *cfg; /* Enclosing configuration */ + uint32_t rnd[2]; /* Random number generation state */ + pthread_t handle; /* Handle */ char *key_buf, *value_buf; /* Key/value memory */ |