首页 > 解决方案 > puppeteer-cluster 是否使用所有内核?

问题描述

我编写了一个脚本来一次抓取一个页面 60 次。

假设我的服务器能够处理负载,puppeteer-cluster 是否会自动在所有内核之间分配工作负载?

如果不是,那么您建议使用什么方法在所有系统内核之间分配工作负载?

(async () => {
    let threads = 60;
    
    const cluster = await Cluster.launch({
        maxConcurrency: threads,
        timeout: Math.pow(2, 31) - 1,
        concurrency: Cluster.CONCURRENCY_BROWSER,
    });

    const crawl = async ({ page, data: {link} }) => {

        async function crawlPage() {
            // crawl the page
        }
        
        // crawl indefinitly
        do {
            await crawlPage()
        } while (true);
        
    };

    // assume there are 60x of those
    await cluster.queue({link: 'link'}, crawl);
    // ...

    await cluster.idle();
    await cluster.close();

})();

标签: multithreadingweb-scrapingpuppeteerpuppeteer-cluster

解决方案


推荐阅读