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

一个非常奇怪的问题, supervisord 启动的用 aiohttp 发请求的爬虫同时发 10 万请求的情况下有大约 30%的请求会无法解析域名,而在 bash 中手动运行则没有这个问题, Google 上没找到一个类似情况的

  •  
  •   edis0n0 · Nov 21, 2022 · 3566 views
    This topic created in 1442 days ago, the information mentioned may be changed or developed.

    这是 supervisor 的配置:

    [program:watchdog]
    command=python3.9 /app/watchdog/wd.py
    directory=/app/watchdog/
    user=root
    autorestart=true
    redirect_stderr=true
    stdout_logfile=/var/log/watchdog.log
    loglevel=info
    startsecs = 20
    

    程序的代码涉及比较复杂的业务逻辑暂时没办法发出来。

    有什么办法排查吗?

    17 replies  •  2022-11-22 11:52:11 +08:00
    eason1874
    eason1874
    Nov 21, 2022
    1
    盲猜 DNS 缓存问题,bash 环境有缓存,而 aiohttp 没有缓存
    pcbl
    pcbl
    Nov 21, 2022 via Android❤️2
    2
    类似的毛病我遇到过自己排查分析了好几天才搞定

    楼主试着把 supervisor 中文件打开数限制调大应该可以解决。
    edis0n0
    edis0n0
    OP
    Nov 21, 2022
    3
    @eason1874 #1 bash 还能缓存 python 脚本解析的域名吗?是在 bash 中手动用 python3.9 命令运行同一个脚本,一点问题都没有,supervisor 运行的 python3.9 5 分钟就几十万条报错
    guanzhangzhang
    guanzhangzhang
    Nov 21, 2022❤️1
    4
    systemd 的 limit file 和 supervisor 你的 program 的 file open 啥的都加大一些试试
    edis0n0
    edis0n0
    OP
    Nov 21, 2022
    5
    @pcbl #2 真的是这问题,解决了,牛逼
    edis0n0
    edis0n0
    OP
    Nov 21, 2022
    6
    就加了一行 minfds = 655350 然后重启 supervisor 服务
    edis0n0
    edis0n0
    OP
    Nov 21, 2022
    7
    昨天排查了一整天都没解决
    liuzhedash
    liuzhedash
    Nov 21, 2022
    8
    @guanzhangzhang
    细说下其中道理?
    我和 1 楼猜的是一样的,但是看起来并不是缓存的问题。
    guanzhangzhang
    guanzhangzhang
    Nov 21, 2022
    9
    @liuzhedash supervisor 这种肯定不会缓存的,因为 dns 缓存都是 glibc 或者 java 的 runtime 有参数决定的,手动 run 没问题,放 supervisor 纳管就有问题明显就是 fd 相关的。例如很多小白 mysql 用 systemd 纳管,写了个很简单的 systemd.service 文件,systemd 的默认 fd 是 4096 ,会导致 mysql 效率不行
    edis0n0
    edis0n0
    OP
    Nov 21, 2022
    10
    @guanzhangzhang #9 手动 run 的话有缓存吗?直接改 fd 让程序跑起来会不会影响性能?
    edis0n0
    edis0n0
    OP
    Nov 21, 2022
    11
    我们没有专业运维搞不定,数据库用的都是各大云厂商的云数据库服务
    guanzhangzhang
    guanzhangzhang
    Nov 21, 2022
    12
    @edis0n0 你可以搜下 关于 limits 生效的四个案例 ,用户和纳管的进程是不一样的
    ClericPy
    ClericPy
    Nov 21, 2022
    14
    ulimit -n 开到百万, 然后 aiohttp 里 HTTP 适配器那俩 limit 也改大点
    julyclyde
    julyclyde
    Nov 22, 2022❤️1
    15
    wliansheng
    wliansheng
    Nov 22, 2022
    16
    @julyclyde 使用 supervisord ,我也遇到这个问题,不用这个那么用什么啊?
    julyclyde
    julyclyde
    Nov 22, 2022
    17
    @wliansheng 建议托管给 systemd ,并在单一的位置(即 systemd service unit file )集中声明程序运行所需的环境
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1301 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 21:41 · PVG 05:41 · LAX 13:41 · JFK 16:41
    ♥ Do have faith in what you're doing.