使用Nginx和uWSGI的多个服务器进程 [英] Multiple server processes using nginx and uWSGI

查看:476
本文介绍了使用Nginx和uWSGI的多个服务器进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到您可以在nginx后面的一个uWSGI实例中启动多个进程:

I've noticed that you can start multiple processes within one uWSGI instance behind nginx:

uwsgi --processes 4 --socket /tmp/uwsgi.sock

或者您可以在不同的套接字上启动多个uWSGI实例,并使用nginx在它们之间进行负载平衡:

Or you can start multiple uWSGI instances on different sockets and load balance between them using nginx:

upstream my_servers {
    server unix:///tmp.uwsgi1.sock;
    server unix:///tmp.uwsgi2.sock;
    #...
}

这两种策略之间有什么区别,一种优先于另一种?

What is the difference between these 2 strategies and is one preferred over the other?

nginx(在第一种情况下)进行的负载平衡与uWSGI(在第二种情况下)进行的负载平衡有何不同?

How does load balancing done by nginx (in the first case) differ from load balancing done by uWSGI (in the second case)?

nginx可以在多个主机上管理服务器. uWSGI可以在单个实例中执行此操作吗?某些uWSGI功能仅在单个uWSGI进程(即共享内存/缓存)中起作用吗?如果是这样,可能很难从第一种方法扩展到第二种方法....

nginx can front servers on multiple hosts. Can uWSGI do this within a single instance? Do certain uWSGI features only work within a single uWSGI process (ie. shared memory/cache)? If so it might be difficult to scale from the first approach to the second one....

推荐答案

区别在于,对于uWSGI,没有真正的"负载平衡.第一个自由进程将始终响应,因此,此方法比在多个实例之间进行nginx负载平衡要好得多(显然,这仅适用于本地实例).您需要考虑的是雷群问题".它的含义在这里公开: http://uwsgi-docs.readthedocs.org/en/latest/article/SerializingAccept.html .

The difference is that in the case of uWSGI there is no "real" load balancing. The first free process will always respond, so this approach is way better than having nginx load balacing between multiple instances (this is obviously true only for local instances). What you need to take in account is the "thundering herd problem". Its implications are exposed here: http://uwsgi-docs.readthedocs.org/en/latest/articles/SerializingAccept.html.

最后,所有uWSGI功能都支持多线程/多进程(和绿线程),因此所有进程都共享缓存(例如).

Finally, all of the uWSGI features are multithread/multiprocess (and greenthreads) aware so the caching (for example) is shared by all processes.

这篇关于使用Nginx和uWSGI的多个服务器进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