summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-02-09 12:45:58 +1100
committerAndrew Tridgell <tridge@samba.org>2007-02-09 12:45:58 +1100
commitf71f62fabdcfaf8c36afa9ed361eed57afefe45f (patch)
treea00a08ba7488592e8b931852a469def2c7b5b391
parente372d2d5fb563adc82bb610c0d2cb3b00653a779 (diff)
downloadsamba-f71f62fabdcfaf8c36afa9ed361eed57afefe45f.tar.gz
samba-f71f62fabdcfaf8c36afa9ed361eed57afefe45f.tar.xz
samba-f71f62fabdcfaf8c36afa9ed361eed57afefe45f.zip
changed ctdb_bench.c to use messages instead of calls
(This used to be ctdb commit d147a434f827f83cf90228a3ed37338db8e9df13)
-rw-r--r--ctdb/common/ctdb.c9
-rw-r--r--ctdb/common/ctdb_message.c3
-rw-r--r--ctdb/ctdb_bench.c66
-rw-r--r--ctdb/include/ctdb.h7
4 files changed, 79 insertions, 6 deletions
diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c
index 9e92059b950..59a14d4dbdc 100644
--- a/ctdb/common/ctdb.c
+++ b/ctdb/common/ctdb.c
@@ -162,6 +162,15 @@ uint32_t ctdb_get_vnn(struct ctdb_context *ctdb)
}
/*
+ return the number of nodes
+*/
+uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb)
+{
+ return ctdb->num_nodes;
+}
+
+
+/*
start the protocol going
*/
int ctdb_start(struct ctdb_context *ctdb)
diff --git a/ctdb/common/ctdb_message.c b/ctdb/common/ctdb_message.c
index abdf9e62167..6e79042b855 100644
--- a/ctdb/common/ctdb_message.c
+++ b/ctdb/common/ctdb_message.c
@@ -39,6 +39,7 @@ void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
struct ctdb_req_message *c = (struct ctdb_req_message *)hdr;
TDB_DATA data;
if (ctdb->message_handler == NULL) {
+ printf("no msg handler\n");
/* no registered message handler */
talloc_free(hdr);
return;
@@ -54,7 +55,7 @@ void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
send a ctdb message
*/
int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
- uint32_t srvid, uint32_t msg_type, TDB_DATA data)
+ uint32_t srvid, TDB_DATA data)
{
struct ctdb_req_message *r;
int len;
diff --git a/ctdb/ctdb_bench.c b/ctdb/ctdb_bench.c
index 31abefc43fa..bbfea00d97e 100644
--- a/ctdb/ctdb_bench.c
+++ b/ctdb/ctdb_bench.c
@@ -122,6 +122,65 @@ static void bench_incr(struct ctdb_context *ctdb)
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)
+{
+ TDB_DATA data;
+ int incr, vnn=ctdb_get_vnn(ctdb);
+
+ data.dptr = (uint8_t *)&incr;
+ data.dsize = sizeof(incr);
+
+ if (vnn == 0) {
+ /* two messages are injected into the ring, moving
+ in opposite directions */
+ int dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+ incr = 1;
+ ctdb_send_message(ctdb, dest, 0, data);
+ incr = -1;
+ ctdb_send_message(ctdb, dest, 0, data);
+ }
+
+ start_timer();
+
+ while (end_timer() < timelimit) {
+ if (vnn == 0 && msg_count % 1000 == 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
*/
@@ -217,6 +276,8 @@ int main(int argc, const char *argv[])
exit(1);
}
+ ctdb_set_message_handler(ctdb, ring_message_handler, &msg_count);
+
/* start the protocol running */
ret = ctdb_start(ctdb);
@@ -224,11 +285,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;
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h
index 335af83215a..efb12c5daac 100644
--- a/ctdb/include/ctdb.h
+++ b/ctdb/include/ctdb.h
@@ -127,6 +127,11 @@ void ctdb_wait_loop(struct ctdb_context *ctdb);
/* return vnn of this node */
uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
+/*
+ return the number of nodes
+*/
+uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
+
/* setup a handler for ctdb messages */
typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid,
TDB_DATA data, void *);
@@ -135,6 +140,6 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handle
/* send a ctdb message */
int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
- uint32_t srvid, uint32_t msg_type, TDB_DATA data);
+ uint32_t srvid, TDB_DATA data);
#endif