【问题标题】:gunicorn spawn workers in host and container as wellgunicorn 在主机和容器中生成工人
【发布时间】:2021-01-19 15:55:27
【问题描述】:

我正在尝试在以nginx 作为反向代理的服务器上部署带有fastapi 和docker 的api。 这是我的 Dockerfile:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.6

RUN mkdir /srv/app

ENV SEGPKG=/srv/app
COPY . $SEGPKG
WORKDIR /srv/app

RUN pip install --upgrade pip --proxy my_proxy --trusted-host pypi.python.org

RUN pip install -e $SEGPKG --proxy my_proxy

EXPOSE 80
CMD ["gunicorn","--timeout","90","--log-level","error", "--reload", "-b", "0.0.0.0:80","--worker-class=uvicorn.workers.UvicornH11Worker", "--workers=24", "app.main:app"]

一切都由docker-compose 处理。我的服务器上已经安装了 Nginx。 部署没问题:我可以访问我的 api,发出请求并收到响应。

昨天,我在我的 linux centos 服务器上运行了top,我看到了这个:

  3369 root      20   0  582388 338624   6016 S   0.7  1.0   0:46.62 gunicorn
  3389 root      20   0  582388 338460   5792 S   0.7  1.0   0:46.40 gunicorn
  3382 root      20   0  582388 338428   5800 S   0.7  1.0   0:46.45 gunicorn
  3356 root      20   0  582392 338408   5788 S   0.7  1.0   0:46.24 gunicorn
  3355 root      20   0  582392 338400   5788 S   0.3  1.0   0:46.86 gunicorn
  3424 root      20   0  582392 338388   5792 S   0.3  1.0   0:45.80 gunicorn
  3344 root      20   0  582392 338384   5796 S   0.7  1.0   0:46.26 gunicorn
  3413 root      20   0  582392 338384   5788 S   0.3  1.0   0:46.52 gunicorn
  3341 root      20   0  582404 338376   5836 S   0.3  1.0   0:46.10 gunicorn
  3348 root      20   0  582392 338372   5792 S   0.7  1.0   0:46.38 gunicorn
  3402 root      20   0  582392 338360   5788 S   0.7  1.0   0:46.15 gunicorn
  3401 root      20   0  582392 338344   5796 S   0.3  1.0   0:46.24 gunicorn
  3422 root      20   0  582392 338344   5788 S   0.3  1.0   0:46.75 gunicorn
  3351 root      20   0  582392 338336   5788 S   1.0  1.0   0:46.47 gunicorn
  3359 root      20   0  582392 338316   5788 S   0.7  1.0   0:46.48 gunicorn
  3399 root      20   0  582388 338312   5788 S   0.3  1.0   0:46.01 gunicorn
  3408 root      20   0  582392 338312   5788 S   0.7  1.0   0:46.38 gunicorn
  3421 root      20   0  582392 338312   5788 S   0.3  1.0   0:46.08 gunicorn
  3343 root      20   0  582396 338304   5812 S   0.7  1.0   0:45.97 gunicorn
  3360 root      20   0  582392 338296   5788 S   0.7  1.0   0:46.43 gunicorn
  3397 root      20   0  582388 338288   5788 S   0.3  1.0   0:46.49 gunicorn
  3425 root      20   0  582392 338260   5792 S   0.3  1.0   0:46.42 gunicorn
  3345 root      20   0  582392 338204   5792 S   0.7  1.0   0:45.63 gunicorn
  3353 root      20   0  582392 338160   5788 S   0.7  1.0   0:46.59 gunicorn

然后我去了为服务这个 api 而创建的 docker 容器并运行 top

 1 root      20   0   36000  23116   5092 S   0.0   0.1   0:01.32 gunicorn
 8 root      20   0  582404 338376   5836 S   0.0   1.0   0:47.97 gunicorn
10 root      20   0  582396 338304   5812 S   0.0   1.0   0:47.91 gunicorn
11 root      20   0  582392 338384   5796 S   0.0   1.0   0:48.17 gunicorn
12 root      20   0  582392 338204   5792 S   0.0   1.0   0:47.55 gunicorn
15 root      20   0  582392 338372   5792 S   0.0   1.0   0:48.25 gunicorn
18 root      20   0  582392 338336   5788 S   0.0   1.0   0:48.35 gunicorn
20 root      20   0  582392 338160   5788 S   0.0   1.0   0:48.52 gunicorn
22 root      20   0  582392 338400   5788 S   0.0   1.0   0:48.77 gunicorn
23 root      20   0  582392 338408   5788 S   0.0   1.0   0:48.19 gunicorn
26 root      20   0  582392 338316   5788 S   0.0   1.0   0:48.36 gunicorn
27 root      20   0  582392 338296   5788 S   0.0   1.0   0:48.33 gunicorn
36 root      20   0  582388 338624   6016 S   0.0   1.0   0:48.51 gunicorn
43 root      20   0  582388 338428   5800 S   0.0   1.0   0:48.34 gunicorn
48 root      20   0  582388 338460   5792 S   0.0   1.0   0:48.31 gunicorn
53 root      20   0  582388 338288   5788 S   0.0   1.0   0:48.38 gunicorn
54 root      20   0  582388 338312   5788 S   0.0   1.0   0:47.92 gunicorn
56 root      20   0  582392 338344   5796 S   0.0   1.0   0:48.14 gunicorn
57 root      20   0  582392 338360   5788 S   0.0   1.0   0:48.07 gunicorn
63 root      20   0  582392 338312   5788 S   0.0   1.0   0:48.27 gunicorn
68 root      20   0  582392 338384   5788 S   0.0   1.0   0:48.46 gunicorn
75 root      20   0  582392 338312   5788 S   0.0   1.0   0:48.01 gunicorn
76 root      20   0  582392 338344   5788 S   0.0   1.0   0:48.68 gunicorn
78 root      20   0  582392 338388   5792 S   0.0   1.0   0:47.71 gunicorn
79 root      20   0  582392 338260   5792 S   0.0   1.0   0:48.35 gunicorn

Gunicorn 仅供此应用程序使用。 我真的不明白。

gunicorn master 似乎在主机和 docker 容器中生成工人? 这对我来说没有意义。

如果我错了,解释一下会很有帮助。

谢谢

【问题讨论】:

    标签: docker gunicorn fastapi


    【解决方案1】:

    不是Linux专家,但我很好奇,发现这个SO question,与gunicorn无关,但仍然是关于主机中显示的docker处理。

    基本上就是这样。 Docker 不是虚拟机,容器进程由主机的相同操作系统/内核运行,因此在那里可见。

    【讨论】:

    • 是的,这就是答案。我用 ps 传真进行了检查,确实它们是容器的孩子。完全愚蠢的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 2021-03-11
    • 1970-01-01
    相关资源
    最近更新 更多