multithreading - 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();
})();
解决方案
推荐阅读
- r - CRAN R - 电子邮件验证器
- mysql - SET NAMES 和 SET CHARSET 的区别
- python - Maya - 在未捕获的异常上自动运行功能
- api - 如何使用 API 调用在 Jfrog X-Ray 中创建策略
- python - 无法在 TensorFlow 1.10 的 IndyLSTMCell 中使用 relu 激活
- javascript - OpenLayers:绘制多边形和点然后拖动它们
- maven - 从 Atlassian Bamboo 构建时的 Maven 问题
- bash - 将表示十六进制值的 ascii 转换为二进制数据
- c++ - 为什么 c++ 函数可以正确返回数组的大小?
- flutter - 我想知道我的截图中的视图