0

I'd like to test how selecting and loading data in java application using hibernate and mysql can be optimized.

I divided results I found into 2 groups

MySQL

  • indexes - for sure
  • stored procedures - is there a difference if select is done in stored procedure?
  • views - is there a difference if select definition is kept in view?
  • query cache - does it work only if we do the same select second time?

Hibernate

  • hibernate cache - is this similar to query cache? how it can be configured?
  • lazy loading - can it help?

Are there any other ways? I use simple queries with several joins and aggregation functions. I need to demonstate time changes between "before" and "after" optimization.

For more information I tried to read this, but language is to complicated for me.

4

1 回答 1

0
  1. 当您阅读例如集合时,批量获取很重要。在这种情况下,Hibernate 可以在一个 SQL 请求中获取集合的许多行,这样会更快。
  2. Hibernate 缓存是一个非常好的解决方案(例如阅读 EHCache),它可以将检索到的数据存储在内存中,如果他这边没有任何变化,它甚至可以在不询问 SQL 引擎的情况下检索它。
  3. 延迟加载对于一对多关联是必须的(没有这个你可以杀死你的解决方案)。但幸运的是,它在 Hibernate 中默认设置为此类关联。

您还可以阅读有关乐观锁的信息,它在许多情况下比悲观锁更快。

最后但并非最不重要的一点是,您应该使用适当的事务策略,以便在不需要时不要创建新事务。

于 2013-05-04T17:17:13.757 回答