diff options
-rw-r--r-- | java/Context.cpp | 15 | ||||
-rw-r--r-- | java/Makefile.am | 22 | ||||
-rw-r--r-- | java/Socket.cpp | 140 | ||||
-rw-r--r-- | java/org/zmq/Context.java | 3 | ||||
-rw-r--r-- | java/org/zmq/Message.java | 66 | ||||
-rw-r--r-- | java/org/zmq/Socket.java | 42 | ||||
-rw-r--r-- | perf/cpp/local_thr.cpp | 2 | ||||
-rw-r--r-- | perf/cpp/remote_lat.cpp | 6 | ||||
-rw-r--r-- | perf/java/local_lat.java | 55 | ||||
-rw-r--r-- | perf/java/local_thr.java | 65 | ||||
-rw-r--r-- | perf/java/remote_lat.java | 60 | ||||
-rw-r--r-- | perf/java/remote_thr.java | 53 |
12 files changed, 343 insertions, 186 deletions
diff --git a/java/Context.cpp b/java/Context.cpp index d8fcf99..3fc66bd 100644 --- a/java/Context.cpp +++ b/java/Context.cpp @@ -27,8 +27,7 @@ static jfieldID ctx_handle_fid = NULL; -static void -raise_exception (JNIEnv *env, int err) +static void raise_exception (JNIEnv *env, int err) { // Get exception class. jclass exception_class = env->FindClass ("java/lang/Exception"); @@ -45,9 +44,8 @@ raise_exception (JNIEnv *env, int err) env->DeleteLocalRef (exception_class); } -JNIEXPORT void JNICALL -Java_org_zmq_Context_construct (JNIEnv *env, jobject obj, - jint app_threads, jint io_threads) +JNIEXPORT void JNICALL Java_org_zmq_Context_construct (JNIEnv *env, jobject obj, + jint app_threads, jint io_threads) { if (ctx_handle_fid == NULL) { jclass cls = env->GetObjectClass (obj); @@ -66,8 +64,7 @@ Java_org_zmq_Context_construct (JNIEnv *env, jobject obj, env->SetLongField (obj, ctx_handle_fid, (jlong) ctx); } -JNIEXPORT void JNICALL -Java_org_zmq_Context_finalize (JNIEnv *env, jobject obj) +JNIEXPORT void JNICALL Java_org_zmq_Context_finalize (JNIEnv *env, jobject obj) { void *ctx = (void*) env->GetLongField (obj, ctx_handle_fid); assert (ctx); @@ -76,8 +73,8 @@ Java_org_zmq_Context_finalize (JNIEnv *env, jobject obj) assert (rc == 0); } -JNIEXPORT jlong JNICALL -Java_org_zmq_Context_createSocket (JNIEnv *env, jobject obj, jint type) +JNIEXPORT jlong JNICALL Java_org_zmq_Context_createSocket (JNIEnv *env, + jobject obj, jint type) { void *ctx = (void*) env->GetLongField (obj, ctx_handle_fid); assert (ctx); diff --git a/java/Makefile.am b/java/Makefile.am index 363f941..403da20 100644 --- a/java/Makefile.am +++ b/java/Makefile.am @@ -12,20 +12,17 @@ jar_DATA = $(jarfile) dist_noinst_JAVA = \ org/zmq/Context.java \ - org/zmq/Socket.java \ - org/zmq/Message.java + org/zmq/Socket.java lib_LTLIBRARIES = libjzmq.la libjzmq_la_SOURCES = \ Context.cpp \ org_zmq_Context.h \ Socket.cpp \ - org_zmq_Socket.h \ - Message.cpp \ - org_zmq_Message.h + org_zmq_Socket.h libjzmq_la_CXXFLAGS = -I$(top_builddir)/src/libzmq \ -@JAVA_INCLUDE@ -I$(top_builddir)/include -I$(top_srcdir)/libjzmq -Wall -I /usr/lib/jvm/java-6-openjdk/include +@JAVA_INCLUDE@ -I$(top_builddir)/include -I$(top_srcdir)/libjzmq -Wall libjzmq_la_LDFLAGS = -version-info 0:0:0 libjzmq_la_LIBADD = $(top_builddir)/src/libzmq.la @@ -33,17 +30,13 @@ BUILT_SOURCES = \ org/zmq/Context.class \ org_zmq_Context.h \ org/zmq/Socket.class \ - org_zmq_Socket.h \ - org/zmq/Message.class \ - org_zmq_Message.h + org_zmq_Socket.h CLEANFILES = \ org/zmq/Context.class \ org_zmq_Context.h \ org/zmq/Socket.class \ org_zmq_Socket.h \ - org/zmq/Message.class \ - org_zmq_Message.h \ Zmq.jar $(srcdir)/Context.cpp: org_zmq_Context.h @@ -60,13 +53,6 @@ org_zmq_Socket.h: org/zmq/Socket.class ./org/zmq/Socket.class: classdist_noinst.stamp -$(srcdir)/Message.cpp: org_zmq_Message.h - -org_zmq_Message.h: org/zmq/Message.class - $(CLASSPATH_ENV) $(JAVAH) -jni -classpath . org.zmq.Message - -./org/zmq/Message.class: classdist_noinst.stamp - dist-hook: -rm $(distdir)/*.h diff --git a/java/Socket.cpp b/java/Socket.cpp index eb3c1e3..f87c298 100644 --- a/java/Socket.cpp +++ b/java/Socket.cpp @@ -26,13 +26,9 @@ #include "org_zmq_Socket.h" static jfieldID socket_handle_fid = NULL; -static jclass msg_class = NULL; -static jmethodID msg_constructor; -static jmethodID get_msg_handle_mid = NULL; static jmethodID create_socket_mid = NULL; -static void -raise_exception (JNIEnv *env, int err) +static void raise_exception (JNIEnv *env, int err) { // Get exception class. jclass exception_class = env->FindClass ("java/lang/Exception"); @@ -49,9 +45,8 @@ raise_exception (JNIEnv *env, int err) env->DeleteLocalRef (exception_class); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_construct (JNIEnv *env, jobject obj, jobject context, - jint type) +JNIEXPORT void JNICALL Java_org_zmq_Socket_construct (JNIEnv *env, jobject obj, + jobject context, jint type) { if (socket_handle_fid == NULL) { jclass cls = env->GetObjectClass (obj); @@ -69,30 +64,14 @@ Java_org_zmq_Socket_construct (JNIEnv *env, jobject obj, jobject context, env->DeleteLocalRef (cls); } - if (msg_class == NULL) { - jclass cls = env->FindClass ("org/zmq/Message"); - assert (cls); - - msg_constructor = env->GetMethodID (cls, "<init>", "()V"); - assert (msg_constructor); - - get_msg_handle_mid = env->GetMethodID (cls, "getMsgHandle", "()J"); - assert (get_msg_handle_mid); - - msg_class = (jclass) env->NewGlobalRef (cls); - assert (msg_class); - env->DeleteLocalRef (cls); - } - - void *s = (void *) env->CallLongMethod (context, create_socket_mid, type); + void *s = (void*) env->CallLongMethod (context, create_socket_mid, type); if (env->ExceptionCheck ()) return; env->SetLongField (obj, socket_handle_fid, (jlong) s); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_finalize (JNIEnv *env, jobject obj) +JNIEXPORT void JNICALL Java_org_zmq_Socket_finalize (JNIEnv *env, jobject obj) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -100,8 +79,8 @@ Java_org_zmq_Socket_finalize (JNIEnv *env, jobject obj) assert (rc == 0); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_setHwm (JNIEnv *env, jobject obj, jlong hwm) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setHwm (JNIEnv *env, jobject obj, + jlong hwm) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -110,8 +89,8 @@ Java_org_zmq_Socket_setHwm (JNIEnv *env, jobject obj, jlong hwm) raise_exception (env, errno); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_setLwm (JNIEnv *env, jobject obj, jlong lwm) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setLwm (JNIEnv *env, jobject obj, + jlong lwm) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -121,8 +100,8 @@ Java_org_zmq_Socket_setLwm (JNIEnv *env, jobject obj, jlong lwm) raise_exception (env, errno); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_setSwap (JNIEnv *env, jobject obj, jlong swap_size) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setSwap (JNIEnv *env, jobject obj, + jlong swap_size) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -132,8 +111,8 @@ Java_org_zmq_Socket_setSwap (JNIEnv *env, jobject obj, jlong swap_size) raise_exception (env, errno); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_setMask (JNIEnv *env, jobject obj, jlong mask) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setMask (JNIEnv *env, jobject obj, + jlong mask) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -143,8 +122,8 @@ Java_org_zmq_Socket_setMask (JNIEnv *env, jobject obj, jlong mask) raise_exception (env, errno); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_setAffinity (JNIEnv *env, jobject obj, jlong affinity) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setAffinity (JNIEnv *env, + jobject obj, jlong affinity) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -154,8 +133,8 @@ Java_org_zmq_Socket_setAffinity (JNIEnv *env, jobject obj, jlong affinity) raise_exception (env, errno); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_setIdentity (JNIEnv *env, jobject obj, jstring identity) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setIdentity (JNIEnv *env, + jobject obj, jstring identity) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -176,8 +155,8 @@ Java_org_zmq_Socket_setIdentity (JNIEnv *env, jobject obj, jstring identity) raise_exception (env, errno); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_bind (JNIEnv *env, jobject obj, jstring addr) +JNIEXPORT void JNICALL Java_org_zmq_Socket_bind (JNIEnv *env, jobject obj, + jstring addr) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -188,8 +167,10 @@ Java_org_zmq_Socket_bind (JNIEnv *env, jobject obj, jstring addr) } const char *c_addr = env->GetStringUTFChars (addr, NULL); - if (c_addr == NULL) + if (c_addr == NULL) { + raise_exception (env, EINVAL); return; + } int rc = zmq_bind (s, c_addr); env->ReleaseStringUTFChars (addr, c_addr); @@ -198,8 +179,8 @@ Java_org_zmq_Socket_bind (JNIEnv *env, jobject obj, jstring addr) raise_exception (env, errno); } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_connect (JNIEnv *env, jobject obj, jstring addr) +JNIEXPORT void JNICALL Java_org_zmq_Socket_connect (JNIEnv *env, jobject obj, + jstring addr) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); @@ -210,8 +191,10 @@ Java_org_zmq_Socket_connect (JNIEnv *env, jobject obj, jstring addr) } const char *c_addr = env->GetStringUTFChars (addr, NULL); - if (c_addr == NULL) + if (c_addr == NULL) { + raise_exception (env, EINVAL); return; + } int rc = zmq_connect (s, c_addr); env->ReleaseStringUTFChars (addr, c_addr); @@ -220,57 +203,80 @@ Java_org_zmq_Socket_connect (JNIEnv *env, jobject obj, jstring addr) raise_exception (env, errno); } -JNIEXPORT jint JNICALL -Java_org_zmq_Socket_send (JNIEnv *env, jobject obj, jobject msg, jlong flags) +JNIEXPORT jboolean JNICALL Java_org_zmq_Socket_send (JNIEnv *env, jobject obj, + jbyteArray msg, jlong flags) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); - zmq_msg_t *zmq_msg = (zmq_msg_t *) - env->CallLongMethod (msg, get_msg_handle_mid); + jsize size = env->GetArrayLength (msg); + jbyte *data = env->GetByteArrayElements (msg, 0); - if (env->ExceptionCheck ()) - return -1; + zmq_msg_t message; + int rc = zmq_msg_init_size (&message, size); + assert (rc == 0); + memcpy (zmq_msg_data (&message), data, size); - int rc = zmq_send (s, zmq_msg, (int) flags); + env->ReleaseByteArrayElements (msg, data, 0); + + rc = zmq_send (s, &message, (int) flags); + + if (rc == -1 && errno == EAGAIN) { + rc = zmq_msg_close (&message); + assert (rc == 0); + return JNI_FALSE; + } + if (rc == -1) { raise_exception (env, errno); - return -1; + rc = zmq_msg_close (&message); + assert (rc == 0); + return JNI_FALSE; } - return rc; + rc = zmq_msg_close (&message); + assert (rc == 0); + return JNI_TRUE; } -JNIEXPORT void JNICALL -Java_org_zmq_Socket_flush (JNIEnv *env, jobject obj) +JNIEXPORT void JNICALL Java_org_zmq_Socket_flush (JNIEnv *env, jobject obj) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); - zmq_flush (s); + int rc = zmq_flush (s); + + if (rc == -1) { + raise_exception (env, errno); + return ; + } } -JNIEXPORT jobject JNICALL -Java_org_zmq_Socket_recv (JNIEnv *env, jobject obj, jlong flags) +JNIEXPORT jbyteArray JNICALL Java_org_zmq_Socket_recv (JNIEnv *env, jobject obj, + jlong flags) { void *s = (void*) env->GetLongField (obj, socket_handle_fid); assert (s); - jobject msg = env->NewObject (msg_class, msg_constructor); - if (msg == NULL) - return NULL; - - zmq_msg_t *zmq_msg = (zmq_msg_t*) - env->CallLongMethod (msg, get_msg_handle_mid); + zmq_msg_t message; + zmq_msg_init (&message); + int rc = zmq_recv (s, &message, (int) flags); - if (env->ExceptionCheck ()) + if (rc == -1 && errno == EAGAIN) { + zmq_msg_close (&message); return NULL; + } - int rc = zmq_recv (s, zmq_msg, (int) flags); if (rc == -1) { raise_exception (env, errno); + zmq_msg_close (&message); return NULL; } - return msg; + jbyteArray data = env->NewByteArray (zmq_msg_size (&message)); + assert (data); + env->SetByteArrayRegion (data, 0, zmq_msg_size (&message), + (jbyte*) zmq_msg_data (&message)); + + return data; } diff --git a/java/org/zmq/Context.java b/java/org/zmq/Context.java index 8bc4d57..c63ef60 100644 --- a/java/org/zmq/Context.java +++ b/java/org/zmq/Context.java @@ -34,6 +34,9 @@ public class Context { construct (appThreads, ioThreads); } + /** + * Internal function. Do not use directly! + */ public native long createSocket (int type); /** Initialize the JNI interface */ diff --git a/java/org/zmq/Message.java b/java/org/zmq/Message.java deleted file mode 100644 index 3691410..0000000 --- a/java/org/zmq/Message.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright (c) 2007-2009 FastMQ Inc. - - This file is part of 0MQ. - - 0MQ is free software; you can redistribute it and/or modify it under - the terms of the Lesser GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - 0MQ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - Lesser GNU General Public License for more details. - - You should have received a copy of the Lesser GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -package org.zmq; - -public class Message { - static { - System.loadLibrary("jzmq"); - } - - /** - * Class constructor. - */ - public Message () { - construct (); - } - - public Message (byte [] payload) { - constructWithData (payload); - } - - /** - * Get message payload. - */ - public native byte [] getMsgPayload (); - - /** - * Get message type. - */ - public native int getMsgType (); - - /** - * Get low-level message handler. - */ - public long getMsgHandle () { - return msgHandle; - } - - /** Initialize the JNI interface */ - protected native void construct (); - - protected native void constructWithData (byte [] payload); - - /** Free resources used by JNI driver. */ - protected native void finalize (); - - /** Opaque data used by JNI driver. */ - private long msgHandle; -} - diff --git a/java/org/zmq/Socket.java b/java/org/zmq/Socket.java index 3bfbfec..832467f 100644 --- a/java/org/zmq/Socket.java +++ b/java/org/zmq/Socket.java @@ -19,26 +19,26 @@ package org.zmq; -public class Socket { +public class Socket +{ + static { System.loadLibrary("jzmq"); } - public static final int ZMQ_MAX_VSM_SIZE = 30; - - public static final int ZMQ_GAP = 1; + public static final int NOBLOCK = 1; - public static final int ZMQ_DELIMITER = 31; + public static final int NOFLUSH = 2; - public static final int ZMQ_NOBLOCK = 1; + public static final int P2P = 0; - public static final int ZMQ_NOFLUSH = 2; + public static final int PUB = 1; - public static final int ZMQ_P2P = 0; + public static final int SUB = 2; - public static final int ZMQ_PUB = 1; + public static final int REQ = 3; - public static final int ZMQ_SUB = 2; + public static final int REP = 4; /** * Class constructor. @@ -47,7 +47,6 @@ public class Socket { * @param type */ public Socket (Context context, int type) { - ctx = context; construct (context, type); } @@ -94,37 +93,39 @@ public class Socket { public native void setIdentity (String identity); /** + * Bind to network interface. Start listening for new connections. + * * @param addr */ public native void bind (String addr); /** - * Connect. + * Connect to remote application. * * @param addr */ public native void connect (String addr); /** - * Send. + * Send the message. * - * @param message - * @param block + * @param msg + * @param flags */ - public native int send (Message msg, long flags); + public native boolean send (byte [] msg, long flags); /** - * Flush all messages sent with flush flag false down the stream. + * Flush the messages down the stream. */ public native void flush (); /** * Receive message. * - * @param block + * @param flags * @return */ - public native Message recv (long flags); + public native byte [] recv (long flags); /** Initialize JNI driver */ protected native void construct (Context context, int type); @@ -132,9 +133,6 @@ public class Socket { /** Free all resources used by JNI driver. */ protected native void finalize (); - /** Keep reference to ZMQ context so it is not garbage collected */ - private Context ctx; - /** Opaque data used by JNI driver. */ private long socketHandle; diff --git a/perf/cpp/local_thr.cpp b/perf/cpp/local_thr.cpp index ca81ba9..31fcd16 100644 --- a/perf/cpp/local_thr.cpp +++ b/perf/cpp/local_thr.cpp @@ -49,7 +49,7 @@ int main (int argc, char *argv []) int rc = gettimeofday (&start, NULL); assert (rc == 0); - for (int i = 0; i != message_count - 1; i++) { + for (int i = 1; i != message_count; i++) { s.recv (&msg); assert (msg.size () == message_size); } diff --git a/perf/cpp/remote_lat.cpp b/perf/cpp/remote_lat.cpp index c3ded10..a88d53d 100644 --- a/perf/cpp/remote_lat.cpp +++ b/perf/cpp/remote_lat.cpp @@ -58,13 +58,13 @@ int main (int argc, char *argv []) end.tv_sec -= start.tv_sec; start.tv_sec = 0; - double usec_elapsed = (end.tv_sec * 1000000 + end.tv_usec) - + double elapsed = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec); - double latency = usec_elapsed / (roundtrip_count * 2); + double latency = elapsed / (roundtrip_count * 2); printf ("message size: %d [B]\n", (int) message_size); printf ("roundtrip count: %d\n", (int) roundtrip_count); - printf ("average latency: %.3f [us]\n", (double) latency); + printf ("mean latency: %.3f [us]\n", (double) latency); return 0; } diff --git a/perf/java/local_lat.java b/perf/java/local_lat.java new file mode 100644 index 0000000..e7583cc --- /dev/null +++ b/perf/java/local_lat.java @@ -0,0 +1,55 @@ +/* + Copyright (c) 2007-2009 FastMQ Inc. + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the Lesser GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + Lesser GNU General Public License for more details. + + You should have received a copy of the Lesser GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +import org.zmq.*; + +class local_lat +{ + public static void main (String [] args) + { + if (args.length != 3) { + System.out.println ("usage: local_lat <bind-to> " + + "<message-size> <roundtrip-count>"); + return; + } + + String bindTo = args [0]; + int messageSize = Integer.parseInt (args [1]); + int roundtripCount = Integer.parseInt (args [2]); + + org.zmq.Context ctx = new org.zmq.Context (1, 1); + + org.zmq.Socket s = new org.zmq.Socket (ctx, org.zmq.Socket.REP); + s.bind (bindTo); + + for (int i = 0; i != roundtripCount; i++) { + byte [] data = s.recv (0); + assert (data.length == messageSize); + s.send (data, 0); + } + + try { + Thread.sleep (1000); + } + catch (InterruptedException e) { + e.printStackTrace (); + } + + } +} diff --git a/perf/java/local_thr.java b/perf/java/local_thr.java new file mode 100644 index 0000000..4a03f1d --- /dev/null +++ b/perf/java/local_thr.java @@ -0,0 +1,65 @@ +/* + Copyright (c) 2007-2009 FastMQ Inc. + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the Lesser GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + Lesser GNU General Public License for more details. + + You should have received a copy of the Lesser GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +import org.zmq.*; + +class local_thr +{ + public static void main (String [] args) + { + if (args.length != 3) { + System.out.println ("usage: local_thr <bind-to> " + + "<message size> <message count>"); + return; + } + + String bindTo = args [0]; + long messageSize = Integer.parseInt (args [1]); + long messageCount = Integer.parseInt (args [2]); + + org.zmq.Context ctx = new org.zmq.Context (1, 1); + + org.zmq.Socket s = new org.zmq.Socket (ctx, org.zmq.Socket.SUB); + s.bind (bindTo); + + byte [] data = s.recv (0); + assert (data.length == messageSize); + + long start = System.currentTimeMillis (); + + for (int i = 1; i != messageCount; i ++) { + data = s.recv (0); + assert (data.length == messageSize); + } + + long end = System.currentTimeMillis (); + + long elapsed = (end - start) * 1000; + if (elapsed == 0) + elapsed = 1; + + long throughput = messageCount * 1000000 / elapsed; + double megabits = (double) (throughput * messageSize * 8) / 1000000; + + System.out.println ("message size: " + messageSize + " [B]"); + System.out.println ("message count: " + messageCount); + System.out.println ("mean throughput: " + throughput + "[msg/s]"); + System.out.println ("mean throughput: " + megabits + "[Mb/s]"); + } +} diff --git a/perf/java/remote_lat.java b/perf/java/remote_lat.java new file mode 100644 index 0000000..28b2f76 --- /dev/null +++ b/perf/java/remote_lat.java @@ -0,0 +1,60 @@ +/* + Copyright (c) 2007-2009 FastMQ Inc. + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the Lesser GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + Lesser GNU General Public License for more details. + + You should have received a copy of the Lesser GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +import org.zmq.*; + +class remote_lat +{ + public static void main (String [] args) + { + if (args.length != 3) { + System.out.println ("usage: remote_lat <connect-to> " + + "<message size> <roundtrip count>"); + return; + } + + String connectTo = args [0]; + int messageSize = Integer.parseInt (args [1]); + int roundtripCount = Integer.parseInt (args [2]); + + org.zmq.Context ctx = new org.zmq.Context (1, 1); + + org.zmq.Socket s = new org.zmq.Socket (ctx, org.zmq.Socket.REQ); + s.connect (connectTo); + + long start = System.currentTimeMillis (); + + byte data [] = new byte [messageSize]; + for (int i = 0; i != roundtripCount; i ++) { + s.send (data, 0); + data = s.recv (0); + assert (data.length == messageSize); + } + + long end = System.currentTimeMillis (); + + long elapsed = (end - start) * 1000; + double latency = (double) elapsed / roundtripCount / 2; + + System.out.println ("message size: " + messageSize + " [B]"); + System.out.println ("roundtrip count: " + roundtripCount); + System.out.println ("mean latency: " + latency + " [us]"); + } +} + diff --git a/perf/java/remote_thr.java b/perf/java/remote_thr.java new file mode 100644 index 0000000..25406ea --- /dev/null +++ b/perf/java/remote_thr.java @@ -0,0 +1,53 @@ +/* + Copyright (c) 2007-2009 FastMQ Inc. + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the Lesser GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + Lesser GNU General Public License for more details. + + You should have received a copy of the Lesser GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +import org.zmq.*; + +class remote_thr +{ + public static void main (String [] args) + { + if (args.length != 3) { + System.out.println ("usage: remote_thr <connect-to> " + + "<message-size> <message-count>"); + return; + } + + // Parse the command line arguments. + String connectTo = args [0]; + int messageSize = Integer.parseInt (args [1]); + int messageCount = Integer.parseInt (args [2]); + + org.zmq.Context ctx = new org.zmq.Context (1, 1); + + org.zmq.Socket s = new org.zmq.Socket (ctx, org.zmq.Socket.PUB); + s.connect (connectTo); + + byte msg [] = new byte [messageSize]; + for (int i = 0; i != messageCount; i++) + s.send (msg, 0); + + try { + Thread.sleep (10000); + } + catch (InterruptedException e) { + e.printStackTrace (); + } + } +} |