JPA - 服务器重新启动后首次运行时调用存储过程很慢。为什么?
我在 Glassfish 上部署了一个应用程序,它使用 JPA (Eclipselink 2.0) 来调用一些存储过程。
我正在做一些性能测试,我发现:每当 glassfish 服务器重新启动并且我尝试调用某些存储过程时,第一个调用总是很慢(与我选择调用哪个存储过程无关)。但随后的所有调用都很快。知道为什么会发生这种情况吗?
我检查了 glassfish 监视器,似乎不是连接问题。连接时间约为70毫秒,但存储过程调用需要1000多毫秒。所有子序列存储过程调用只需要不到 10 毫秒。
I have an application deployed on Glassfish that uses JPA (Eclipselink 2.0) to call some stored procedures.
I was doing some performance testing and I found out that: whenever glassfish server is restarted and I tried to call some stored procedure, the first call is always slow (doesn't matter which stored procedure I choose to call). but all the subsequent calls are fast. Any idea why this happens?
I checked the glassfish monitor, it doesn't appears to be the connection problem. the connection time is about 70 milliseconds but the stored procedure call takes more than 1000 milliseconds. All subsequence stored procedure calls only takes less than 10 milliseconds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是第一次访问 JPA 时拨打的电话吗?如果是,那么 JPA 会在首次访问时初始化持久性单元,因此这可能是您看到的成本。
否则,您可以尝试设置 EclipseLink Performance Profiler 以查看查询时间花在哪里,或者使用 Java 分析器(例如 JProfiler)。
在最新的 EclipseLink 版本中,有一个持久性单元属性“eclipselink.deploy-on-startup”,这将导致持久性单元在服务器启动时初始化,而不是在第一次访问时初始化。
Is the call the first time you access JPA? If it is, then JPA initializes the persistence unit when first accessed, so this may be the cost you are seeing.
Otherwise, you could try setting the EclipseLink Performance Profiler to see where the query time is being spent, or use a Java profiler such as JProfiler.
In the latest EclipseLink release there is a persistence unit poperty "eclipselink.deploy-on-startup", that will cause the persistence unit to be initialized when the server starts, instead of on first access.