hyj1991/v8-profiler-next

process memory is larger than 1G, cpu is 100% immediately

sahalazj-github opened this issue · 3 comments

process memory is larger than 1G, cpu is 100% immediately
const v8Profiler = require('v8-profiler-next')
const generateVmHeapsnapshot = (options, callback) => {
    try {
        const { cupFilePath } = options
        console.log('EnterGenerateSnapshot', cupFilePath)
        const snapshot = v8Profiler.takeSnapshot()

        console.log('AfterGenerateSnapshot')

        // 1. not as stream
        const file = fs.createWriteStream(cupFilePath);
        const transform = snapshot.export();
        transform.pipe(file);
        transform.on('finish', snapshot.delete.bind(snapshot));

    } catch(e) {
        console.log('GenerateVmHeapsnapshotError', e)
    }
}

这段代码执行完之后,就会看到进程的cpu立即上升到接近100%,这属于正常现象吗?node版本:12.16.1
image

这是正常的,堆快照序列化是一个比较大的开销,等堆快照生成 cpu 会降下来。

相比之下,进程堆内存比较大时,生成的堆快照的体积一般也比较大,且会耗费一定的时间,这个是没问题的。