Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 mc.get 的时候出现 heap out of memory 错误 #10

Open
whxaxes opened this issue Jan 5, 2017 · 5 comments
Open

使用 mc.get 的时候出现 heap out of memory 错误 #10

whxaxes opened this issue Jan 5, 2017 · 5 comments

Comments

@whxaxes
Copy link

whxaxes commented Jan 5, 2017

如图:
image

缓存的数据是一大段 json 字符串,大小为 5KB ,使用了 yield mc.get 就会抛出以上错误,如果不使用 yield 就不会抛出异常,能正常取到数据。

@fengmk2
Copy link
Member

fengmk2 commented Jan 5, 2017

具体的使用代码是怎样的?

@fengmk2
Copy link
Member

fengmk2 commented Jan 5, 2017

你截图明显是内存爆了。

@whxaxes
Copy link
Author

whxaxes commented Jan 6, 2017

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。

@JacksonTian
Copy link

把coredump文件发给我 帮你分析下吧。这样看代码 不行的。

@ghost
Copy link

ghost commented Sep 12, 2017

经测试内容在3K以上都会出现这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants