推荐学习书目
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
tihiro
V2EX  ›  Python

请教下各位用 tornado 框架的开发,耗时任务直接扔协程里面去做就行了还是用 Celery 处理呢?

  •  
  •   tihiro · Mar 12, 2019 · 2853 views
    This topic created in 2629 days ago, the information mentioned may be changed or developed.
    7 replies    2019-03-17 20:14:48 +08:00
    shallyy
        1
    shallyy  
       Mar 12, 2019
    后者
    neoblackcap
        2
    neoblackcap  
       Mar 12, 2019
    耗时任务分两种,CPU 密集型,IO 密集型。你网络请求放在 Handler 里面做没问题,记得用 Tornado 自带的 Http Client。

    Tornado 是一个高性能网络框架,不过究其根本其实还是封装了事件循环,因此你要运用非堵塞 IO 处理才能算是正确发挥它的功效。任何堵塞操作(包括在主线程读写数据库,读写文件,CPU 密集型操作)都会带来悲剧
    tihiro
        3
    tihiro  
    OP
       Mar 12, 2019
    谢谢你的回答,但是我想知道为什么,利弊有哪些呢?
    a852695
        4
    a852695  
       Mar 12, 2019
    还是看你任务类型吧,celery 效率比较低
    cs8814336
        5
    cs8814336  
       Mar 13, 2019
    我理解你的协程是 tornado 进程里面的程序的协程吧. 这个问题当然是你能多进程多协程比多进程或者多线程号,所以能协程你就扔协程, 但是你说用 celery 其实还是一个队列解耦的一个好东西 . 要我选就选解耦微服务, 否则后面扩展很难
    cs8814336
        6
    cs8814336  
       Mar 13, 2019   ❤️ 1
    celery 也可以用协程 gevent 的, 所以其实你这 2 个感觉不能这么比着选
    zhze93
        7
    zhze93  
       Mar 17, 2019
    我之前做的时候,直接放在 celery 里做的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2847 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 466ea39e · 43ms · UTC 06:02 · PVG 14:02 · LAX 23:02 · JFK 02:02
    ♥ Do have faith in what you're doing.