python - 开启猴子补丁后,requests 库在请求时是否是阻塞整个程序的?
高洛峰
高洛峰 2017-04-17 13:49:03
0
1
331

在 v2ex 上提问。有人说使用 Gevent 并开启猴子补丁,如果一个线程阻塞也是会影响整个程序线程的。
但我测试 20 个 get 任务时:

  • 顺序(for 循环)访问约 7 秒
  • 使用 gevent.pool 后,约为 2 秒

但,1000 个任务,使用 多线程明显比多协程快 30% 左右。这是不是因为某个协程的 requests.get 阻塞的整个线程呢?
另问:在做一个线上持续运行的爬虫时,应该如何分配进程、线程、携程才能使带宽、硬件有最佳使用率呢?


条件:python 2.7.8

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
PHPzhong

When there are ten thousand concurrent tasks, the advantages of coroutines are reflected~
Coroutines are not faster than threads, but in ultra-high concurrency situations, they are more stable than multi-threads and account for Few resources.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!