簡體   English   中英

Ignite for Hibernate L2非常慢

[英]Ignite for Hibernate L2 is extremely slow

我有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;
    }

}

看起來EhCache區域工廠仍然使用,因此Ignite實際上並未配置為L2緩存。

您應該使用Ignite的HibernateRegionFactory ,請參閱HibernateL2CacheExample以獲取正確配置的示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM