Rev 57: changed ctdb_bench.c to use messages instead of calls in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Fri Feb 9 01:45:58 GMT 2007


------------------------------------------------------------
revno: 57
revision-id: tridge at samba.org-20070209014558-ivbu2vfjhz0szafo
parent: tridge at samba.org-20070208225421-3q7n9qgukzhqjtnz
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Fri 2007-02-09 12:45:58 +1100
message:
  changed ctdb_bench.c to use messages instead of calls
modified:
  common/ctdb.c                  ctdb.c-20061127094323-t50f58d65iaao5of-2
  common/ctdb_message.c          ctdb_message.c-20070208224107-9dnio7x7z33prrmt-1
  ctdb_bench.c                   ctdb_bench.c-20061219052637-2liagoglohxb6p7s-1
  include/ctdb.h                 ctdb.h-20061117234101-o3qt14umlg9en8z0-11
=== modified file 'common/ctdb.c'
--- a/common/ctdb.c	2007-02-08 22:54:21 +0000
+++ b/common/ctdb.c	2007-02-09 01:45:58 +0000
@@ -162,6 +162,15 @@
 }
 
 /*
+  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)

=== modified file 'common/ctdb_message.c'
--- a/common/ctdb_message.c	2007-02-08 22:42:04 +0000
+++ b/common/ctdb_message.c	2007-02-09 01:45:58 +0000
@@ -39,6 +39,7 @@
 	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 @@
   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;

=== modified file 'ctdb_bench.c'
--- a/ctdb_bench.c	2007-01-25 05:13:17 +0000
+++ b/ctdb_bench.c	2007-02-09 01:45:58 +0000
@@ -122,6 +122,65 @@
 	       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 @@
 		exit(1);
 	}
 
+	ctdb_set_message_handler(ctdb, ring_message_handler, &msg_count);
+
 	/* start the protocol running */
 	ret = ctdb_start(ctdb);
 
@@ -224,11 +285,8 @@
 	   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;

=== modified file 'include/ctdb.h'
--- a/include/ctdb.h	2007-02-08 22:42:04 +0000
+++ b/include/ctdb.h	2007-02-09 01:45:58 +0000
@@ -127,6 +127,11 @@
 /* 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 @@
 
 /* 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



More information about the samba-cvs mailing list