summaryrefslogtreecommitdiff
path: root/source4/cluster/ctdb/tests/ctdb_bench.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/cluster/ctdb/tests/ctdb_bench.c')
-rw-r--r--source4/cluster/ctdb/tests/ctdb_bench.c113
1 files changed, 94 insertions, 19 deletions
diff --git a/source4/cluster/ctdb/tests/ctdb_bench.c b/source4/cluster/ctdb/tests/ctdb_bench.c
index 01a8cc0f15..023c76e7f9 100644
--- a/source4/cluster/ctdb/tests/ctdb_bench.c
+++ b/source4/cluster/ctdb/tests/ctdb_bench.c
@@ -43,6 +43,7 @@ static double end_timer(void)
static int timelimit = 10;
static int num_records = 10;
+static int num_msgs = 1;
static int num_repeats = 100;
enum my_functions {FUNC_INCR=1, FUNC_FETCH=2};
@@ -50,7 +51,7 @@ enum my_functions {FUNC_INCR=1, FUNC_FETCH=2};
/*
ctdb call function to increment an integer
*/
-static int incr_func(struct ctdb_call *call)
+static int incr_func(struct ctdb_call_info *call)
{
if (call->record_data.dsize == 0) {
call->new_data = talloc(call, TDB_DATA);
@@ -70,7 +71,7 @@ static int incr_func(struct ctdb_call *call)
/*
ctdb call function to fetch a record
*/
-static int fetch_func(struct ctdb_call *call)
+static int fetch_func(struct ctdb_call_info *call)
{
call->reply_data = &call->record_data;
return 0;
@@ -79,20 +80,25 @@ static int fetch_func(struct ctdb_call *call)
/*
benchmark incrementing an integer
*/
-static void bench_incr(struct ctdb_context *ctdb)
+static void bench_incr(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db)
{
- TDB_DATA key, data;
int loops=0;
int ret, i;
+ struct ctdb_call call;
+
+ ZERO_STRUCT(call);
start_timer();
while (1) {
uint32_t v = loops % num_records;
- key.dptr = &v;
- key.dsize = 4;
+
+ call.call_id = FUNC_INCR;
+ call.key.dptr = (uint8_t *)&v;
+ call.key.dsize = 4;
+
for (i=0;i<num_repeats;i++) {
- ret = ctdb_call(ctdb, key, FUNC_INCR, NULL, NULL);
+ ret = ctdb_call(ctdb_db, &call);
if (ret != 0) {
printf("incr call failed - %s\n", ctdb_errstr(ctdb));
return;
@@ -105,22 +111,91 @@ static void bench_incr(struct ctdb_context *ctdb)
}
}
- ret = ctdb_call(ctdb, key, FUNC_FETCH, NULL, &data);
+ call.call_id = FUNC_FETCH;
+
+ ret = ctdb_call(ctdb_db, &call);
if (ret == -1) {
printf("ctdb_call FUNC_FETCH failed - %s\n", ctdb_errstr(ctdb));
return;
}
printf("Incr: %.2f ops/sec (loops=%d val=%d)\n",
- num_repeats*loops/end_timer(), loops, *(uint32_t *)data.dptr);
+ num_repeats*loops/end_timer(), loops, *(uint32_t *)call.reply_data.dptr);
}
+static int msg_count;
+static int msg_plus, msg_minus;
+
+/*
+ handler for messages in bench_ring()
+*/
+static void ring_message_handler(struct ctdb_context *ctdb, uint32_t srvid,
+ TDB_DATA data, void *private)
+{
+ int incr = *(int *)data.dptr;
+ int *count = (int *)private;
+ int dest;
+ (*count)++;
+ dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+ ctdb_send_message(ctdb, dest, srvid, data);
+ if (incr == 1) {
+ msg_plus++;
+ } else {
+ msg_minus++;
+ }
+}
+
+/*
+ benchmark sending messages in a ring around the nodes
+*/
+static void bench_ring(struct ctdb_context *ctdb, struct event_context *ev)
+{
+ int vnn=ctdb_get_vnn(ctdb);
+
+ if (vnn == 0) {
+ int i;
+ /* two messages are injected into the ring, moving
+ in opposite directions */
+ int dest, incr;
+ TDB_DATA data;
+
+ data.dptr = (uint8_t *)&incr;
+ data.dsize = sizeof(incr);
+
+ for (i=0;i<num_msgs;i++) {
+ incr = 1;
+ dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+ ctdb_send_message(ctdb, dest, 0, data);
+
+ incr = -1;
+ dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+ ctdb_send_message(ctdb, dest, 0, data);
+ }
+ }
+
+ start_timer();
+
+ while (end_timer() < timelimit) {
+ if (vnn == 0 && msg_count % 10000 == 0) {
+ printf("Ring: %.2f msgs/sec (+ve=%d -ve=%d)\r",
+ msg_count/end_timer(), msg_plus, msg_minus);
+ fflush(stdout);
+ }
+ event_loop_once(ev);
+ }
+
+ printf("Ring: %.2f msgs/sec (+ve=%d -ve=%d)\n",
+ msg_count/end_timer(), msg_plus, msg_minus);
+}
+
+
/*
main program
*/
int main(int argc, const char *argv[])
{
struct ctdb_context *ctdb;
+ struct ctdb_db_context *ctdb_db;
const char *nlist = NULL;
const char *transport = "tcp";
const char *myaddress = NULL;
@@ -134,6 +209,7 @@ int main(int argc, const char *argv[])
{ "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" },
{ "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
{ "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
+ { "num-msgs", 'n', POPT_ARG_INT, &num_msgs, 0, "num_msgs", "integer" },
POPT_TABLEEND
};
int opt;
@@ -199,17 +275,19 @@ int main(int argc, const char *argv[])
exit(1);
}
- /* setup a ctdb call function */
- ret = ctdb_set_call(ctdb, incr_func, FUNC_INCR);
- ret = ctdb_set_call(ctdb, fetch_func, FUNC_FETCH);
-
/* attach to a specific database */
- ret = ctdb_attach(ctdb, "test.tdb", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0666);
- if (ret == -1) {
+ ctdb_db = ctdb_attach(ctdb, "test.tdb", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0666);
+ if (!ctdb_db) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
+ /* setup a ctdb call function */
+ ret = ctdb_set_call(ctdb_db, incr_func, FUNC_INCR);
+ ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH);
+
+ ctdb_set_message_handler(ctdb, ring_message_handler, &msg_count);
+
/* start the protocol running */
ret = ctdb_start(ctdb);
@@ -217,11 +295,8 @@ int main(int argc, const char *argv[])
outside of test code) */
ctdb_connect_wait(ctdb);
- bench_incr(ctdb);
+ bench_ring(ctdb, ev);
- /* go into a wait loop to allow other nodes to complete */
- ctdb_wait_loop(ctdb);
-
/* shut it down */
talloc_free(ctdb);
return 0;