当前位置: 首页 > 知识库问答 >
问题:

分布式缓存- Terracotta

严昀
2023-03-14

我正在使用ehcache(2.10.1)和terracotta(开源4.3.1)实现分布式缓存。我在单台机器上尝试了两个JVM实例和一个terracotta服务器,代码按预期工作,没有错误。

现在,我尝试运行相同的terracotta服务器,但在虚拟机上使用客户端。在虚拟机上运行客户端时,会收到以下消息和错误:

2016-02-23 14:27:10,943  INFO TerracottaClient:209 - Thread [main] [cacheManager: no name]: Creating new ClusteredInstanceFactory
2016-02-23 14:27:10,954  WARN TerracottaClusteredInstanceHelper:148 - ehcache-terracotta jar is detected in the current classpath. The use of ehcache-terracotta jar is no longer needed in this version of Ehcache.

2016-02-23 14:27:11,241 INFO - Terracotta 4.3.1, as of 20151016-121959 (Revision 26592 from 4.3.1)
2016-02-23 14:27:12,177 INFO - Successfully loaded base configuration from server at 'A.B.C.D:9510'.

2016-02-23 14:27:12,222 INFO - Log file: '/root/terracotta/client-logs/terracotta-client.log'.

2016-02-23 14:27:18,202 INFO - Connection successfully established to server at A.B.C.D:9510
2016-02-23 14:27:24,731  INFO AnnotationSizeOfFilter:53 - Using regular expression provided through VM argument net.sf.ehcache.pool.sizeof.ignore.pattern for IgnoreSizeOf annotation : ^.*cache\..*IgnoreSizeOf$

Exception in thread "main" net.sf.ehcache.CacheException: Unable to load class net.sf.ehcache.terracotta.StandaloneTerracottaClusteredInstanceFactory. Initial cause was org.terracotta.toolkit.ToolkitInstantiationException: java.lang.RuntimeException: Unable to create toolkit.
    at net.sf.ehcache.util.ClassLoaderUtil.createNewInstance(ClassLoaderUtil.java:90)
    at net.sf.ehcache.terracotta.TerracottaClusteredInstanceHelper.newClusteredInstanceFactory(TerracottaClusteredInstanceHelper.java:157)
    at net.sf.ehcache.terracotta.TerracottaClient.createNewClusteredInstanceFactory(TerracottaClient.java:180)
    at net.sf.ehcache.terracotta.TerracottaClient.createClusteredInstanceFactory(TerracottaClient.java:129)
    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:463)
    at net.sf.ehcache.CacheManager.init(CacheManager.java:395)
    at net.sf.ehcache.CacheManager.<init>(CacheManager.java:295)
    at com.cisco.dcextract.ExtractCache.main(ExtractCache.java:13)

使用的 tc-config.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<con:tc-config xmlns:con="http://www.terracotta.org/config">
  <servers>
    <server host="A.B.C.D" name="tcservername" >
      <data>c:\datacache</data>
      <tsa-port>9510</tsa-port>
      <jmx-port>9520</jmx-port>
    <tsa-group-port>9530</tsa-group-port>
    <offheap>
              <enabled>true</enabled>
              <maxDataSize>2g</maxDataSize>
     </offheap>
      <logs>terracotta/server-logs</logs>
     </server>
    <update-check>
      <enabled>true</enabled>
    </update-check>
  </servers>
  <clients>
    <logs>terracotta/client-logs</logs>
  </clients>  
</con:tc-config>

使用的 ehcache.xml 文件:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd"
             updateCheck="true" monitoring="autodetect">
             <terracottaConfig url="A.B.C.D:9510" />

   <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            diskSpoolBufferSizeMB="30"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />

    <cache name="cache1290"
           maxElementsInMemory="1000000"
           eternal="false"
           overflowToDisk="false"
           diskSpoolBufferSizeMB="20"
           timeToIdleSeconds="100"
           timeToLiveSeconds="100"
           memoryStoreEvictionPolicy="LRU">
    <terracotta/> 
     </cache>
</ehcache>

在客户机上运行程序时,我包含了terracotta-toolkit-runtime-4.3.1.jar

日志文件内容(仅添加相关部分)

2016-02-25 15:37:28,852 [main] INFO com.terracottatech.console - Connection successfully established to server at 173.39.65.73:9510

2016-02-25 15:37:28,852 [WorkerThread(client_coordination_stage, 0)] INFO com.tc.object.RemoteServerMapManager - ClientID[6]: Sending outstanding servermap requests, num msgs: 0

2016-02-25 15:37:28,853 [main] INFO com.terracottatech.tsa - Connection successfully established to server at 173.39.65.73:9510

2016-02-25 15:37:28,853 [WorkerThread(client_coordination_stage, 0)] INFO com.tc.management.remote.protocol.terracotta.TunnelingEventHandler - Client JMX server ready; sending notification to L2 server

2016-02-25 15:37:28,853 [WorkerThread(client_coordination_stage, 0)] INFO com.tc.platform.rejoin.RejoinManagerImpl - This node joined the cluster - rejoinEnabled: false newNodeId: ClientID[6]

2016-02-25 15:37:28,855 [WorkerThread(client_coordination_stage, 0)] INFO com.tc.cluster.DsoClusterImpl - NODE_JOINED ClientID[6] rejoinHappened false

2016-02-25 15:37:33,417 [main] INFO com.tc.management.remote.protocol.terracotta.TunneledDomainManager - Sending current registered tunneled domains to L2 server to set up the tunneled connections for the mbeans that match.

