changed ctdb_bench.c to use messages instead of calls
authorAndrew Tridgell <tridge@samba.org>
Fri, 9 Feb 2007 01:45:58 +0000 (12:45 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 9 Feb 2007 01:45:58 +0000 (12:45 +1100)
(This used to be ctdb commit d147a434f827f83cf90228a3ed37338db8e9df13)

ctdb/common/ctdb.c
ctdb/common/ctdb_message.c
ctdb/ctdb_bench.c
ctdb/include/ctdb.h

index 9e92059b950e373952746945d7081e1638d61318..59a14d4dbdc19ee25befe0377591d9cf342c419d 100644 (file)
@@ -161,6 +161,15 @@ uint32_t ctdb_get_vnn(struct ctdb_context *ctdb)
        return ctdb->vnn;
 }
 
+/*
+  return the number of nodes
+*/
+uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb)
+{
+       return ctdb->num_nodes;
+}
+
+
 /*
   start the protocol going
 */
index abdf9e6216768a57af419309a8cdf7c77d5e9e3f..6e79042b85559cb7aee85f2367071e7b039b751e 100644 (file)
@@ -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;
index 31abefc43fa5ab166b820f52d9a6373197774f01..bbfea00d97ecc1b744ef2ebf5e79ed945b348ee5 100644 (file)
@@ -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;
index 335af83215a0d58310e27a6ba19e95cb74c27b21..efb12c5daac46d16e27b7af40af6d6defc763794 100644 (file)
@@ -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