简体   繁体   English

休眠查询在堆转储中的作用

[英]Role of hibernate queries in heap dump

I'm JProfiling my application to analyze high CPU usage. 我正在JProfiling我的应用程序以分析高CPU使用率。 CPU usage is 100% ( at server ) at the time of user login. 用户登录时,CPU使用率为100%( 在服务器上 )。 So started profiling my application. 因此,开始分析我的应用程序。

The below query strings I found in the heap dumps. 我在堆转储中找到的以下查询字符串。 Not only these 4 queries, there are hundreds of queries like this in the dump. 不仅这4个查询,转储中还有数百个类似的查询。

java.lang.String (0x3262b1) ["/* load com.v4common.shared.beans.transaction.ControlTransaction */ select controltra0_.id as id47_48_, controltra0_.form_transaction_id as form2_47_48_, controltra0_.string_value as string3_47_48_, c"]     129 kB (0 %)
java.lang.String (0x310b2f) ["/* load com.v4common.shared.beans.transaction.ReportTransaction */ select reporttran0_.id as id158_45_, reporttran0_.report_id as report2_158_45_, reporttran0_.norm_id as norm3_158_45_, reporttran0_.d"]     124 kB (0 %)
java.lang.String (0x312222) ["/* load com.v4common.shared.beans.transaction.ReportItemTransaction */ select reportitem0_.id as id160_41_, reportitem0_.report_structure as report2_160_41_, reportitem0_.grid_row_criteria as grid3_16"]     110 kB (0 %)
java.lang.String (0x30c104) ["/* load com.v4common.shared.beans.Reports.EsenderCSReport */ select esendercsr0_.id as id117_36_, esendercsr0_.name as name117_36_, esendercsr0_.report_type as report3_117_36_, esendercsr0_.is_show_pr"]     94,248 bytes (0 %)
java.lang.String (0x30d1dc) ["/* load com.v4common.shared.beans.Reports.ReportStructure */ select reportstru0_.id as id120_35_, reportstru0_.name as name120_35_, reportstru0_.xml as xml120_35_, reportstru0_.esender_format as esend"]     90,736 bytes (0 %)

I'm just logged in the system and I'm not touching the beans at all, still I'm able to see them in the dumps. 我刚刚登录系统,根本没有碰过豆子,但仍然可以在转储中看到它们。

Any ideas why those strings are there in the dump? 有什么想法为什么这些字符串存在于转储中?

Or what does that line mean even? 或那行甚至意味着什么?

This is normal, these are the Hibernate pre-prepared queries that are prepared at server startup time. 这是正常的,这些是在服务器启动时准备的Hibernate预查询。

Take for example the ControlTransaction class. ControlTransaction类为例。 Hibernate already knows that will probably need queries to select entities by ID, delete them, etc. Hibernate已经知道,可能需要查询以按ID选择实体,将其删除等。

So it generates beforehand a series of SQL prepared statements to do these operations. 因此,它会预先生成一系列准备好的SQL语句来执行这些操作。 The comments at the beginning of each query indicate why they where generated. 每个查询开头的注释指示生成它们的原因。

For example this query was generated to load a ControlTransaction by Id: 例如,生成此查询以通过ID加载ControlTransaction:

/* load com.v4common.shared.beans.transaction.ControlTransaction */ 
select controltra0_.id as id47_48_, controltra0_.form_transaction_id as form2_47_48_, controltra0_.string_value as string3_47_48_, c 

Queries that start with comments of one-to-many or one-to-one , are used for lazy loading, etc. Named queries in JPQL/HQL are also compiled into a SQL query at server startup and the comment identifies which named query originated the SQL query. one-to-manyone-to-one注释开头的查询用于延迟加载等。JPQL / HQL中的命名查询在服务器启动时也被编译成SQL查询,并且注释标识了哪个命名查询源自SQL查询。

Each entity will give rise to several of these queries, depending on the mapping annotations used. 每个实体都将引起其中一些查询,具体取决于所使用的映射注释。

So it's actually normal that these queries are there in the heap at user first login time. 因此,在用户首次登录时,这些查询实际上在堆中是正常的。

Do you have these queries as @NamedQueries (or @NamedQuery ) on any of your Entities? 您是否在任何实体上将这些查询作为@NamedQueries (或@NamedQuery )使用?

Hibernate could be loading the Named Queries into it's cache at server startup time. Hibernate可能在服务器启动时将“命名查询”加载到其缓存中。 They are certainly parsed at startup to check syntax, etc. 当然,它们会在启动时进行解析以检查语法等。

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

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