问题描述
我有Hibernate,Spring,PostgreSQL,MongoDB,Neo4j和ElasticSearch的系统,并与EhCache一起用于Hibernate L2和Spring Cache,它运行良好。
I have system with Hibernate, Spring, PostgreSQL, MongoDB, Neo4j and ElasticSearch working with EhCache for Hibernate L2 and Spring Cache, it works well.
我测试Ignite,但是当我将Ignite用于Hibernate L2(使用Spring Cache可以快速运行)时,系统变得非常慢,我使用JProfiler来查看真正慢的东西,而我只是看到以下方法非常慢:
I'm testing Ignite but the system became extremely slow when I put Ignite for Hibernate L2 (with Spring Cache works fast), I put JProfiler to see what is really slow and I just saw the follow methods extremely slow:
org.postgresql.core.VisibleBufferedInputStream.read(byte[ ], int, int)
org.postgresql.jdbc2.AbstractJdbc2Statement.parseSql
javax.persistence.EntityManager.find
对我来说这没有多大意义。我正在使用(我进行了更改以自动为Hibernate L2创建缓存),我在1.4.0下进行了测试,问题还是一样。
This doesn't make much sense to me. I'm using Ignite 1.5.1.final-SNAPSHOT from Branch 1.5.1-2 with https://github.com/apache/ignite/pull/388 (I made a change to automatically create the caches for Hibernate L2), I tested with 1.4.0 and the problem is the same.
用于Ignite的配置:
Configuration for Ignite:
@Configuration
public class CacheConfiguration {
@Bean
public DynamicClassLoaderWrapper dynamicClassLoaderWrapper() {
return new DynamicClassLoaderWrapper(this.getClass().getClassLoader());
}
@Bean
@SuppressWarnings("unchecked")
public CacheManager cacheManager() {
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setGridName("meceap-grid");
igniteConfiguration.setClassLoader(dynamicClassLoaderWrapper());
igniteConfiguration.setCacheConfiguration(this.createDefaultCache("br.com.bruno.model.*"),
this.createDefaultCache("org.hibernate.cache.spi.UpdateTimestampsCache"),
this.createDefaultCache("org.hibernate.cache.internal.StandardQueryCache"));
SpringCacheManager springCacheManager = new SpringCacheManager();
springCacheManager.setConfiguration(igniteConfiguration);
springCacheManager.setDynamicCacheConfiguration(this.createDefaultCache(null));
return springCacheManager;
}
private org.apache.ignite.configuration.CacheConfiguration createDefaultCache(String name) {
org.apache.ignite.configuration.CacheConfiguration cacheConfiguration = new org.apache.ignite.configuration.CacheConfiguration();
cacheConfiguration.setName(name);
cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheConfiguration.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cacheConfiguration.setStatisticsEnabled(true);
cacheConfiguration.setEvictSynchronized(true);
return cacheConfiguration;
}
}
public class RepositoryConfiguration {
@Bean
public LocalContainerEntityManagerFactoryBean meceapEntityManagerFactory() {
LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
bean.setDataSource(dataSource);
bean.getJpaPropertyMap().put("hibernate.dialect", hibernateDialect);
bean.getJpaPropertyMap().put("hibernate.ejb.naming_strategy", NamingStrategyLowerCase.class.getCanonicalName());
bean.getJpaPropertyMap().put("hibernate.jdbc.batch_size", 0);
bean.getJpaPropertyMap().put("hibernate.use_sql_comments", true);
bean.getJpaPropertyMap().put("hibernate.show_sql", false);
bean.getJpaPropertyMap().put("org.apache.ignite.hibernate.grid_name", "meceap-grid");
bean.getJpaPropertyMap().put("hibernate.cache.region.factory_class", HibernateRegionFactory.class.getCanonicalName());
bean.getJpaPropertyMap().put("hibernate.cache.use_second_level_cache", true);
bean.getJpaPropertyMap().put("hibernate.cache.use_query_cache", true);
bean.getJpaPropertyMap().put("javax.persistence.sharedCache.mode", SharedCacheMode.ALL);
bean.getJpaPropertyMap().put("hibernate.cache.default_cache_concurrency_strategy", "read-write");
bean.getJpaPropertyMap().put("hibernate.generate_statistics", true);
bean.getJpaPropertyMap().put("javax.persistence.validation.factory", validator);
bean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
bean.setPackagesToScan("br.com.me.ceap.model");
meceapEntityManagerFactoryRef = bean;
return bean;
}
}
推荐答案
似乎仍在使用EhCache区域工厂,因此实际上并未将Ignite配置为L2缓存。
It looks like EhCache region factory is still used, so Ignite is not actually configured as the L2 cache.
您应该使用Ignite的 HibernateRegionFactory
代替,有关正确配置的示例,请参考 HibernateL2CacheExample
。
You should use Ignite's HibernateRegionFactory
instead, refer to HibernateL2CacheExample
for example of correct configuration.
这篇关于Hibernate L2的点火非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!