为什么使用Hibernate进行查询缓存使查询速度降低了十倍?(Why does query caching with Hibernate make the query ten times slower?)
我目前正在尝试将EJB3作为工作中重要项目的预先研究。 我正在研究的其中一件事是查询缓存。
我使用JPA批注,一个@Local业务接口和一个在EJB-JAR中的@Stateless实现做了一个非常简单的领域模型,并在EAR中部署了一个非常简单的Web应用程序以进行一些基本测试。 EAR部署在JBoss 5.0.1默认配置中,无需修改。 这非常直接,并按预期工作。
然而,我最近的测试涉及查询缓存,并且我得到了一些奇怪的结果:
- 我有一个域类只映射一个ID和一个字符串值,并已在该特定的表中创建了约10000行
- 在商业bean中,有一个非常简单的查询,SELECT m FROM MyClass m
- 没有缓存,平均执行时间约为400毫秒
- 启用查询缓存(通过查询提示),第一次执行过程需要更长的时间,大约1200毫秒。 下一次执行平均需要3500毫秒!
这使我感到困惑,所以我让Hibernate的show_sql查看日志。 未缓存,并且在启用缓存的第一次执行时,如预期的那样记录了一个SELECT。 当我得到缓存命中时,Hibernate为数据库表中的每一行记录一个SELECT。
这肯定会解释执行时间缓慢,但任何人都可以告诉我为什么会发生这种情况?
I'm currently experimenting with EJB3 as a prestudy for a major project at work. One of the things I'm looking into is query caching.
I've made a very simple domain model with JPA annotations, a @Local business interface and a @Stateless implementation in an EJB-JAR, deployed in an EAR together with a very simple webapp to do some basic testing. The EAR is deployed in JBoss 5.0.1 default config with no modifications. This was very straighforward, and worked as expected.
However, my latest test involved query caching, and I got some strange results:
- I have a domain class that only maps an ID and a String value, and have created about 10000 rows in that particular table
- In the business bean, there's a very simple query, SELECT m FROM MyClass m
- With no cache, this executes in about 400ms on average
- With query cache enabled (through hints on the query), the first execution of course takes a little longer, about 1200ms. The next executions take 3500ms on average!
This puzzled me, so I enabled Hibernate's show_sql to look at the log. Uncached, and on the first execution with cache enabled, there is one SELECT logged, as expected. When I should get cache hits, Hibernate logs one SELECT for each row in the database table.
That would certainly explain the slow execution time, but can anyone tell me why this happens?
原文:https://stackoverflow.com/questions/890041
最满意答案
做最终的完整安装; 它仍然在那里。
Do a full install on ultimate; it is still there.
相关问答
更多-
ASP.NET Web服务应用程序项目模板不适用于.Net Framework 4.0,但可用于.Net Framework 3.5。 如果您在.net framework 4.0上构建应用程序,则可以在传统中将WCF Service Application用作ASMX。 请注意,您需要启用AspNetCompatibilityMode才能访问HttpContext对象。 如果您仍想使用ASMX,请选择“ASP.NET空白Web应用程序”,然后将ASMX文件添加到项目中。 ASP.NET Web Servi ...
-
做最终的完整安装; 它仍然在那里。 Do a full install on ultimate; it is still there.
-
Web部署在Visual Studio 2010中 - 缺少Web管理服务(Web deploy in Visual Studio 2010 - web management service is missing)[2023-11-15]
以下是截至2014年4月的当前演练: 在服务器上安装Web平台安装程序, 可从Microsoft下载 。 http://www.schiffhauer.com/wp-content/uploads/2014/04/2014-04-01_14-26-18.png 打开Web平台安装程序,在顶部选择“产品”,并搜索“管理服务”。 单击“添加”按钮从“IIS:管理服务”结果,然后单击“安装”。 http://www.schiffhauer.com/wp-content/uploads/2014/04/2014-0 ... -
如果你指的是如何在vs2010中添加旧的asmx样式引用右键单击引用并选择“添加服务引用”,然后单击“高级”,然后单击“添加Web引用” 对于一个wcf服务,只需右键单击并说“添加引用” 使用它 - 输入您班级的名字。 由于我不知道你的名字空间,你可能必须在顶部包含一个导入。 但基本上 - ServiceReference1.WhateverClient cleint = new ServiceReference1.WhateverClient(); 在代码中执行ServiceReference1时,应该会 ...
-
我相信“Windows Azure项目”是正确的,“云服务项目”只是旧术语。 我也没有一个名为的项目模板。 I believe "Windows Azure project" is correct, and "Cloud Service Project" is just old terminology. I don't have a project template called that either.
-
使用visual studio 2010消费sharepoint 2010 Web服务(consuming sharepoint 2010 web service with visual studio 2010)[2022-05-04]
试试这个代码:请尝试以下功能。 您需要传递FileURL(文档的完整网址),标题(您希望为下载的文件提供通行证名称。) (注意:此功能需要传递凭据以及要下载的文档的完整URL。我认为这对您来说已经足够了) public string DownLoadfiletolocal(string FileURL, string Title) { //Copy.Copy is a webservice object that I consumed. Copy.Copy CopyObj = new Copy.Copy ... -
根据Visual C ++团队博客上的评论 ,他们从Visual Studio 2008开始被删除。但是,您可以在codeplex上找到最新版本。 通过利用以前版本的Visual Studio中的项目模板,可能有一种方法可以使用最新的编译器来构建这样的项目。 本文介绍了如何完成它。 According to the comments on the Visual C++ Team Blog they were removed starting with Visual Studio 2008. However, ...
-
在VS2010中创建Web服务的两种方法之间的区别?(Difference between two methods of creating a Web Service in VS2010?)[2023-03-26]
我将通过以下方式回答我自己的问题:我认为这不重要。 I'm going to answer my own question by way of saying: I don't think it matters. -
是。 但为了将来的理解,请考虑以下注意事项: 创建Web服务实际上不需要任何IDE。 您可以使用记事本创建Web服务(或整个网站)。 因此,Visual Studio只是一个有用的工具。 创建基于.NET Framework的Web服务实际上需要您编译代码。 因此,您可以再次使用记事本创建Web服务,并使用C#或VB.NET编译器进行编译,部署并使用它。 Visual Web Developer 2010(Express)只是一个IDE。 另一方面,Web Service是一个项目模板 (为您编写基本的基础 ...
-
Nuget仅为您提供运行Web API所需的程序集。 要使用MVC4 Web Api Visual Studio模板,您必须从此处安装MVC4软件包 - http://www.asp.net/web-api 。 安装完成后,在“创建新项目”向导中,您必须选择MVC4模板,然后在下一个窗口中选择Web API项目。 请注意,如果您不明确需要MVC4应用程序,则不需要这样做。 您可以将Web API与几乎任何东西一起使用 - MVC3,Web窗体,控制台应用程序,WPF应用程序......它不依赖于MVC4。 ...