【问题标题】:Timeout in grails application with memcached(ElastiCache) on heavy load and big cache files在重负载和大缓存文件上使用 memcached(ElastiCache) 的 grails 应用程序超时
【发布时间】:2015-02-20 19:45:31
【问题描述】:

我有一个 grails 应用程序,它始终使用 memcached 来存储请求结果。

在缓存中存储的结果很小 (100kb) 的请求适用于 50K 请求,但在一种情况下,当结果大约为 800kb 时,应用程序会在每分钟有超过 1K 的请求时抛出异常。

我在过去两天试图解决这个问题,但所有答案都没有定论。我开始认为问题可能出在 ElastiCache 上。

对于实施,我使用 AWS ElastiCache 集群客户端,即 spymemcached 的一个分支。

我尝试修复将客户端更改为默认 spymemcached 和 xmemcached 但错误相同。

异常是:java.util.concurrent.ExecutionException: net.spy.memcached.internal.CheckedOperationTimeoutException: 操作超时。

我的服务实现:

import net.spy.memcached.*
import grails.converters.JSON
import org.springframework.beans.factory.InitializingBean

class MemCacheService implements InitializingBean {

    String ELASTIC_CACHE_CLUSTER_IP = "teste.ptsfty.cfg.use1.cache.amazonaws.com";
    def ELASTIC_CACHE_CLUSTER_PORT = 11211
    def MemcachedClient client
    def expireTime = 21600

    def void afterPropertiesSet() {
        client = new MemcachedClient(new InetSocketAddress(ELASTIC_CACHE_CLUSTER_IP, ELASTIC_CACHE_CLUSTER_PORT));
    }

    def getDataOnCache(key) {
        try {
            def result = client.get(key)
            if (result) return JSON.parse(result)
            else return  null
        } catch(Exception e) {
            println e.getMessage()
            return null
        } 
    }

    def saveOnCache(key, value) {
        try {
            def result = client.add(key, expireTime, value);
            return result
        } catch(Exception e) {
            println e.getMessage()
            return null
        }

    }

    def removeOnCache(key) {
        def result = client.delete(key);
        return result
    }


}

【问题讨论】:

    标签: grails memcached spymemcached


    【解决方案1】:

    如果 Elasticache 随着连接数的增加而停止工作,请尝试增加 memcached_connections_overhead 参数。您的 Elasticache 实例可能内存不足,无法处理传入连接。每个实例使用少量内存来处理每个连接,并且该参数通常具有较低的默认值。

    【讨论】:

    • 嗨,卡洛斯。感谢帮助。我更改了 ElastiCache 上的配置,但错误并没有停止。
    • 在日志中是否有此问题的迹象?
    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 2015-12-03
    • 2013-02-26
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 2015-07-09
    • 2012-02-03
    相关资源
    最近更新 更多