V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
woostundy
V2EX  ›  Python

Python 2.7 Gunicorn + Flask,有大量的第三方服务 http 请求, requests 库阻塞导致出现性能瓶颈

  •  3
     
  •   woostundy · 2017-08-15 17:48:12 +08:00 · 14663 次点击
    这是一个创建于 2443 天前的主题,其中的信息可能已经有所发展或是发生改变。
    该怎么优化呢?异步 http 客户端的库哪个比较靠谱?
    第 1 条附言  ·  2017-08-16 17:49:17 +08:00
    多谢各位帮忙,我觉得有必要重新描述一下问题:
    现在有服务 A 和服务 B,服务 A 有一部分数据库读写操作,同时每次都会通过 requests 访问服务 B (每次都只会访问一次,B 服务性能完全足够)
    服务 A 的结构是 Flask + Gunicorn + Gevent,当 A 服务器 QPS 到 50 时,数据库访问没有压力,但会出现 requests 到服务 B 的速度变慢甚至超时。

    不是 A 一次请求内多次请求 B 服务,而是每次 A 都会请求一次 B,所以设置 session 共享 tcp 连接( keep-alive )应该是无效的。
    101 条回复    2017-08-26 13:08:33 +08:00
    1  2  
    justff
        101
    justff  
       2017-08-26 13:08:33 +08:00 via Android
    同意楼上 加上 io 密集条件更接近实战
    1  2  
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5385 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 05:51 · PVG 13:51 · LAX 22:51 · JFK 01:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.