gpt4 book ai didi

python - Scrapy download_delay 与 max_concurrent_requests_per_domain

转载 作者:太空狗 更新时间:2023-10-30 01:33:55 25 4
gpt4 key购买 nike

我对 Scrapy 中 DOWNLOAD_DELAYMAX_CONCURRENT_REQUESTS_PER_DOMAIN 之间的区别和交互感到很困惑。

下载延迟是否会影响每个域的最大并发请求数,例如,如果我将延迟设置为 10 秒但允许每个域有 8 个并发请求,这些并发请求是否不会同时触发,而是根据下载延迟交错,还是它们会同时被解雇但响应的下载会错开? DOWNLOAD_DELAY 没有被称为 REQUEST_DELAY 有什么原因吗?

例如,在以下场景中,粗略的吞吐量计算是什么:

  • start_urls 拥有给定域的 100 个 URL
  • MAX_CONCURRENT_REQUESTS_PER_DOMAIN = 8
  • DOWNLOAD_DELAY = 3
  • 假设服务器需要 2 秒来生成响应
  • 假设我们生成的 URL 不会超过 start_urls
  • 中已有的 URL

关联的爬虫处理这个队列需要多长时间?

最佳答案

来自下载器source代码

conc = self.ip_concurrency if self.ip_concurrency else self.domain_concurrency
conc, delay = _get_concurrency_delay(conc, spider, self.settings)

因此看起来行为与 this 相同,它说

This setting also affects DOWNLOAD_DELAY: if CONCURRENT_REQUESTS_PER_IP is non-zero, download delay is enforced per IP, not per domain.

所以我认为您不会通过较大的 download_delay 实现很多并发。我在具有自动节流功能的慢速网络上运行爬虫,一次并发请求不超过 2-3 个。

关于python - Scrapy download_delay 与 max_concurrent_requests_per_domain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27736162/

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