`
woshizn
  • 浏览: 207056 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Terracotta集群定制安装

    博客分类:
  • Java
阅读更多

分布式Ehcache 参考
这个文档包括一个Terracotta 分布cache的参考信息

快速安装 与定制安装

有2种方法来安装Terracotta分布cache:快速与定制。快速安装适用于只需要一个cache的集群。定制安装适用于需要一个cache集群和其他java对象,例如sessions和定制POJOs,或者使用Terracotta应用,或者使用Terracotta整合模块(Terracotta integration Modules:TIMs)整合其他技术。

如果你使用Ehcache在一个单独的JVM上,或者使用一个集群响应,可以考虑快速安装(在这里 )。如果你是一个前沿的Terracotta使用者,而且想要添加一个分布caching,可以考虑使用定制安装。

如果你不确定用哪种方式安装,请阅读2中安装方法,然后找到适合你的安装方法。这2中安装方法不兼容,也不能被兼容使用。

分布式cache配置文件

Terracotta分布式配置文件(默认为ehcache.xml)包含一个CacheMananger(the Ehcache class managing a set of defined caches)的一个实例的配置。这个配置文件必须在你应用的classpath里面。当你使用WAR文件的时候,需要将ehcache.xml复制到WEB-INF/classes中。

Terracotta集群配置元素

<terracotta>
这个element是一个<cache>中可选的sub-element。在ehcache.xml中定义的每个<cache>中,<terracotta>可以做不同的设置。
<terracotta>有以下这些特性:
clusted - 开启("true")或者关闭("false")terracotta集群对于某个cache。
valueMode - 设置cache序列化的方式(the standard Ehcache "copy" cache)或者标识 (Terracotta object identity)。标识只能在定制安装中被使用(查看快速安装
提示:比较序列化和标识模块

In serialization mode, getting an element from the cache gets a copy of that element. Changes made to that copy do not affect any other copies of the same element or the value in the cache. Putting the element in the cache overwrites the existing value. This type of cache provides high performance with small, read-only data sets. Large data sets with high traffic, or caches with very large elements, can suffer performance degradation because this type of cache serializes clustered objects. In read-write data sets, data coherency issues may arise because this type of cache cannot guarantee a consistent view of object values. Objects clustered in this mode _must be_ serializable.

In identity mode, getting an element from the cache gets a reference to that element. Changes made to the referenced element updates the element on every node on which it exists (or a reference to it exists) as well as updating the value in the cache. Putting the element in the cache does not overwrite the existing value. This mode guarantees data coherence. It can be used only with a custom Terracotta Distributed Cache installation. Objects clustered in this mode must be portable
 and must be locked when accessed.
 


 
 默认的在<cache>模块中添加<terracotta/>等价于添加<terracotta clustered="true" valueMode="seralization">。如果valueMode没有指明,会使用默认的"seralization"。
 
 <terracottaConfig>
 这个元素只在快速安装中使用(查看快速安装 )。当Terracotta对于某个cache打开时,这个元素必须用url或者用一个内嵌配置,指明Terracotta配置文件(默认为tc-config.xml)。
 
 用URL属性
 为<terracottaConfig>元素添加一个URL属性:
 <terracottaConfig url="<source>" />
 <source>可以是以下几种方式:
 路径:(例如:url="/path/to/tc-config.xml")
 URL:(例如:url="http://www.mydomain.com/path/to/tc-config.xml)
 Terracotta主机地址:(例如:url="host1:9510")
 
 Note the following about using server addresses in the form <host>:<dso-port>:

  •     * The default DSO port is 9510.
  •     * In a multi-server cluster, you can specify a comma-delimited list (for example, url="host1:9510,host2:9510,host3:9510" ).


内嵌Terracotta配置
你可以在ehcache.xml中内嵌一个关于Terracotta配置的内容:

<terracottaConfig>

        <tc-config>

            <servers>

                <server host="server1" name="s1"/>

                <server host="server2" name="s2"/>

            </servers>

            <clients>

                <logs>app/logs-%i</logs>

            </clients>           

        </tc-config>

    </terracottaConfig>
 

    
编辑不相容的配置
对于任何被集群的cache,你必须删除、disable、或者编辑那些在Terracotta集群时不相容的配置元素。被集群的caches有个<terracotta>或者<terracotta clustered=”true”>元素。
下面这些Ehcache配置属性或者元素需要删除或者disable。

  •  DiskStore-related attributes overflowToDisk and diskPersistent .

Terracotta 服务器自动提供一个磁盘储存。

  •   Replication-related configuration elements, such as <cacheManagerPeerProviderFactory>, <cacheManagerPeerListenerFactory>, <bootstrapCacheLoaderFactory>, <cacheEventListenerFactory>.

当一个变化发生在Terracotta集群的时候,所以包含变化元素和对象的节点都会更新。 Unlike the replication methods used to cluster Ehcache, cache event listeners are not (and do not need to be) notified of remote changes. Listeners are still aware of local changes.

  •    Replication-related attributes such as replicateAsynchronously and replicatePuts .

MemoryStoreEvictionPolicy属性需要被设置成LFU或者LRU。设置MemoryStoreEvictionPolicy为FIFO将会引起IllegalArgumentException错误。

可以查看Ehcache documentation 得到更多标准的配置关于Ehcache。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics