请教下 nodejs 程序的占用 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
jqtmviyu683
V2EX    Node.js

请教下 nodejs 程序的占用

  •  
  •   jqtmviyu683 2023-03-24 17:45:54 +08:00 2151 次点击
    这是一个创建于 939 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近重拾 nodejs, 照抄了个简单的签到程序, 挂在服务器上用, 使用 pm2 启动, 但发现为啥内存占用那么高 就这和 hello word 一样简单的代码, 显示内存占用 63.6mb, 到底是我写的问题, 还是什么原因. 看了眼 docker 里跑的其他几个签到服务, 大多在十几 M 左右, 用 chatgpt 把这段代码转下, 同样用 pm2 启动, 也是占用非常少.

    const schedule = require('node-schedule') const axios = require('axios') const profiles = require('./config') const getNowTime = () => { return new Date()['toLocaleDateString']() } const request = () => { profiles.forEach(async item => { const {url, headers} = item console.log(`\n\n------${getNowTime()} - ${url}:开始签到------\n`) const res = await axios({ url, method: 'post', headers, }) if (res && res.data) { console.log(`------ ${getNowTime()} 签到成功 ------\n`) console.log(JSON.stringify(res.data)) } else { console.log(`------ ${getNowTime()} 签到失败 ------\n`) console.log(res) } }) } const checkin = () => { schedule.scheduleJob('0 0 7 * * *', () => { setTimeout(() => { request() }, Math.random() * 10 * 60 * 1000) }) } console.log(`开始执行任务-${getNowTime()}`) checkin() 
    jqtmviyu683
        1
    jqtmviyu683  
    OP
       2023-03-24 17:56:31 +08:00
    发完就发现自己写了个 bug, 不该用 forEach 的
    jqtmviyu683
        2
    jqtmviyu683  
    OP
       2023-03-24 19:43:18 +08:00
    感觉自己犯蠢了, 写个最简单的 setInterval + console.log()不就可以验证了吗?
    51.9mb

    v8.getHeapStatistics() 打印

    {
    total_heap_size: 7430144,
    total_heap_size_executable: 524288,
    total_physical_size: 6549504,
    total_available_size: 4339934392,
    used_heap_size: 4521952,
    heap_size_limit: 4345298944,
    malloced_memory: 139368,
    peak_malloced_memory: 246160,
    does_zap_garbage: 0,
    number_of_native_contexts: 1,
    number_of_detached_contexts: 0,
    total_global_handles_size: 8192,
    used_global_handles_size: 2368,
    external_memory: 408283
    }
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2487 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 05:36 PVG 13:36 LAX 22:36 JFK 01:36
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86