我正在尝试对启用了预写的点火缓存进行一些简单的基准测试(使用JMH)。 直写正常,但可以写出预写错误。
我收到CacheWriterException
,并且连接池正在超时。
数据源是Spring Boot配置的默认hikari datasource
(可与直写一起正常使用)。
点燃缓存配置
CacheConfiguration<Long, Customer> customerWriteAheadCacheCfg = new CacheConfiguration<(CacheName.WRITE_AHEAD.getCacheName());
customerWriteAheadCacheCfg.setIndexedTypes(Long.class, Customer.class);
customerWriteAheadCacheCfg.setWriteThrough(true);
customerWriteAheadCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
customerWriteAheadCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
customerWriteAheadCacheCfg.setWriteBehindEnabled(true);
customerWriteAheadCacheCfg.setWriteBehindBatchSize(50);
存储和实体配置
CacheJdbcPojoStoreFactory<Long, Customer> customerPojoFactory1 = new CacheJdbcPojoStoreFactory<>();
customerPojoFactory1.setDataSourceBean("dataSource");
customerPojoFactory1.setDialect(new BasicJdbcDialect());
JdbcType customerPojoType1 = new JdbcType();
customerPojoType1.setCacheName(CacheName.WRITE_AHEAD.getCacheName());
customerPojoType1.setKeyType(Long.class);
customerPojoType1.setValueType(Customer.class);
customerPojoType1.setDatabaseTable("customer");
customerPojoType1.setKeyFields(new JdbcTypeField(Types.INTEGER, "id", Long.class, "id"));
customerPojoType1.setValueFields(
new JdbcTypeField(Types.VARCHAR, "name", String.class, "name"),
new JdbcTypeField(Types.VARCHAR, "type", String.class, "type")
);
customerPojoFactory1.setTypes(customerPojoType1);
对于基准测试,我只是在缓存中使用put
public void saveToCacheWriteAhead(Customer customer) {
waCache.put(customer.getId(), customer);
}
关于可能导致错误的原因有什么想法?
答案 0 :(得分:0)
“连接不可用”可能意味着连接池已满。 如果提前写入,则在每个写入线程中打开一个连接。 因此,最大连接数应至少为写入线程数。