coherence比较小众,网上查询的资料很少。如果生产环境上使用默认的配置,那就会出现问题:
1. 经常会出现缓存条目被频繁age out出缓存。
2. 网络流量拥堵。
以下是默认的设置。
<local-scheme>
<scheme-name>example-binary-backing-map</scheme-name><eviction-policy>HYBRID</eviction-policy>
<high-units>{back-size-limit 0}</high-units>
<unit-calculator>BINARY</unit-calculator>
<expiry-delay>{back-expiry 1h}</expiry-delay>
<cachestore-scheme></cachestore-scheme>
</local-scheme>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>dist-sessionShareCache</cache-name>
<scheme-name>example-distributed</scheme-name>
<init-params>
<init-param>
<param-name>back-size-limit</param-name>
<param-value>8MB</param-value>
</init-param>
</init-params>
</cache-mapping>
<cache-mapping>
<cache-name>dist-default</cache-name>
<scheme-name>example-distributed</scheme-name>
<init-params>
<init-param>
<param-name>back-size-limit</param-name>
<param-value>8MB</param-value>
</init-param>
</init-params>
</cache-mapping>
要想知缓存条目被频繁age out出缓存,就得知道缓存策略。
<eviction-policy> Optional Specifies the type of eviction policy to use.Legal values are:
■ LRU – Least Recently Used eviction policy chooses which entries to
evict based on how recently they were last accessed, evicting those
that were not accessed the for the longest period first.
■ LFU – Least Frequently Used eviction policy chooses which entries to
evict based on how often they are being accessed, evicting those that
are accessed least frequently first.
■ HYBRID (default) – Hybrid eviction policy chooses which entries to
evict based on the combination (weighted score) of how often and
recently they were accessed, evicting those that are accessed least
frequently and were not accessed for the longest period first.
■ <class-scheme> – A custom eviction policy, specified as a
class-scheme. The class specified within this scheme must implement
the ConfigurableCacheMap.EvictionPolicy interface or extend the
AbstractEvictionPolicy class
看官方文档得小心了,不同的unit-calculator设置单位不同。如果按照默认的设置,缓存只是设置了8M,整个JVM设置的是4G,完全没有用到。
<unit-calculator> Optional Specifies the type of unit calculator to use. A unit calculator is used to
determine the cost (in "units") of a given object. This element is used only
if the high-units element is set to a positive number. Legal values are:
■ FIXED – A unit calculator that assigns an equal weight of 1 to all
cached objects.
■ BINARY (default) – A unit calculator that assigns an object a weight
equal to the number of bytes of memory that are required to cache
the object. This calculator is used for Partitioned Caches that cache
data in a binary serialized form. See
com.tangosol.net.cache.BinaryMemoryCalculator for additional
details.
■ <class-scheme> – A custom unit calculator, specified as a
class-scheme. The class specified within this scheme must implement
the
com/tangosol/net/cache/ConfigurableCacheMap.UnitCalculator
interface
那网络的拥堵原因是什么呢?我认为是key被频繁age out,会导致需要频繁的put,况且数据节点之间也需要同步数据,进一步加重的网络的负担。