【问题标题】:Ehcache write-behind caching thread-priorityEhcache 后写缓存线程优先级
【发布时间】:2011-06-23 21:44:31
【问题描述】:

我正在尝试使用 Ehcache 后写缓存将批量事务写入我的数据库。我需要的是后写缓存以 5 秒间隔(或更频繁)转储事务。

我一定是遗漏了一些东西,因为尽我所能,它就是行不通。我设置了后写缓存,然后将负载放到服务器上。几千,再后来几十万的交易,等了几分钟,数据库里还是什么都没有。直到我关闭服务器上的负载,缓存才开始写入数据库。

这是线程优先级的问题吗?有没有办法修改 Ehcache 以在服务器负载下执行 DB 写入?

这是我的配置:

<cache name="server.db.model.Request"
 maxElementsInMemory="10000"
 eternal="false"
 timeToIdleSeconds="5"
 timeToLiveSeconds="5"
 overflowToDisk="false"
 memoryStoreEvictionPolicy="FIFO">
    <cacheWriter writeMode="write_behind" maxWriteDelay="5" rateLimitPerSecond="5"
     writeCoalescing="true" writeBatching="true" writeBatchSize="5000"
     retryAttempts="2" retryAttemptDelaySeconds="10">
        <cacheWriterFactory class="server.db.util.RequestCacheWriterFactory"/> 
    </cacheWriter>
</cache>

谢谢。

【问题讨论】:

    标签: java hibernate ehcache


    【解决方案1】:

    嗯……这真的很奇怪。我们一直在进行广泛的测试,并且从未体验过编写器线程从未获得 CPU 时间。你在运行什么操作系统?创建 CacheManager 的线程是否以较低的优先级运行?

    另外,很抱歉可能会问一些显而易见的问题,但是当您说“关闭”负载时,这是什么意思?不关闭应用程序(和 CacheManager)?基本上我要问的是“事务分界确实发生在 writeAll/deleteAll 方法中,对吧?”…

    还有最后一点,因为这是用休眠标记的,所以您没有在休眠二级缓存上配置后写,对吗?那只是一个错误的标签,不是吗?

    【讨论】:

    • 这是在 Linux/Tomcat 环境中。我们没有在任何地方明确设置线程优先级。通过关闭负载,我的意思是我关闭了用于访问服务器的 jMeter 线程。最后,根据此处的 ehcache 文档:ehcache.org/documentation/hibernate.html,我们正在使用休眠。奇怪的是,即使在我关闭服务器上的负载之后,我也必须再等 5 分钟左右才能开始写入数据库。感谢您的帮助。
    • 我很困惑,所以 server.db.model.Request 保存休眠数据?我的意思是您知道您不应该将 ehcache write-behind 与休眠缓存一起使用,对吗?另外,你用的是什么版本?这也是 ehcache 独立的,对吗?不是兵马俑聚集...
    【解决方案2】:

    最后,将我的配置更改为这个是有效的 - 尽管我仍然不确定哪个参数更改产生了影响。

    <cache name="server.db.model.Request"
      maxElementsInMemory="10000" 
      maxElementsOnDisk="0"
      eternal="false"
      timeToIdleSeconds="5"
      timeToLiveSeconds="5">
          <cacheWriter writeMode="write_behind" maxWriteDelay="5" 
            writeCoalescing="false" writeBatching="true" writeBatchSize="5000"
            retryAttempts="2" retryAttemptDelaySeconds="10"
            notifyListenersOnException="false" writeBehindMaxQueueSize="10000" 
            writeBehindConcurrency="10" >
             <cacheWriterFactory class="server.db.util.RequestCacheWriterFactory" />
          </cacheWriter>
    </cache>
    

    【讨论】:

      猜你喜欢
      • 2011-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多