推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
josephok
V2EX  ›  Python

测试了一下 requests 的效率

  •  
  •   josephok · Feb 7, 2015 · 3538 views
    This topic created in 4183 days ago, the information mentioned may be changed or developed.
    9 replies    2015-02-10 10:27:38 +08:00
    invite
        1
    invite  
       Feb 7, 2015
    单线程的时候,没有对比的?

    比如用wget单个单个的下,看看耗时多少。

    而且,测一次很明显不能排除耗时是否由网络引起或者对方服务器引起。
    leyle
        2
    leyle  
       Feb 7, 2015
    看了你的文章了,你的结论是什么?
    leyle
        3
    leyle  
       Feb 7, 2015
    @leyle 可以得出的一个结论是,在 python 编写的程序中,I/O bound 型应用,使用多线程能大大提高效率。
    lincanbin
        4
    lincanbin  
       Feb 7, 2015
    干扰变量没有控制,测试准确性存疑。
    我觉得你可以通过有线网络访问内网一台Web服务器进行抓取,这样的结果所受干扰变量较少。
    a2z
        5
    a2z  
       Feb 7, 2015
    我自己的测试是multiprocessing最快,gevent其次,threading有时候还不如单线程快……
    VYSE
        6
    VYSE  
       Feb 8, 2015 via Android
    gevent改成grequest再测
    ffffwh
        7
    ffffwh  
       Feb 8, 2015
    这gevent靠谱么。。有试过手写回调的方案么。

    可能单线程异步会稍微慢一点,弄2~3个应该差不多(线程数=c)。但I/O Bound用同步多线程(线程数=n)绝对是不好的。
    josephok
        8
    josephok  
    OP
       Feb 10, 2015
    @leyle 嗯 看了你的文章: http://www.leyle.com/archives/threading_and_queue.html 改天研究一下你的代码。
    leyle
        9
    leyle  
       Feb 10, 2015
    @josephok 哈哈,互相交流哈。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5909 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 75ms · UTC 03:28 · PVG 11:28 · LAX 20:28 · JFK 23:28
    ♥ Do have faith in what you're doing.