diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 30e8d2a..de46dbe 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -142,6 +142,8 @@ int64 latency_limit = 0; char *tablespace = NULL; char *index_tablespace = NULL; +bool single_writer_multi_reader = false; + /* * end of configurable parameters *********************************************************************/ @@ -1143,6 +1145,15 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa top: INSTR_TIME_SET_ZERO(now); + /* hacked to run single writer, multi-reader test. */ + if (single_writer_multi_reader) + { + if (thread->tid == 0) + st->use_file = 0; + else + st->use_file = 1; + } + commands = sql_files[st->use_file]; /* @@ -1327,7 +1338,18 @@ top: if (commands[st->state] == NULL) { st->state = 0; - st->use_file = (int) getrand(thread, 0, num_files - 1); + + /* hacked to run single writer, multi-reader test. */ + if (single_writer_multi_reader) + { + if (thread->tid == 0) + st->use_file = 0; + else + st->use_file = 1; + } + else + st->use_file = (int) getrand(thread, 0, num_files - 1); + commands = sql_files[st->use_file]; st->is_throttled = false; @@ -2619,6 +2641,8 @@ printResults(int ttype, int64 normal_xacts, int nclients, if (ttype == 0) s = "TPC-B (sort of)"; + else if (ttype == 3) + s = "SELECT only and Update only"; else if (ttype == 2) s = "Update only pgbench_accounts"; else if (ttype == 1) @@ -2850,7 +2874,7 @@ main(int argc, char **argv) state = (CState *) pg_malloc(sizeof(CState)); memset(state, 0, sizeof(CState)); - while ((c = getopt_long(argc, argv, "ih:nvp:dqSNc:j:Crs:t:T:U:lf:D:F:M:P:R:L:", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "ih:nvp:dqSNWc:j:Crs:t:T:U:lf:D:F:M:P:R:L:", long_options, &optindex)) != -1) { switch (c) { @@ -2880,6 +2904,11 @@ main(int argc, char **argv) ttype = 2; benchmarking_option_set = true; break; + case 'W': + ttype = 3; + benchmarking_option_set = true; + single_writer_multi_reader = true; + break; case 'c': benchmarking_option_set = true; nclients = atoi(optarg); @@ -3245,7 +3274,7 @@ main(int argc, char **argv) exit(1); } - if (ttype != 3) + if (ttype != 4) { /* * get the scaling factor that should be same as count(*) from @@ -3350,6 +3379,14 @@ main(int argc, char **argv) num_files = 1; break; + case 3: + sql_files[0] = process_builtin(simple_update, + ""); + sql_files[1] = process_builtin(select_only, + ""); + num_files = 2; + break; + default: break; } @@ -3568,10 +3605,23 @@ threadRun(void *arg) for (i = 0; i < nstate; i++) { CState *st = &state[i]; - Command **commands = sql_files[st->use_file]; + Command **commands; int prev_ecnt = st->ecnt; - st->use_file = getrand(thread, 0, num_files - 1); + /* hacked to run single writer, multi-reader test. */ + if (single_writer_multi_reader) + { + if (thread->tid == 0) + st->use_file = 0; + else + st->use_file = 1; + } + + commands = sql_files[st->use_file]; + + if (!single_writer_multi_reader) + st->use_file = getrand(thread, 0, num_files - 1); + if (!doCustom(thread, st, &thread->conn_time, logfile, &aggs)) remains--; /* I've aborted */ @@ -3599,9 +3649,20 @@ threadRun(void *arg) for (i = 0; i < nstate; i++) { CState *st = &state[i]; - Command **commands = sql_files[st->use_file]; + Command **commands; int sock; + /* hacked to run single writer, multi-reader test. */ + if (single_writer_multi_reader) + { + if (thread->tid == 0) + st->use_file = 0; + else + st->use_file = 1; + } + + commands = sql_files[st->use_file]; + if (st->con == NULL) { continue; @@ -3705,9 +3766,20 @@ threadRun(void *arg) for (i = 0; i < nstate; i++) { CState *st = &state[i]; - Command **commands = sql_files[st->use_file]; + Command **commands; int prev_ecnt = st->ecnt; + /* hacked to run single writer, multi-reader test. */ + if (single_writer_multi_reader) + { + if (thread->tid == 0) + st->use_file = 0; + else + st->use_file = 1; + } + + commands = sql_files[st->use_file]; + if (st->con && (FD_ISSET(PQsocket(st->con), &input_mask) || commands[st->state]->type == META_COMMAND)) {