gpt4 book ai didi

javascript - 对集群和子进程的工作方式感到困惑

转载 作者:搜寻专家 更新时间:2023-11-01 00:34:40 24 4
gpt4 key购买 nike

我在 Electron 申请中使用了子进程。我只在前一个子进程结束后才 fork 子进程。而且如果我 fork 多个进程,它也不会提高速度。

那么我可以在 electron 应用程序中使用 cluster 模块同时 fork 多个子进程。

let doneFunction = {}
let queue = createQueue(1);
this.state.files.forEach((file, i) => {
queue.defer(function(details, done) {
readSizeRecursive(details.path, e); // inside that i forked child
doneFunction = done;
}, file);
});

childFinished = () => {
doneFunction()
}

我之前问过Child process maximum limit但我无法回答。

  1. 如果我 fork 两个集群方式,我 fork 两个子进程方式,每个子进程在两个不同的集群中并行运行?

最佳答案

And also if I fork multiple processes, it won't increase the speed.

要提高速度,您需要加快磁盘 IO 瓶颈(目录大小计算等)。 CPU 比磁盘 IO 快得多,因此多/单线程/进程无关紧要。

if I forked two cluster means, and I fork two child process means, each child runs parallel in two different clusters?

是的,但它不会像上面提到的那样加快你的最终结果

关于javascript - 对集群和子进程的工作方式感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56948862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com