近日在项目中使用了JBOSS Cache(1.4.1sp6)来做全局缓存同步,但测试发现写对象的性能非常低 。后来仔细测试才发现是配置问题。JBOSS Cache支持文件和JDBC加载器,这两种加载器是用于把缓存中的数据持久化的,如果你的应用系统不需要持久化的话,请不要加上加载器的配置。持久化的好处就是在系统DOWN掉以后缓存中的数据在下次启动系统时依然可用,通常这种方案在很多时候是不需要的,而一但设置需要持久化,JBOSS CACHE的实现方案是在每次写入时都会同步持久化数据,性能非常低下。去掉加载器的配置则性能得以大副提高。即把配置文件中的如下类似的一段去掉:
<attribute name="CacheLoaderConfiguration">
<config>
<!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
<passivation>false</passivation>
<preload>/</preload>
<shared>false</shared>
<!-- we can now have multiple cache loaders, which get chained -->
<cacheloader>
<class>org.jboss.cache.loader.FileCacheLoader</class>
<!-- same as the old CacheLoaderConfig attribute -->
<properties>
location=/tmp/node1
</properties>
<!-- whether the cache loader writes are asynchronous -->
<async>false</async>
<!-- only one cache loader in the chain may set fetchPersistentState to true.
An exception is thrown if more than one cache loader sets this to true. -->
<fetchPersistentState>true</fetchPersistentState>
<!-- determines whether this cache loader ignores writes - defaults to false. -->
<ignoreModifications>false</ignoreModifications>
<!-- if set to true, purges the contents of this cache loader when the cache starts up.
Defaults to false. -->
<purgeOnStartup>false</purgeOnStartup>
</cacheloader>
</config>
</attribute>