2016-02-25 15:37:34,553 [L1 VM Shutdown Hook] INFO com.terracottatech.tsa - Running L1 VM shutdown hook

2016-02-25 15:37:34,553 [L1 VM Shutdown Hook] INFO com.terracottatech.tsa - shuting down Terracotta Client hook=true force=false

2016-02-25 15:37:34,553 [L1 VM Shutdown Hook] INFO com.terracotta.toolkit.factory.impl.ToolkitNotifierFactoryImpl - Shutting Down Notifier Thread Pool
2016-02-25 15:37:34,554 [CommonShutDownHook] INFO com.terracottatech.tsa - L1 Exiting...
2016-02-25 15:37:34,789 [L1 VM Shutdown Hook] INFO com.tc.object.tx.RemoteTransactionManagerImpl - ClientID[6]: stop(): took 0 millis to complete
2016-02-25 15:37:34,790 [L1 VM Shutdown Hook] INFO com.tc.net.protocol.transport.ConnectionHealthCheckerImpl: DSO Client - Connection to [dhcp-173-39-65-73.cisco.com:9510] CLOSED. Health Monitoring for this node is now disabled.
2016-02-25 15:37:34,790 [L1 VM Shutdown Hook] INFO com.tc.net.protocol.transport.ClientConnectionEstablisher - waiting for connection establisher to finish null
2016-02-25 15:37:34,790 [L1 VM Shutdown Hook] INFO com.tc.platform.rejoin.ClientChannelEventController - Got channel event - type: CHANNEL_CLOSED_EVENT, event: com.tc.net.protocol.tcm.ChannelEventImpl@1768481525[type = CHANNEL_CLOSED_EVENT, timestamp = Thu Feb 25 15:37:34 IST 2016, channel  = ChannelID[NULL_ID, Status:CLOSED]:10.197.70.109:35582 <--> 173.39.65.73:9510 remote node  : GroupID[0]

共有2个答案

仲孙奇
2023-03-14

我有同样的问题,它通过添加来解决:

    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-terracotta</artifactId>
        <version>2.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.terracotta</groupId>
        <artifactId>terracotta-toolkit-runtime-ee</artifactId>
        <version>4.1.1</version>
    </dependency>

回购协议:

<repositories>
    <repository>
        <id>terracotta-repository</id>
        <url>http://www.terracotta.org/download/reflector/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
松铭
2023-03-14

这个问题应该是由于缺少依赖项或版本不匹配。我也面临同样的问题,通过在下面添加依赖项组合来解决它。

<dependencies>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-core</artifactId>
        <version>2.5.6</version>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-terracotta</artifactId>
        <version>2.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.terracotta</groupId>
        <artifactId>terracotta-toolkit-1.5-runtime</artifactId>
        <version>4.5.0</version>
    </dependency>
    <dependency>
        <groupId>org.terracotta</groupId>
        <artifactId>terracotta-toolkit-runtime</artifactId>
        <version>4.3.2</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>terracotta-repository</id>
        <url>http://www.terracotta.org/download/reflector/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
 类似资料:
  • Web 应用程序可能需要为成百上千甚至更多的用户同时提供服务。如果你没有采取必要的措施,在这种负载下,你的网站可能会崩溃或变得没有响应。 假设在主页显示最后 10 条新闻,并且平均每分钟有上千名用户访问此页面。你可能为每个用户通过查询数据库来显示页面视图信息: SELECT TOP 10 Title, NewsDate, Subject, Body FROM News ORDER BY NewsD

  • 问题内容: 我正在寻找Java分布式缓存解决方案。我们希望功能喜欢: 我们已经分析了Terracotta这样的框架,它似乎是缓存框架中我们想要的一切……但是,似乎需要一个中央缓存节点,这成为我们的单点故障。 除了推出我们自己的解决方案之外,还有其他想法吗? 问题答案: 我建议使用JBossCache或EhCache(使用分布式缓存侦听器)。我都用过,我都喜欢,它们都适合您的要求。

  • [命名空间: Serenity.Caching, 程序集: Serenity.Caching.Couchbase] Redis 是另一种内存数据库,由于其优秀的性能和可靠性, StackOverflow 也在使用它,他们所有的 WEB 服务只用了一个 Redis 数据库。 你可以从 Serenity.Caching.Redis 的 NuGet 程序包获取该服务类型的 Serenity 实现。 它可

  • [命名空间: Serenity.Caching, 程序集: Serenity.Caching.Couchbase] Couchbase 是一个分布式数据库,有像 Memcached 的访问接口。 可以从 NuGet 程序包 Serenity.Caching.Couchbase 获取 Serenity 对此服务类型的实现。 一旦你使用服务定位器注册它: Dependency.Resolve<IDep

  • [命名空间: Serenity.Abstractions, 程序集: Serenity.Core] 如果你现在不需要分布式缓存,但希望现在编写的代码在将来可以与分布式缓存一起工作,你可以使用 DistributedCacheEmulator 类。 DistributedCacheEmulator 也对单元测试和部署环境非常有用(因此,开发人员不需要访问分布式缓存系统而不会影响彼此的工作)。 Dis

  • 现在假设我们有一个社交网站,有数以百万的用户简介,一些著名用户的简介页面每分钟有数百或数千人访问。 要生成一个用户简介,需要多个 SQL 查询(朋友、相册名称及照片总数、简介信息、最后状态等)。 只要用户没有更新个人资料,在个人资料页显示的信息几乎是静态的。因此,个人资料页的快照可以缓存 5 分钟或 1 小时等。 但这或许还不够。我们正在谈论数以百万的简介和用户。用户不会只查看一些简介页。我们需要