From: Michael Vrable Date: Sun, 20 Feb 2011 03:30:49 +0000 (-0800) Subject: Change how mixed read/write workloads are done in mixedbench X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=c8feda79feb6bed1e8a65b4e46789e8a6133f65b;p=bluesky.git Change how mixed read/write workloads are done in mixedbench Split reads and writes into separate threads, instead of mixing operations within a single thread. This does not allow arbitrary mixes any longer, since the ratios are quantized based on the number of total threads. --- diff --git a/microbench/mixedbench.c b/microbench/mixedbench.c index 50dae27..0447fd1 100644 --- a/microbench/mixedbench.c +++ b/microbench/mixedbench.c @@ -29,6 +29,8 @@ int opt_filesize, opt_filecount, opt_threads, opt_duration, opt_intervals, opt_dirsize; double opt_writeratio, opt_ops; +int write_threads; + struct thread_state { pthread_t thread; pthread_mutex_t lock; @@ -93,12 +95,10 @@ void benchmark_op(struct thread_state *ts) char filename[256]; int n = get_random(opt_filecount); int n1 = n / opt_dirsize, n2 = n % opt_dirsize; - sprintf(filename, "t%d/%d/%d", ts->thread_num, n1, n2); - - double r = get_random(1000000) / 1e6; - if (r >= opt_writeratio) { + if (ts->thread_num >= write_threads) { /* Read */ + sprintf(filename, "t%d/%d/%d", ts->thread_num - write_threads, n1, n2); FILE *f = fopen(filename, "rb"); if (f == NULL) { perror("fopen"); @@ -117,6 +117,7 @@ void benchmark_op(struct thread_state *ts) pthread_mutex_unlock(&ts->lock); } else { /* Write */ + sprintf(filename, "t%d/%d/%d", ts->thread_num, n1, n2); FILE *f = fopen(filename, "wb"); if (f == NULL) { perror("fopen"); @@ -232,6 +233,12 @@ int main(int argc, char *argv[]) start_time = now_hires(); + /* Partition threads into those that should do reads and those for writes, + * as close as possible to the desired allocation. */ + write_threads = (int)round(opt_threads * opt_writeratio); + fprintf(stderr, "Using %d threads for reads, %d for writes\n", + opt_threads - write_threads, write_threads); + for (int i = 0; i < opt_threads; i++) { launch_thread(i); }