gpt4 book ai didi

java - Ignite for Hibernate L2 非常慢

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:32 25 4
gpt4 key购买 nike

我的系统包含 Hibernate、Spring、PostgreSQL、MongoDB、Neo4j 和 ElasticSearch,并使用 EhCache for Hibernate L2 和 Spring Cache,效果很好。

我正在测试 Ignite,但是当我将 Ignite 用于 Hibernate L2(使用 Spring Cache 运行速度很快)时,系统变得非常慢,我使用 JProfiler 来查看真正慢的是什么,我只看到以下方法非常慢:

org.postgresql.core.VisibleBufferedInputStream.read(byte[ ], int, int)
org.postgresql.jdbc2.AbstractJdbc2Statement.parseSql
javax.persistence.EntityManager.find

这对我来说意义不大。我正在使用来自 Branch 1.5.1-2 的 Ignite 1.5.1.final-SNAPSHOT 和 https://github.com/apache/ignite/pull/388 (我做了一个更改,自动为 Hibernate L2 创建缓存),我用 1.4.0 测试,问题是一样的。

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 region factory,所以Ignite实际上并没有配置为二级缓存。

您应该改用 Ignite 的 HibernateRegionFactory,有关正确配置的示例,请参阅 HibernateL2CacheExample

关于java - Ignite for Hibernate L2 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34534251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com