svn commit: samba r7295 - in branches/SAMBA_4_0/source: lib/messaging torture/local

tridge at samba.org tridge at samba.org
Sun Jun 5 07:30:45 GMT 2005


Author: tridge
Date: 2005-06-05 07:30:44 +0000 (Sun, 05 Jun 2005)
New Revision: 7295

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7295

Log:
added an irpc benchmark. It gets about 16k messages/sec on my laptop,
compared to about 20k messages/sec for the raw messaging layer. I
think that is quite acceptable given the extra functionality.

Modified:
   branches/SAMBA_4_0/source/lib/messaging/irpc.h
   branches/SAMBA_4_0/source/lib/messaging/messaging.c
   branches/SAMBA_4_0/source/torture/local/irpc.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/messaging/irpc.h
===================================================================
--- branches/SAMBA_4_0/source/lib/messaging/irpc.h	2005-06-05 06:53:07 UTC (rev 7294)
+++ branches/SAMBA_4_0/source/lib/messaging/irpc.h	2005-06-05 07:30:44 UTC (rev 7295)
@@ -28,7 +28,7 @@
 };
 
 /* don't allow calls to take too long */
-#define IRPC_CALL_TIMEOUT 10
+#define IRPC_CALL_TIMEOUT 20
 
 
 /* the server function type */
@@ -44,7 +44,10 @@
 #define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr) \
    irpc_call(msg_ctx, server_id, &dcerpc_table_ ## pipename, DCERPC_ ## funcname, ptr)
 
+#define IRPC_CALL_SEND(msg_ctx, server_id, pipename, funcname, ptr) \
+   irpc_call_send(msg_ctx, server_id, &dcerpc_table_ ## pipename, DCERPC_ ## funcname, ptr)
 
+
 /*
   a pending irpc call
 */

Modified: branches/SAMBA_4_0/source/lib/messaging/messaging.c
===================================================================
--- branches/SAMBA_4_0/source/lib/messaging/messaging.c	2005-06-05 06:53:07 UTC (rev 7294)
+++ branches/SAMBA_4_0/source/lib/messaging/messaging.c	2005-06-05 07:30:44 UTC (rev 7295)
@@ -315,7 +315,7 @@
 		if (msg->pending == NULL) {
 			EVENT_FD_WRITEABLE(msg->event.fde);
 		}
-		DLIST_ADD(msg->pending, rec);
+		DLIST_ADD_END(msg->pending, rec, struct messaging_rec *);
 		return NT_STATUS_OK;
 	}
 
@@ -426,20 +426,27 @@
 */
 NTSTATUS irpc_register(struct messaging_context *msg_ctx, 
 		       const struct dcerpc_interface_table *table, 
-		       int call, irpc_function_t fn)
+		       int callnum, irpc_function_t fn)
 {
 	struct irpc_list *irpc;
 
-	irpc = talloc(msg_ctx, struct irpc_list);
-	NT_STATUS_HAVE_NO_MEMORY(irpc);
+	/* override an existing handler, if any */
+	for (irpc=msg_ctx->irpc; irpc; irpc=irpc->next) {
+		if (irpc->table == table && irpc->callnum == callnum) {
+			break;
+		}
+	}
+	if (irpc == NULL) {
+		irpc = talloc(msg_ctx, struct irpc_list);
+		NT_STATUS_HAVE_NO_MEMORY(irpc);
+		DLIST_ADD(msg_ctx->irpc, irpc);
+	}
 
 	irpc->table   = table;
-	irpc->callnum = call;
+	irpc->callnum = callnum;
 	irpc->fn      = fn;
 	GUID_from_string(irpc->table->uuid, &irpc->uuid);
 
-	DLIST_ADD(msg_ctx->irpc, irpc);
-
 	return NT_STATUS_OK;
 }
 

Modified: branches/SAMBA_4_0/source/torture/local/irpc.c
===================================================================
--- branches/SAMBA_4_0/source/torture/local/irpc.c	2005-06-05 06:53:07 UTC (rev 7294)
+++ branches/SAMBA_4_0/source/torture/local/irpc.c	2005-06-05 07:30:44 UTC (rev 7295)
@@ -46,9 +46,6 @@
 	NTSTATUS status;
 	uint32_t res;
 
-	/* register the server side function */
-	IRPC_REGISTER(msg_ctx, rpcecho, ECHO_ADDONE, irpc_AddOne);
-
 	/* make the call */
 	r.in.in_data = random();
 	r.out.out_data = &res;
@@ -71,6 +68,75 @@
 	return True;	
 }
 
+
+static void irpc_callback(struct irpc_request *irpc)
+{
+	int *pong_count = (int *)irpc->async.private;
+	NTSTATUS status = irpc_call_recv(irpc);
+	if (!NT_STATUS_IS_OK(status)) {
+		printf("irpc call failed - %s\n", nt_errstr(status));
+	}
+	(*pong_count)++;
+}
+
+/*
+  test echo speed
+*/
+static BOOL test_speed(TALLOC_CTX *mem_ctx, 
+		       struct messaging_context *msg_ctx,
+		       struct event_context *ev)
+{
+	int ping_count = 0;
+	int pong_count = 0;
+	BOOL ret = True;
+	struct timeval tv;
+	struct echo_AddOne r;
+	uint32_t res;
+
+	tv = timeval_current();
+
+	r.in.in_data = 0;
+	r.out.out_data = &res;
+
+	printf("Sending echo for 10 seconds\n");
+	while (timeval_elapsed(&tv) < 10.0) {
+		struct irpc_request *irpc;
+
+		irpc = IRPC_CALL_SEND(msg_ctx, MSG_ID, rpcecho, ECHO_ADDONE, &r);
+		if (irpc == NULL) {
+			printf("AddOne send failed\n");
+			return False;
+		}
+
+		irpc->async.fn = irpc_callback;
+		irpc->async.private = &pong_count;
+
+		ping_count++;
+
+		while (ping_count > pong_count + 20) {
+			event_loop_once(ev);
+		}
+	}
+
+	printf("waiting for %d remaining replies (done %d)\n", 
+	       ping_count - pong_count, pong_count);
+	while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) {
+		event_loop_once(ev);
+	}
+
+	if (ping_count != pong_count) {
+		printf("ping test failed! received %d, sent %d\n", 
+		       pong_count, ping_count);
+		ret = False;
+	}
+
+	printf("echo rate of %.0f messages/sec\n", 
+	       (ping_count+pong_count)/timeval_elapsed(&tv));
+
+	return ret;
+}
+
+
 BOOL torture_local_irpc(void) 
 {
 	TALLOC_CTX *mem_ctx = talloc_init("torture_local_irpc");
@@ -83,7 +149,11 @@
 	ev = event_context_init(mem_ctx);
 	msg_ctx = messaging_init(mem_ctx, MSG_ID, ev);
 
+	/* register the server side function */
+	IRPC_REGISTER(msg_ctx, rpcecho, ECHO_ADDONE, irpc_AddOne);
+
 	ret &= test_addone(mem_ctx, msg_ctx);
+	ret &= test_speed(mem_ctx, msg_ctx, ev);
 
 	talloc_free(mem_ctx);
 



More information about the samba-cvs mailing list