search

Home  >  Q&A  >  body text

python - gunicorn supervisor nginx 配置问题,该给gunicorn几个worker,有没有必要上gevent

配置了一下午环境,跑起来是跑起来了,但是寻摸着一次琢磨透他们嘛。

鉴于gunicorn,supervisor用的不多,网络上找到资料很少(中文)

英文的也有些不太好懂。

想问下gunicorn可以设置worker设置几个比较合适呢。阿里云服务器,双核的。

supervisor是不是也有设置类似worker的地方,配置一下午迷糊了。

nginx呢。
晕乎乎的。

另外gevent不太了解,这个有必要上吗。我看配置起来蛮简单的。有什么优缺点呢。

谢谢各位。

PHPzPHPz2891 days ago494

reply all(4)I'll reply

  • 阿神

    阿神2017-04-18 09:17:36

    Whatever worker还是NginxProcess,都是根据你的服务器的CPU核数决定的,你的阿里云只有双核(2个核)?

    gunicorn不是很了解,uWSGI也有个worker,一般设置成核数X2.

    Nginx据说8One process is enough.

    Search Nginxoptimization online, there should be quite a few tutorials.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:17:36

    About worker这个基本上是建议等于实际CPU核心数的一到两倍,我一般是有几个核,就用几个worker.

    As for the settings of supervisor我好像并没有看到有关worker.

    Actually, I use uwsgi + supervisor + nginx的组合。具体你可以google下,我也只是照着官方wiki to make it, and I don’t use anything fancy.

    PS: Give up the Chinese materials, most of them are in disrepair. Although the English is not easy to read, at least you can’t get into the pit

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:17:36

    1. The number of Gunicorn workers is generally configured from an experience point of view 2 * core + 1, core refers to the number of cores.

    2. Supervisor does not have the concept of configuring the number of workers, but it has the concept of configuring the number of processes, numprocs this field

    3. If you use gunicorn, it is generally recommended to use worker_class 配置成 gevent, you know this.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:17:36

    gunicorn 是常用的 WSGI 服务器,在目前应用中,和 uWSGI 都是比较常用的选择,而两者性能都相差不远。gunicorn 配置的 worker 数量官网的示例值是 2 * cpu数 + 1, official website example

    import multiprocessing
    
    bind = "127.0.0.1:8000"
    workers = multiprocessing.cpu_count() * 2 + 1

    So, for the subject’s dual-core server, it should be set to 5 appropriately.


    And supervisor 是一个进程管理工具,可以用于管理N多的进程,不仅仅是 Gunicorn ,我甚至用来管理 Redis。确实,supervisor 中也存在类似worker数量的东西,叫procs,其实是进程数量,也就是说你配置了几个,supervisor will help you start several processes.

    It should be noted that the workers of supervisorGunicorn are independent. If you set both of them to 5, then there will actually be 5 * 5 = 25 processes providing services.


    nginx is generally used for reverse proxy and load balancing. Suppose you have two web applications running locally on the server:

    • http://127.0.0.1:5000 Blog

    • http://127.0.0.1:8080 Forum

    Then you want to access these two applications separately through domain names, for example

    • http://baidu.com/blog blog

    • http://baidu.com/bss Forum

    Then this can be configured through nginx.


    gevent 是协程的一个库,一般用于 IO密集型 应用,不建议使用。如果是IO密集型 应用,建议使用 Tornado Framework for writing.

    That’s about it. It is recommended to read more official documents.

    reply
    0
  • Cancelreply