hi: 请教个问题:
我们在用 resty.lock 结合 lua_shared_dict 做 缓存层。
在压测中 发现了如下的报错:
2015/12/10 04:52:17 [crit] 27554#0: ngx_slab_alloc() failed: no memory
2015/12/10 04:53:15 [crit] 27554#0: ngx_slab_alloc() failed: no memory
问题是 我从redis取出来的 数据只有几个字节, 但是我 声明的时候 是100k : lua_shared_dict my_locks 100k;
报错的次数不多, 大概50万次请求出现了 8次。
是因为在缓存过期的时候,大量的锁申请导致的内存不足吗?
下面是核心代码:
local lock_c = {}
local lock_cf = require "lock_cache_config"
local resty_lock = require "resty.lock"
local lock = resty_lock:new("my_locks", lock_cf)
local cache = ngx.shared.share_mem
function lock_c.get(key, dynamic_fun_hash, params_obj, exp_time)
local value = cache:get(key)
if value then
return value
end
local elapsed, err = lock:lock(key)
if not elapsed then
return nil
end
value = cache:get(key)
if value then
lock:unlock()
return value
end
value = dynamic_fun_hash.get_data(params_obj)
if value then
cache:set(key, value, exp_time)
end
lock:unlock()
return value
end
return lock_c