mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-19 18:03:50 +00:00
Java perf tests added
This commit is contained in:
parent
63b56d7fb3
commit
67253f3186
@ -27,8 +27,7 @@
|
|||||||
|
|
||||||
static jfieldID ctx_handle_fid = NULL;
|
static jfieldID ctx_handle_fid = NULL;
|
||||||
|
|
||||||
static void
|
static void raise_exception (JNIEnv *env, int err)
|
||||||
raise_exception (JNIEnv *env, int err)
|
|
||||||
{
|
{
|
||||||
// Get exception class.
|
// Get exception class.
|
||||||
jclass exception_class = env->FindClass ("java/lang/Exception");
|
jclass exception_class = env->FindClass ("java/lang/Exception");
|
||||||
@ -45,8 +44,7 @@ raise_exception (JNIEnv *env, int err)
|
|||||||
env->DeleteLocalRef (exception_class);
|
env->DeleteLocalRef (exception_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Context_construct (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Context_construct (JNIEnv *env, jobject obj,
|
|
||||||
jint app_threads, jint io_threads)
|
jint app_threads, jint io_threads)
|
||||||
{
|
{
|
||||||
if (ctx_handle_fid == NULL) {
|
if (ctx_handle_fid == NULL) {
|
||||||
@ -66,8 +64,7 @@ Java_org_zmq_Context_construct (JNIEnv *env, jobject obj,
|
|||||||
env->SetLongField (obj, ctx_handle_fid, (jlong) ctx);
|
env->SetLongField (obj, ctx_handle_fid, (jlong) ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Context_finalize (JNIEnv *env, jobject obj)
|
||||||
Java_org_zmq_Context_finalize (JNIEnv *env, jobject obj)
|
|
||||||
{
|
{
|
||||||
void *ctx = (void*) env->GetLongField (obj, ctx_handle_fid);
|
void *ctx = (void*) env->GetLongField (obj, ctx_handle_fid);
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
@ -76,8 +73,8 @@ Java_org_zmq_Context_finalize (JNIEnv *env, jobject obj)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL
|
JNIEXPORT jlong JNICALL Java_org_zmq_Context_createSocket (JNIEnv *env,
|
||||||
Java_org_zmq_Context_createSocket (JNIEnv *env, jobject obj, jint type)
|
jobject obj, jint type)
|
||||||
{
|
{
|
||||||
void *ctx = (void*) env->GetLongField (obj, ctx_handle_fid);
|
void *ctx = (void*) env->GetLongField (obj, ctx_handle_fid);
|
||||||
assert (ctx);
|
assert (ctx);
|
||||||
|
@ -12,20 +12,17 @@ jar_DATA = $(jarfile)
|
|||||||
|
|
||||||
dist_noinst_JAVA = \
|
dist_noinst_JAVA = \
|
||||||
org/zmq/Context.java \
|
org/zmq/Context.java \
|
||||||
org/zmq/Socket.java \
|
org/zmq/Socket.java
|
||||||
org/zmq/Message.java
|
|
||||||
|
|
||||||
lib_LTLIBRARIES = libjzmq.la
|
lib_LTLIBRARIES = libjzmq.la
|
||||||
libjzmq_la_SOURCES = \
|
libjzmq_la_SOURCES = \
|
||||||
Context.cpp \
|
Context.cpp \
|
||||||
org_zmq_Context.h \
|
org_zmq_Context.h \
|
||||||
Socket.cpp \
|
Socket.cpp \
|
||||||
org_zmq_Socket.h \
|
org_zmq_Socket.h
|
||||||
Message.cpp \
|
|
||||||
org_zmq_Message.h
|
|
||||||
|
|
||||||
libjzmq_la_CXXFLAGS = -I$(top_builddir)/src/libzmq \
|
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_LDFLAGS = -version-info 0:0:0
|
||||||
libjzmq_la_LIBADD = $(top_builddir)/src/libzmq.la
|
libjzmq_la_LIBADD = $(top_builddir)/src/libzmq.la
|
||||||
|
|
||||||
@ -33,17 +30,13 @@ BUILT_SOURCES = \
|
|||||||
org/zmq/Context.class \
|
org/zmq/Context.class \
|
||||||
org_zmq_Context.h \
|
org_zmq_Context.h \
|
||||||
org/zmq/Socket.class \
|
org/zmq/Socket.class \
|
||||||
org_zmq_Socket.h \
|
org_zmq_Socket.h
|
||||||
org/zmq/Message.class \
|
|
||||||
org_zmq_Message.h
|
|
||||||
|
|
||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
org/zmq/Context.class \
|
org/zmq/Context.class \
|
||||||
org_zmq_Context.h \
|
org_zmq_Context.h \
|
||||||
org/zmq/Socket.class \
|
org/zmq/Socket.class \
|
||||||
org_zmq_Socket.h \
|
org_zmq_Socket.h \
|
||||||
org/zmq/Message.class \
|
|
||||||
org_zmq_Message.h \
|
|
||||||
Zmq.jar
|
Zmq.jar
|
||||||
|
|
||||||
$(srcdir)/Context.cpp: org_zmq_Context.h
|
$(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
|
./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:
|
dist-hook:
|
||||||
-rm $(distdir)/*.h
|
-rm $(distdir)/*.h
|
||||||
|
|
||||||
|
174
java/Socket.cpp
174
java/Socket.cpp
@ -26,13 +26,9 @@
|
|||||||
#include "org_zmq_Socket.h"
|
#include "org_zmq_Socket.h"
|
||||||
|
|
||||||
static jfieldID socket_handle_fid = NULL;
|
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 jmethodID create_socket_mid = NULL;
|
||||||
|
|
||||||
static void
|
static void raise_exception (JNIEnv *env, int err)
|
||||||
raise_exception (JNIEnv *env, int err)
|
|
||||||
{
|
{
|
||||||
// Get exception class.
|
// Get exception class.
|
||||||
jclass exception_class = env->FindClass ("java/lang/Exception");
|
jclass exception_class = env->FindClass ("java/lang/Exception");
|
||||||
@ -49,9 +45,8 @@ raise_exception (JNIEnv *env, int err)
|
|||||||
env->DeleteLocalRef (exception_class);
|
env->DeleteLocalRef (exception_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_construct (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_construct (JNIEnv *env, jobject obj, jobject context,
|
jobject context, jint type)
|
||||||
jint type)
|
|
||||||
{
|
{
|
||||||
if (socket_handle_fid == NULL) {
|
if (socket_handle_fid == NULL) {
|
||||||
jclass cls = env->GetObjectClass (obj);
|
jclass cls = env->GetObjectClass (obj);
|
||||||
@ -69,30 +64,14 @@ Java_org_zmq_Socket_construct (JNIEnv *env, jobject obj, jobject context,
|
|||||||
env->DeleteLocalRef (cls);
|
env->DeleteLocalRef (cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg_class == NULL) {
|
void *s = (void*) env->CallLongMethod (context, create_socket_mid, type);
|
||||||
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);
|
|
||||||
if (env->ExceptionCheck ())
|
if (env->ExceptionCheck ())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
env->SetLongField (obj, socket_handle_fid, (jlong) s);
|
env->SetLongField (obj, socket_handle_fid, (jlong) s);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_finalize (JNIEnv *env, jobject obj)
|
||||||
Java_org_zmq_Socket_finalize (JNIEnv *env, jobject obj)
|
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
@ -100,8 +79,8 @@ Java_org_zmq_Socket_finalize (JNIEnv *env, jobject obj)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_setHwm (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_setHwm (JNIEnv *env, jobject obj, jlong hwm)
|
jlong hwm)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
@ -110,8 +89,8 @@ Java_org_zmq_Socket_setHwm (JNIEnv *env, jobject obj, jlong hwm)
|
|||||||
raise_exception (env, errno);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_setLwm (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_setLwm (JNIEnv *env, jobject obj, jlong lwm)
|
jlong lwm)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
@ -121,8 +100,8 @@ Java_org_zmq_Socket_setLwm (JNIEnv *env, jobject obj, jlong lwm)
|
|||||||
raise_exception (env, errno);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_setSwap (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_setSwap (JNIEnv *env, jobject obj, jlong swap_size)
|
jlong swap_size)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
@ -132,8 +111,8 @@ Java_org_zmq_Socket_setSwap (JNIEnv *env, jobject obj, jlong swap_size)
|
|||||||
raise_exception (env, errno);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_setMask (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_setMask (JNIEnv *env, jobject obj, jlong mask)
|
jlong mask)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
@ -143,8 +122,8 @@ Java_org_zmq_Socket_setMask (JNIEnv *env, jobject obj, jlong mask)
|
|||||||
raise_exception (env, errno);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_setAffinity (JNIEnv *env,
|
||||||
Java_org_zmq_Socket_setAffinity (JNIEnv *env, jobject obj, jlong affinity)
|
jobject obj, jlong affinity)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
@ -154,8 +133,8 @@ Java_org_zmq_Socket_setAffinity (JNIEnv *env, jobject obj, jlong affinity)
|
|||||||
raise_exception (env, errno);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_setIdentity (JNIEnv *env,
|
||||||
Java_org_zmq_Socket_setIdentity (JNIEnv *env, jobject obj, jstring identity)
|
jobject obj, jstring identity)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
@ -176,8 +155,8 @@ Java_org_zmq_Socket_setIdentity (JNIEnv *env, jobject obj, jstring identity)
|
|||||||
raise_exception (env, errno);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_bind (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_bind (JNIEnv *env, jobject obj, jstring addr)
|
jstring addr)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
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);
|
const char *c_addr = env->GetStringUTFChars (addr, NULL);
|
||||||
if (c_addr == NULL)
|
if (c_addr == NULL) {
|
||||||
|
raise_exception (env, EINVAL);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int rc = zmq_bind (s, c_addr);
|
int rc = zmq_bind (s, c_addr);
|
||||||
env->ReleaseStringUTFChars (addr, 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);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_connect (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_connect (JNIEnv *env, jobject obj, jstring addr)
|
jstring addr)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
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);
|
const char *c_addr = env->GetStringUTFChars (addr, NULL);
|
||||||
if (c_addr == NULL)
|
if (c_addr == NULL) {
|
||||||
|
raise_exception (env, EINVAL);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int rc = zmq_connect (s, c_addr);
|
int rc = zmq_connect (s, c_addr);
|
||||||
env->ReleaseStringUTFChars (addr, 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);
|
raise_exception (env, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jboolean JNICALL Java_org_zmq_Socket_send (JNIEnv *env, jobject obj,
|
||||||
Java_org_zmq_Socket_send (JNIEnv *env, jobject obj, jobject msg, jlong flags)
|
jbyteArray msg, jlong flags)
|
||||||
{
|
{
|
||||||
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
assert (s);
|
assert (s);
|
||||||
|
|
||||||
zmq_msg_t *zmq_msg = (zmq_msg_t *)
|
jsize size = env->GetArrayLength (msg);
|
||||||
env->CallLongMethod (msg, get_msg_handle_mid);
|
jbyte *data = env->GetByteArrayElements (msg, 0);
|
||||||
|
|
||||||
if (env->ExceptionCheck ())
|
zmq_msg_t message;
|
||||||
return -1;
|
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);
|
||||||
if (rc == -1) {
|
|
||||||
raise_exception (env, errno);
|
rc = zmq_send (s, &message, (int) flags);
|
||||||
return -1;
|
|
||||||
|
if (rc == -1 && errno == EAGAIN) {
|
||||||
|
rc = zmq_msg_close (&message);
|
||||||
|
assert (rc == 0);
|
||||||
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT jobject 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);
|
|
||||||
|
|
||||||
if (env->ExceptionCheck ())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
int rc = zmq_recv (s, zmq_msg, (int) flags);
|
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
raise_exception (env, errno);
|
raise_exception (env, errno);
|
||||||
|
rc = zmq_msg_close (&message);
|
||||||
|
assert (rc == 0);
|
||||||
|
return JNI_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = zmq_msg_close (&message);
|
||||||
|
assert (rc == 0);
|
||||||
|
return JNI_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_zmq_Socket_flush (JNIEnv *env, jobject obj)
|
||||||
|
{
|
||||||
|
void *s = (void*) env->GetLongField (obj, socket_handle_fid);
|
||||||
|
assert (s);
|
||||||
|
|
||||||
|
int rc = zmq_flush (s);
|
||||||
|
|
||||||
|
if (rc == -1) {
|
||||||
|
raise_exception (env, errno);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
zmq_msg_t message;
|
||||||
|
zmq_msg_init (&message);
|
||||||
|
int rc = zmq_recv (s, &message, (int) flags);
|
||||||
|
|
||||||
|
if (rc == -1 && errno == EAGAIN) {
|
||||||
|
zmq_msg_close (&message);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return msg;
|
if (rc == -1) {
|
||||||
|
raise_exception (env, errno);
|
||||||
|
zmq_msg_close (&message);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,9 @@ public class Context {
|
|||||||
construct (appThreads, ioThreads);
|
construct (appThreads, ioThreads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal function. Do not use directly!
|
||||||
|
*/
|
||||||
public native long createSocket (int type);
|
public native long createSocket (int type);
|
||||||
|
|
||||||
/** Initialize the JNI interface */
|
/** Initialize the JNI interface */
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -19,26 +19,26 @@
|
|||||||
|
|
||||||
package org.zmq;
|
package org.zmq;
|
||||||
|
|
||||||
public class Socket {
|
public class Socket
|
||||||
|
{
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("jzmq");
|
System.loadLibrary("jzmq");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int ZMQ_MAX_VSM_SIZE = 30;
|
public static final int NOBLOCK = 1;
|
||||||
|
|
||||||
public static final int ZMQ_GAP = 1;
|
public static final int NOFLUSH = 2;
|
||||||
|
|
||||||
public static final int ZMQ_DELIMITER = 31;
|
public static final int P2P = 0;
|
||||||
|
|
||||||
public static final int ZMQ_NOBLOCK = 1;
|
public static final int PUB = 1;
|
||||||
|
|
||||||
public static final int ZMQ_NOFLUSH = 2;
|
public static final int SUB = 2;
|
||||||
|
|
||||||
public static final int ZMQ_P2P = 0;
|
public static final int REQ = 3;
|
||||||
|
|
||||||
public static final int ZMQ_PUB = 1;
|
public static final int REP = 4;
|
||||||
|
|
||||||
public static final int ZMQ_SUB = 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
@ -47,7 +47,6 @@ public class Socket {
|
|||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public Socket (Context context, int type) {
|
public Socket (Context context, int type) {
|
||||||
ctx = context;
|
|
||||||
construct (context, type);
|
construct (context, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,37 +93,39 @@ public class Socket {
|
|||||||
public native void setIdentity (String identity);
|
public native void setIdentity (String identity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Bind to network interface. Start listening for new connections.
|
||||||
|
*
|
||||||
* @param addr
|
* @param addr
|
||||||
*/
|
*/
|
||||||
public native void bind (String addr);
|
public native void bind (String addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect.
|
* Connect to remote application.
|
||||||
*
|
*
|
||||||
* @param addr
|
* @param addr
|
||||||
*/
|
*/
|
||||||
public native void connect (String addr);
|
public native void connect (String addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send.
|
* Send the message.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param msg
|
||||||
* @param block
|
* @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 ();
|
public native void flush ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receive message.
|
* Receive message.
|
||||||
*
|
*
|
||||||
* @param block
|
* @param flags
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public native Message recv (long flags);
|
public native byte [] recv (long flags);
|
||||||
|
|
||||||
/** Initialize JNI driver */
|
/** Initialize JNI driver */
|
||||||
protected native void construct (Context context, int type);
|
protected native void construct (Context context, int type);
|
||||||
@ -132,9 +133,6 @@ public class Socket {
|
|||||||
/** Free all resources used by JNI driver. */
|
/** Free all resources used by JNI driver. */
|
||||||
protected native void finalize ();
|
protected native void finalize ();
|
||||||
|
|
||||||
/** Keep reference to ZMQ context so it is not garbage collected */
|
|
||||||
private Context ctx;
|
|
||||||
|
|
||||||
/** Opaque data used by JNI driver. */
|
/** Opaque data used by JNI driver. */
|
||||||
private long socketHandle;
|
private long socketHandle;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ int main (int argc, char *argv [])
|
|||||||
int rc = gettimeofday (&start, NULL);
|
int rc = gettimeofday (&start, NULL);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
for (int i = 0; i != message_count - 1; i++) {
|
for (int i = 1; i != message_count; i++) {
|
||||||
s.recv (&msg);
|
s.recv (&msg);
|
||||||
assert (msg.size () == message_size);
|
assert (msg.size () == message_size);
|
||||||
}
|
}
|
||||||
|
@ -58,13 +58,13 @@ int main (int argc, char *argv [])
|
|||||||
end.tv_sec -= start.tv_sec;
|
end.tv_sec -= start.tv_sec;
|
||||||
start.tv_sec = 0;
|
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);
|
(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 ("message size: %d [B]\n", (int) message_size);
|
||||||
printf ("roundtrip count: %d\n", (int) roundtrip_count);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
55
perf/java/local_lat.java
Normal file
55
perf/java/local_lat.java
Normal file
@ -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 ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
65
perf/java/local_thr.java
Normal file
65
perf/java/local_thr.java
Normal file
@ -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]");
|
||||||
|
}
|
||||||
|
}
|
60
perf/java/remote_lat.java
Normal file
60
perf/java/remote_lat.java
Normal file
@ -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]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
53
perf/java/remote_thr.java
Normal file
53
perf/java/remote_thr.java
Normal file
@ -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 ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user