Bruce Simpson wrote:
Ben Greear wrote:
UNIX domain sockets can be used in XRL as it stands, by passing 'env
XORP_PF=x', without any patches.
If these are faster, why not use them by default?
How about this? 'scons check' runs to completion.
This is bork, because 'unix_socket' is never ignored as a compile-time
default; the environment needs to be checked in all cases.
xrl_std_router.cc needs this diff chunk instead. Hitting getenv() twice
in one shot isn't too bad, can clean up later, after feedback.
XrlStdRouter is not something which gets constructed a lot; typically
once per process. libfeaclient, however, will build its own,
independently of anything else the process is doing.
Using the attached script revealed this relatively quickly. BTW: I've
seen the performance difference fall to around 15%. I was getting up to
30% faster than TCP in some situations.
Index: xrl_std_router.cc
===================================================================
--- xrl_std_router.cc (revision 11632)
+++ xrl_std_router.cc (working copy)
@@ -23,42 +23,55 @@
#include "xrl_module.h"
#include "xrl_std_router.hh"
-//#include "xrl_pf_inproc.hh"
+//#include "xrl_pf_inproc.hh" // Inproc is deprecated.
#include "xrl_pf_stcp.hh"
-//#include "xrl_pf_sudp.hh"
+//#include "xrl_pf_sudp.hh" // UDP is deprecated.
#include "xrl_pf_unix.hh"
#include "libxorp/xlog.h"
+
// ----------------------------------------------------------------------------
// Helper methods
+#if !defined(XRL_PF)
+#error "A default transport for XRL must be defined using the preprocessor."
+#endif
+
+static const char default_pf[] = { XRL_PF, '\0' };
+
XrlPFListener*
XrlStdRouter::create_listener()
{
const char* pf = getenv("XORP_PF");
+ if (pf == NULL)
+ pf = default_pf;
- if (pf != NULL) {
- switch (pf[0]) {
-#if 0
+ switch (pf[0]) {
+#if 0 // Inproc is deprecated.
case 'i':
return new XrlPFInProcListener(_e, this);
-
+#endif
+ // For the benefit of bench_ipc.sh.
+ case 't':
+ return new XrlPFSTCPListener(_e, this);
+ break;
+#if 0 // UDP is deprecated.
case 'u':
return new XrlPFSUDPListener(_e, this);
#endif
-
case 'x':
+#if XRL_PF != 'x'
XLOG_ASSERT(_unix == NULL);
+#endif
return new XrlPFUNIXListener(_e, this);
-
default:
XLOG_ERROR("Unknown PF %s\n", pf);
XLOG_ASSERT(false);
break;
- }
}
- return new XrlPFSTCPListener(_e, this);
+ XLOG_UNREACHABLE();
+ return 0;
}
static void
@@ -125,6 +138,14 @@
{
_unix = _l = NULL;
+ // We need to check the environment otherwise
+ // we get the compiled-in default.
+ const char* pf = getenv("XORP_PF");
+ if (pf == NULL)
+ pf = default_pf;
+ if (pf[0] != 'x')
+ unix_socket = false;
+
if (unix_socket)
create_unix_listener();
#!/bin/sh
set -x
# XXX Assumes you've built a 'scons check' run and the objects
# are at this location.
BUILDDIR=/home/bms/svn/xorp/xorp/obj/x86_64-unknown-freebsd7.2
# XXX Assumes finder is installed at this location.
INSTDIR=/tmp/xorp
# Run the finder in the background.
$INSTDIR/libxipc/xorp_finder & finder_pid=$!
trap "kill $finder_pid" 1 2 15 EXIT
# Some bright spark told the test receiver to use stdout by
# default, which is buffered, and loses its output on a kill -TERM.
# Fix this lameness.
# Also, the bench_ipc.sh script seems to assume the sender logs
# the meaningful statistics.
mybasename=$(basename $0)
# first, PF_INET SOCK_STREAM aka tcp
TMPFILE=$(mktemp /tmp/${mybasename}.XXXXXXX)
/usr/bin/env XORP_PF=t $BUILDDIR/libxipc/tests/test_xrl_receiver 2>&1 >
$TMPFILE & rx_pid=$!
trap "kill $rx_pid $finder_pid" 1 2 15 EXIT
/usr/bin/env XORP_PF=t $BUILDDIR/libxipc/tests/test_xrl_sender
kill $rx_pid
# dilute it
TMPFILE_A=$(mktemp /tmp/${mybasename}.XXXXXXX)
awk '{ printf("%s\n", $(NF-1)) }' <$TMPFILE >$TMPFILE_A
# clean up first run
rm -f $TMPFILE
# now, PF_LOCAL SOCK_STREAM aka local
TMPFILE=$(mktemp /tmp/${mybasename}.XXXXXXX)
/usr/bin/env XORP_PF=x $BUILDDIR/libxipc/tests/test_xrl_receiver 2>&1 >
$TMPFILE & rx_pid=$!
trap "kill $rx_pid $finder_pid" 1 2 15 EXIT
/usr/bin/env XORP_PF=x $BUILDDIR/libxipc/tests/test_xrl_sender
kill $rx_pid
trap "kill $finder_pid" 1 2 15 EXIT
# dilute it
TMPFILE_B=$(mktemp /tmp/${mybasename}.XXXXXXX)
awk '{ printf("%s\n", $(NF-1)) }' <$TMPFILE >$TMPFILE_B
# clean up second run
rm -f $TMPFILE
# bring finder down
kill $finder_pid
trap 1 2 15 EXIT
# compare it
/usr/bin/ministat $TMPFILE_A $TMPFILE_B
# clean up
#rm -f $TMPFILE_A $TMPFILE_B
_______________________________________________
Xorp-hackers mailing list
[email protected]
http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/xorp-hackers