使用jboss传输序列化对象比传输字节数组快得多?

发布于 2024-12-07 08:34:29 字数 1368 浏览 2 评论 0原文

以下场景:

我有一个具有 40 个线程的 java 客户端。每个线程都有自己的 bean 实例,并且每个线程调用其 beans 方法 100 次。 我对此测试的结果感到困惑,因为发送对象比发送字节数组或整数数组要快得多。不过,发送单个整数值仍然是最快的。此测试中两个数组的大小均为 1。大小 2048 既不慢也不快。 map、data、panel、maprecord 和 field 是具有相当多属性的类。

怎么会这样呢?

静态:创建一次,服务器始终返回相同的实例 动态:每次调用 beans 方法时创建

sessions: 40
repetitions: 100
transactions: 4000

send bytes ( static )
transactions/s: 1047.3947
time: 3.819

send ints ( dynamic )
transactions/s: 11976.048
time: 0.334

send int arrays ( static )
transactions/s: 1114.5166
time: 3.589

send map with 30 fields ( static )
transactions/s: 4613.6104
time: 0.867

send map, created from panel ( dynamic )
transactions/s: 221.50847
time: 18.058

send data, containing a map created from a maprecord ( dynamic )
transactions/s: 5797.1016
time: 0.69

我的 javax.ejb.EJBObject:

...
public byte[] getByteArrayForPerformanceTest() throws java.rmi.RemoteException;
public Map getMapForPerformanceTest() throws java.rmi.RemoteException;
public Data getConverseDataForPerformanceTest() throws java.rmi.RemoteException;
...

UserSessionBean:

...
private static byte[] byteArrayForPerformanceTest = new byte[1];

public byte[] getByteArrayForPerformanceTest() throws java.rmi.RemoteException {
    return UserSessionBean.byteArrayForPerformanceTest;
}
...

Following scenario:

I have a java client with 40 threads. Each thread has its own bean instance and each thread calls its beans method 100 times.
I'm confused about the results of this test because sending objects turned out to be a lot faster than sending byte arrays or integer arrays. Sending a single integer value is still fastest, though. The size of both arrays in this test was 1. Size 2048 was neither slower nor faster.
map, data, panel, maprecord and field are classes with quite a lot of properties.

How can this be?

static: created once, server always returns same instance
dynamic: created everytime the beans method is called

sessions: 40
repetitions: 100
transactions: 4000

send bytes ( static )
transactions/s: 1047.3947
time: 3.819

send ints ( dynamic )
transactions/s: 11976.048
time: 0.334

send int arrays ( static )
transactions/s: 1114.5166
time: 3.589

send map with 30 fields ( static )
transactions/s: 4613.6104
time: 0.867

send map, created from panel ( dynamic )
transactions/s: 221.50847
time: 18.058

send data, containing a map created from a maprecord ( dynamic )
transactions/s: 5797.1016
time: 0.69

My javax.ejb.EJBObject:

...
public byte[] getByteArrayForPerformanceTest() throws java.rmi.RemoteException;
public Map getMapForPerformanceTest() throws java.rmi.RemoteException;
public Data getConverseDataForPerformanceTest() throws java.rmi.RemoteException;
...

The UserSessionBean:

...
private static byte[] byteArrayForPerformanceTest = new byte[1];

public byte[] getByteArrayForPerformanceTest() throws java.rmi.RemoteException {
    return UserSessionBean.byteArrayForPerformanceTest;
}
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神魇的王 2024-12-14 08:34:29

那么,您的集合、映射和数组以及基元都是可序列化的。 JBoss 更有可能使用标准 Java 序列化在远程实体之间发送/接收这些实例。如果您不想解释为什么一件事比另一件事进展得更快,那么为什么不将这两个实例序列化为单独的文件并查看哪一个更大。特别是对于集合和映射,当实例化它们时,您无法知道在幕后创建了多少对象(尤其是数组)。请注意,对于这些,您可以在某种程度上控制底层数组的初始大小。

Well your Collections, Maps, and arrays are all serializable, as well as the primitives. It's more likely that JBoss uses standard Java serialization to send/receive these instances between remote entitites. If you wan't an explanation as to why one thing goes faster than other, then why don't you serialize both those instances to separate files and see which one is bigger. Especially with collections and maps you can't know how many objects (especially arrays) are created under the hood when you instantiate them. Note that for these you can controll to some point the initial sizes of the underlying arrays.

悸初 2024-12-14 08:34:29

您没有说明这里的内容,但您可能会将对象序列化为字节数组,然后发送这些对象,并且 JBoss 正在序列化它们,因此有两个序列化步骤。

You don't say what is under the hood here but you might for example be serializing your objects to byte arrays then sending those and JBoss is serializing them, so two serialization step.s

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文