简体   繁体   English

Java EJB / Hibernate性能,首次调用较慢

[英]Java EJB/Hibernate performance, slower first call

I have an Java application which is using an EJB client to make a calls to the server. 我有一个Java应用程序,该应用程序正在使用EJB客户端来调用服务器。 Server side EJB's create again calls to the DB. 服务器端EJB的create再次调用DB。 Hibernate is used, but second level cache is disabled. 使用了休眠模式,但禁用了二级缓存。 When performance testing DB calls using EJB client, usually the first calls take much longer than the next ones, even though calls are made using different parameters. 当使用EJB客户端对数据库调用进行性能测试时,即使使用不同的参数进行调用,通常第一个调用要比下一个调用花费更长的时间。 What things can explain or have effect on the performance in this scenario? 在这种情况下,哪些事情可以解释或影响性能?

EJB's on the top uses Java's RMI calls. 顶部的EJB使用Java的RMI调用。 Whenever your client calls the EJB components running in an EJB container, then in the meanwhile some expensive operations are performed. 每当您的客户端调用在EJB容器中运行的EJB组件时,就会同时执行一些昂贵的操作。

Lets say, you have a remote interface called HelloRemote and a service bean called HelloBean which implements the HelloRemote interface . 可以说,您有一个名为HelloRemote的远程接口和一个名为HelloBean的服务bean,它实现HelloRemote 接口

1) First your client needs to look-up for the service object which is registered with the JNDI Registry as : 1)首先,您的客户需要查找JNDI注册中心注册为以下内容的服务对象:

HelloRemote service=(HelloRemote)context.lookup("HelloBean/remote");  
// JBoss specific

Here, 这里,

i) Your client makes a call to LDAP Server which contains the JNDI Registry and looks for the remote bean registered with the given name. i)您的客户端调用包含JNDI注册表的LDAP服务器,并查找以给定名称注册的远程bean。

ii) If the any bean registry with the given name is found then the container first serializes the registered bean object and sends it to the client where it is again deserialized which is also known as marshaling and unmarshaling . ii)如果找到了具有给定名称的任何bean注册表,则容器首先序列化已注册的bean对象,并将其发送到客户端,在此客户端再次进行反序列化 ,这也称为封送处理拆封处理

The above step in itself is somewhat costly and that is why it is recommended that if your application architecture is going to use the same JVM for both the client application and the session beans, then use the local interface ( which can be a no-interface option starting from EJB 3.1) instead of using the remote interface. 上面的步骤本身会花费一些成本,这就是为什么建议如果您的应用程序体系结构将对客户端应用程序和会话Bean使用相同的JVM,则建议使用本地接口(可以是无接口)选项从EJB 3.1开始),而不是使用远程接口。

iii) With the Business interface stub in hand, you now invoke the business operations on that stub interface. iii)拥有业务接口存根,您现在可以在该存根接口上调用业务操作。 This stub performs the required serialization and delegates the call to the container. 该存根执行所需的序列化并将调用委托给容器。

The container now performs the deserialization and invokes the corresponding methods on Business interface object. 容器现在执行反序列化,并在Business接口对象上调用相应的方法。 The same process occurs when the result of this invocation is being returned to the cilent. 当此调用的结果返回给客户端时,将发生相同的过程。

As you can see there is a lot of Serialization and De-Serialization happening when a client communicates with the EJB component. 如您所见,当客户端与EJB组件进行通信时,会发生许多序列化和反序列化。 Enabling Second Level cache does improves the performance in Hibernate, but In view the communication b/w an EJB Client and an EJB service object is more expensive wrto time. 启用二级缓存确实可以提高Hibernate的性能,但是从黑白通信的角度来看,EJB客户端和EJB服务对象的写入时间更为昂贵。

NOTE : I was looking for someone to respond to this post, as i was also eager to know the reasons, however not finding any responses, I had this post with the whatever understanding i have on these topics 注意:我一直在寻找可以回应此帖子的人,因为我也很想知道原因,但是没有找到任何回复,我对这篇帖子的理解与我对这些主题的理解相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM