我在nodejs中有一个抓取算法,其中puppeteer同时刮擦5个页面,当它完成一个页面时,它从队列中拉出下一个url并在同一页面中打开它.CPU始终为100%.如何让puppeteer使用更少的CPU?
此过程在具有4gb RAM和2个vCPU的digitaloceans droplet上运行.
我用一些args启动了puppeteer实例,试图让它更轻但没有任何反应
puppeteer.launch({
args: ['--no-sandbox', "--disable-accelerated-2d-canvas","--disable-gpu"],
headless: true,
});
Run Code Online (Sandbox Code Playgroud)
我可以提供任何其他args以减少CPU饥饿吗?
我也阻止了图片加载
await page.setRequestInterception(true);
page.on('request', request => {
if (request.resourceType().toUpperCase() === 'IMAGE')
request.abort();
else
request.continue();
});
Run Code Online (Sandbox Code Playgroud) 我试图以headless:false模式启动人偶。它在我的本地计算机上运行,但是当我将其推送到服务器并尝试启动它时,出现此错误:
4|scraperP | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
4|scraperP | Error: Failed to launch chrome!
4|scraperP | [0620/073557.986542:ERROR:nacl_helper_linux.cc(310)] NaCl helper process running without a sandbox!
4|scraperP | Most likely you need to configure your SUID sandbox correctly
4|scraperP | TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
4|scraperP | at onClose (/home/pjotr/scrapermmcreation/node_modules/puppeteer/lib/Launcher.js:285:14)
4|scraperP | at Interface.helper.addEventListener (/home/pjotr/scrapermmcreation/node_modules/puppeteer/lib/Launcher.js:274:50)
4|scraperP | at Interface.emit (events.js:165:20)
4|scraperP | at Interface.close (readline.js:381:8)
4|scraperP | at Socket.onend (readline.js:154:10)
4|scraperP | at Socket.emit (events.js:165:20) …Run Code Online (Sandbox Code Playgroud) 我有一个带有promise的函数,每次都必须使用不同的params执行n次.我想以一种方式链接承诺,即脚本当时总是处理3-4个承诺.
我用promise.all做了它,它同时执行3个,当所有的promises结算时,它继续下一个3.
如何使其工作,当3中的一个解决它立即与另一个开始,但总是在当时最大3工作?
for( var i = 0; i < tasks.length; i++){
if( i > 0 && i%3 == 0 ){
await Promise.all([
doTaskFunction(tasks[i]),
doTaskFunction(tasks[i-1]),
doTaskFunction(tasks[i-2]),
]);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使两个异步调用同时运行并等待它们完成Promise.all。如何Promise.all在 Node.js 的 es6 中使用 async/await 返回多个值?我希望我能在外面看到分配的变量。这段代码是错误的,但代表了我所需要的。
Promise.all([
var rowA = await buildRow(example, countries),
var rowM = await buildRow(example, countries)
])
console.log(rowA+rowB)
Run Code Online (Sandbox Code Playgroud)
有没有办法查看范围之外的这些变量?
node.js ×4
headless ×2
javascript ×2
puppeteer ×2
concurrency ×1
cpu-usage ×1
es6-promise ×1
promise ×1