0
我正在使用Hibernate中的二級緩存(啓用EhCache)進行基準測試,但似乎並未提高性能。實際上,執行查詢的時間略有增加。使用EhCache for session.createCriteria(...)。list()
查詢是:
session.createCriteria(MyEntity.class).list();
的實體是:
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MyEntity {
@Id
@GeneratedValue
private long id;
@Column(length=5000)
private String data;
//---SNIP getters and setters---
}
我的hibernate.cfg.xml是:
<!-- all the normal stuff to get it to connect & map the entities plus:-->
<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>
的myEntity所表包含約2000行。
問題是,在添加緩存之前,上面列出所有實體的查詢平均需要65毫秒。緩存之後,它們平均需要74毫秒。有什麼我失蹤?是否還有其他需要完成的工作可以提高性能?
謝謝,我啓用了查詢緩存,它絕對有所作爲。查詢從未緩存的65毫秒變爲22毫秒,然後恢復。 – 2010-06-12 17:05:39
@James:對於更復雜的查詢,差異應該更明顯。 – skaffman 2010-06-12 17:44:00