V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
helloriver952
V2EX  ›  问与答

nodejs 写的后端 常驻内存(Rss)慢慢增长很高 请问一下如何排查是什么出了问题呢

  •  1
     
  •   helloriver952 · 2022-11-04 16:14:10 +08:00 · 2696 次点击
    这是一个创建于 536 天前的主题,其中的信息可能已经有所发展或是发生改变。

    内存监控图片

    11 条回复    2022-12-15 18:01:21 +08:00
    nomagick
        1
    nomagick  
       2022-11-04 16:15:37 +08:00
    正常的,v8 不愿意把内存释放给操作系统,倾向于自己管理,这有个上限,默认是不到 2G 来着
    jchnxu
        2
    jchnxu  
       2022-11-04 16:19:05 +08:00
    snapshot 一下,看哪些对象没有被释放?
    helloriver952
        3
    helloriver952  
    OP
       2022-11-04 16:41:54 +08:00
    @nomagick 有没有办法让他释放呢,一个服务器部署许多个程序,不释放掉太卡了。
    尝试使用了 jemalloc 好像没什么用,不知道是不是姿势不对 我看 node 下边有 issue 通过 jemalloc 解决了此问题
    helloriver952
        4
    helloriver952  
    OP
       2022-11-04 16:44:11 +08:00
    @jchnxu 堆内存 189.38M ,应该不是程序内变量没有释放
    nomagick
        5
    nomagick  
       2022-11-04 16:56:52 +08:00
    设置一下--max-old-space-size ,再不行就是 c++世界什么地方泄漏了,检查一下有没有用原生库之类的
    helloriver952
        6
    helloriver952  
    OP
       2022-11-04 17:42:54 +08:00
    @nomagick 谢谢 确实用到了 一些 c 和 c++的库 通过 child_process 调用的 我仔细排查一下
    qfdk
        7
    qfdk  
       2022-11-04 20:18:52 +08:00 via iPhone
    干啥的啊 是不是有定时任务? 网络请求? graphql 这样的东西 fetch ?
    gen900
        8
    gen900  
       2022-11-05 09:30:58 +08:00 via iPhone
    去掉怀疑的模块,一个个试。看内存有没有降下来
    helloriver952
        9
    helloriver952  
    OP
       2022-11-07 09:28:12 +08:00
    @gen900 目前我在这样做呢
    helloriver952
        10
    helloriver952  
    OP
       2022-11-07 09:30:13 +08:00
    @qfdk 应该不是吧
    helloriver952
        11
    helloriver952  
    OP
       2022-12-15 18:01:21 +08:00
    经过排查最终发现是 node-canvas 的问题 可能是 c++内存泄露 https://github.com/Automattic/node-canvas/issues/1974 目前未得到解决
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1443 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:52 · PVG 07:52 · LAX 16:52 · JFK 19:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.