Hibernate L2缓存中的Ignite性能极慢

3

我有一个系统,使用了Hibernate、Spring、PostgreSQL、MongoDB、Neo4j和ElasticSearch,并且使用EhCache作为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

对我来说这没什么意义。我正在使用分支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;
    }

}


在您的分析结果中,缓存未被使用,因为它正在等待数据库。这对您有意义吗? - Kayaman
在Ignite上的命中率与其他供应商相比,您是否没有遇到这个问题?存活期/到期/驱逐设置可能不同吗? - Dragan Bozanovic
定义“极慢”。 - Norbert
@Kayaman,分析器显示缓存未被使用,但实际上已经在使用,如果我关闭Hibernate L2或切换回EhCache,则系统正常工作。 - Bruno
@DraganBozanovic 缓存命中率与使用 EhCache 之前相同,没有任何变化。 - Bruno
@NorbertvanNobelen 一个通过Hibernate的获取操作需要几分钟时间,而且我发现每次执行时间都在增加。 - Bruno
1个回答

2
看起来仍在使用EhCache区域工厂,因此Ignite实际上没有配置为L2缓存。
你应该使用Ignite的HibernateRegionFactory,参考HibernateL2CacheExample以获取正确配置示例。

非常抱歉出现错误,我在文本中放入了错误的值,但是在我的应用程序中我正在使用HibernateRegionFactory,我会查看HibernateL2CacheExample中的配置并进行更多测试。 - Bruno
我检查了示例中的配置,一切都没问题,但在我的应用程序中,Hibernate Ignite L2 真的很慢。我已经没有更多的想法了... - Bruno
我在Apache Ignite JIRA中开了一个工单。看起来有必要让社区的某个人来调查这个问题。@Bruno,如果可能的话,请在JIRA工单中提供可重现示例的链接或至少代码的一部分。如果您能在GitHub或其他工具上分享源代码,那就太完美了。 - dmagda
@dmagda 很抱歉,我只能展示我的配置,因为我所在的系统是私有的。请提供工单链接,我可以提供他们可能需要的更多信息。 - Bruno
@Bruno 这是Ignite JIRA中的工单。请在那里提供更多细节。 - dmagda

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接