Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
67253f31
Commit
67253f31
authored
Sep 05, 2009
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Java perf tests added
parent
63b56d7f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
322 additions
and
165 deletions
+322
-165
Context.cpp
java/Context.cpp
+6
-9
Makefile.am
java/Makefile.am
+4
-18
Socket.cpp
java/Socket.cpp
+73
-67
Context.java
java/org/zmq/Context.java
+3
-0
Socket.java
java/org/zmq/Socket.java
+20
-22
local_thr.cpp
perf/cpp/local_thr.cpp
+1
-1
remote_lat.cpp
perf/cpp/remote_lat.cpp
+3
-3
local_lat.java
perf/java/local_lat.java
+55
-0
local_thr.java
perf/java/local_thr.java
+65
-0
remote_lat.java
perf/java/remote_lat.java
+60
-0
remote_thr.java
perf/java/remote_thr.java
+32
-45
No files found.
java/Context.cpp
View file @
67253f31
...
...
@@ -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
);
...
...
java/Makefile.am
View file @
67253f31
...
...
@@ -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
java/Socket.cpp
View file @
67253f31
...
...
@@ -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
j
int
JNICALL
Java_org_zmq_Socket_send
(
JNIEnv
*
env
,
jobject
obj
,
jobject
msg
,
jlong
flags
)
JNIEXPORT
j
boolean
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
j
object
JNICALL
Java_org_zmq_Socket_recv
(
JNIEnv
*
env
,
jobject
obj
,
jlong
flags
)
JNIEXPORT
j
byteArray
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
;
}
java/org/zmq/Context.java
View file @
67253f31
...
...
@@ -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 */
...
...
java/org/zmq/Socket.java
View file @
67253f31
...
...
@@ -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 m
essage
* @param
block
* @param m
sg
* @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
;
...
...
perf/cpp/local_thr.cpp
View file @
67253f31
...
...
@@ -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
);
}
...
...
perf/cpp/remote_lat.cpp
View file @
67253f31
...
...
@@ -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
;
}
perf/java/local_lat.java
0 → 100644
View file @
67253f31
/*
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
();
}
}
}
perf/java/local_thr.java
0 → 100644
View file @
67253f31
/*
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]"
);
}
}
perf/java/remote_lat.java
0 → 100644
View file @
67253f31
/*
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]"
);
}
}
java/org/zmq/Message
.java
→
perf/java/remote_thr
.java
View file @
67253f31
...
...
@@ -17,50 +17,37 @@
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
;
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
();
}
}
/** 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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment