使用 mc.get 的时候出现 heap out of memory 错误
whxaxes opened this issue · comments
吖猩 commented
fengmk2 commented
具体的使用代码是怎样的?
fengmk2 commented
你截图明显是内存爆了。
吖猩 commented
extend context
mcCache(key, handle, time = 5 * 60000) {
if (typeof key !== 'string') {
throw new Error('key must be string');
}
key = key.replace(/\s/g, '_'); // 替换非法字符
return co(this.mc.get(key)).then(res => {
if (res) {
this.app.logger.debug(`${key} has cache: ${res}`);
return Promise.resolve(res);
} else {
return Promise.reject();
}
}).catch(() => {
return co.apply(this, [handle]).then(res => {
if (res && (!res.error || !_.isError(res.error))) {
try {
const resString = (typeof res === 'object') ? JSON.stringify(res) : res;
this.mcSet(key, resString + '', time);
} catch (e) {
this.app.logger.error(e);
}
}
return Promise.resolve(res);
});
});
},
router
const result = yield this.mcCache(
`pinyin_${pinyin}`,
function* test() {
const result = yield this.proxy.xxx.getXXX({
args: pinyin,
});
return result;
}
);
返回的数据量大小就是一个接口响应的 json 数据,数据量为 5KB。
Jackson Tian commented
把coredump文件发给我 帮你分析下吧。这样看代码 不行的。
Deleted user commented
经测试内容在3K以上都会出现这个问题