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

pymongo+gevent Pool 导致 mongodb 扛不住怎么办?

  •  
  •   SlipStupig · Oct 29, 2016 · 3512 views
    This topic created in 3502 days ago, the information mentioned may be changed or developed.
    pymongo+gevent pool 导致 mongodb 卡死,报了一堆 AutoReconnectError 错误和 connection close ,我 pymongo 的 pool 和 gevent pool 都设置的不大(都为 100 )有什么办法能很好的调控,又还能保证速度呢?
    5 replies    2016-10-30 22:43:34 +08:00
    20150517
        1
    20150517  
       Oct 29, 2016
    你不帖代码怎么看,或许是你的 query 有问题,或者是你的连接没有关闭,可能性太多了
    SlipStupig
        2
    SlipStupig  
    OP
       Oct 30, 2016
    @20150517 代码有点多,基本上就是读取一个地方的数据写到数据库里,在__del__定义了 close ,但是似乎没有作用
    ldbC5uTBj11yaeh5
        3
    ldbC5uTBj11yaeh5  
       Oct 30, 2016   ❤️ 1
    @SlipStupig 大兄弟, 用 __del__ 来实现 RAII 语义,在 python 里面不是正确的姿势。

    正确的做法是使用 with 句式, contextlib 可能是你想要的。 https://docs.python.org/2.7/library/contextlib.html
    SlipStupig
        4
    SlipStupig  
    OP
       Oct 30, 2016
    @jigloo 找到原因了,我用 signal 去关闭的,结果发现官网说的不对,直接 close 就行
    JamesPan
        5
    JamesPan  
       Oct 30, 2016
    这是把 __del__ 当作析构函数来用?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1269 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 17:23 · PVG 01:23 · LAX 10:23 · JFK 13:23
    ♥ Do have faith in what you're doing.