mirror of
https://github.com/samba-team/samba.git
synced 2025-02-03 13:47:25 +03:00
changed ctdb_bench.c to use messages instead of calls
(This used to be ctdb commit d147a434f827f83cf90228a3ed37338db8e9df13)
This commit is contained in:
parent
e372d2d5fb
commit
f71f62fabd
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user