简体   繁体   English

哪种流行的方法将基于Python的WebApp部署到WebServer?

[英]Which is the more popular way to deploy a Python-based WebApp to a WebServer?

I only known WSGI,FCGI(FastCGI) and uWSGI. 我只知道WSGI,FCGI(FastCGI)和uWSGI。 If you known other,please tell me. 如果您认识其他人,请告诉我。 How the application status of the three way above-mentioned,which is more popular? 以上三种方式的应用状况如何,哪个更受欢迎? Thanks. 谢谢。

You are confusing things. 你使事情变得混乱。

WSGI is an API specification. WSGI是API规范。 It is itself not a way of deploying anything. 它本身不是部署任何东西的方法。 A specific WSGI deployment mechanism would be an implementation of the WSGI specification bridging a Python web application adhering to the WSGI specification to a specific web hosting mechanism. 特定的WSGI部署机制将是WSGI规范的实现,它将遵循WSGI规范的Python Web应用程序桥接到特定的Web托管机制。 This might be where the web application ends up being embedded within the same web server process, or where it communicates with a separate web server over a socket protocol. 这可能是Web应用程序最终嵌入同一Web服务器进程中的地方,或者是通过套接字协议与单独的Web服务器通信的地方。

FASTCGI is one instance of such a socket protocol used to communicate between a web application process and a web server. FASTCGI是此类套接字协议的一个实例,用于在Web应用程序进程和Web服务器之间进行通信。 In the case of Python web applications, flup is one example of an implementation of a WSGI adapter bridging between FASTCGI and a Python web application. 就Python Web应用程序而言,flup是在FASTCGI和Python Web应用程序之间桥接WSGI适配器的一种实现示例。 Another example of a socket protocol is SCGI. 套接字协议的另一个示例是SCGI。

uWSGI is an implementation which is actually an umbrella for hosting web applications in various languages. uWSGI是一种实现,实际上是用于托管各种语言的Web应用程序的保护伞。 It can handle HTTP direct, but normally uses its own socket protocol called uwsgi (lower case) to communicate with a web server. 它可以直接处理HTTP,但通常使用自己的套接字协议uwsgi(小写)与Web服务器通信。 One of the languages it supports via its plugin system is Python and so at that point it serves as an implementation of a WSGI adapter for its uwsgi protocol or HTTP when handling it direct. 它通过其插件系统支持的一种语言是Python,因此,当直接处理它时,它可用作其uwsgi协议或HTTP的WSGI适配器的实现。

As to what you probably intended to be the question, in the Python world the most popular WSGI deployment mechanisms are: 关于您可能想成为的问题,在Python世界中,最流行的WSGI部署机制是:

  • Apache/mod_wsgi 阿帕奇/ mod_wsgi
  • uWSGI uWSGI
  • gunicorn 古尼康

Apache/mod_wsgi is the oldest and well regarded as being rock solid. Apache / mod_wsgi是最古老的,并且被认为是坚如磐石。 Many people don't take the time to learn how to configure Apache properly for Python web applications and so don't get the most out of it, thus leading to a lot of wrong impressions about Apache. 许多人没有花时间学习如何为Python Web应用程序正确配置Apache,因此没有充分利用它,从而导致对Apache产生许多错误印象。 Be very suspicious of people who say Apache is slow and bloated. 对说Apache速度慢且blo肿的人非常怀疑。 This simply shows they never setup Apache properly. 这只是表明他们从未正确设置Apache。 One of the best ways to truly make Apache/mod_wsgi shine is to use it behind nginx. 真正使Apache / mod_wsgi发光的最佳方法之一是在nginx之后使用它。 When using Apache/mod_wsgi, it is always best to use its daemon mode unless you truly know what you are doing. 使用Apache / mod_wsgi时,除非您真正知道自己在做什么,否则始终最好使用其守护程序模式。

The gunicorn server is a pure Python server and so is attractive for that reason. gunicorn服务器是纯Python服务器,因此很有吸引力。 It is limited to single threaded synchronous worker though and doesn't support traditional multithreading. 但是,它仅限于单线程同步工作器,并且不支持传统的多线程。 You therefore have to use multi process configurations which although that has benefits in CPU intensive tasks, for I/O bound tasks as one usually has for web applications means that it can use a lot more memory than a well configured Apache setup using multithreading and multiprocessing. 因此,您必须使用多进程配置,尽管这在处理CPU密集型任务中有好处,但对于I / O绑定任务,就像Web应用程序通常具有的那样,这意味着与使用多线程和多处理的配置良好的Apache设置相比,它可以使用更多的内存。 。 One can also use a couple of couroutine based workers with gunicorn, but you have to be very careful using those and ensure that all your application code and modules you use are greenlet aware and will work with coroutines or you can have problems with single points blocking the whole process from doing anything. 一个人也可以使用几个以couroutine为基础的工作人员使用gunicorn,但是您必须非常小心地使用它们,并确保您使用的所有应用程序代码和模块都对greenlet敏感,并且可以与协程一起使用,否则您可能会遇到单点阻塞问题整个过程无所事事。

Although using nginx in front of Apache/mod_wsgi is a really great combination, most people settle on uWSGI behind nginx. 尽管在Apache / mod_wsgi之前使用nginx是一个非常不错的组合,但是大多数人还是在nginx之后使用uWSGI。 A problem with uWSGI can be that it has too many different ways of setting it up and its defaults aren't the best and you need to make sure certain options are used to make it more robust. uWSGI的一个问题可能是,它有太多不同的设置方式,并且默认设置不是最佳选择,您需要确保使用某些选项来使其更强大。 The uWSGI code based still sees very rapid development and that has been an issue in the past with reliability. 基于uWSGI代码的开发仍然非常迅速,并且过去一直是可靠性问题。 So make sure you aren't using an ancient version that comes with your Linux distribution, make sure you are using a recent version. 因此,请确保您没有使用Linux发行版随附的旧版本,请确保您使用的是最新版本。

As to which is best, when setup properly, the performance differences between each shouldn't be that much. 至于最好的是,在正确设置后,两者之间的性能差异不应该那么大。 The bottlenecks are generally never going to be with the deployment mechanism unless you screwed up their configuration. 除非您搞砸了它们的配置,否则部署机制通常不会遇到瓶颈。 The real bottlenecks will be in your web application, database and backend services. 真正的瓶颈将出现在您的Web应用程序,数据库和后端服务中。

So as a general rule, you are better to select one based on what your system administrators or yourself understand and think you can configure and manage the easiest. 因此,通常,最好根据系统管理员或您自己理解并认为您可以配置和管理最简单的内容来选择一个。 Try and ignore people who religiously try and steer you to their favourite as what may work for them isn't always going to work for you. 试着忽略那些虔诚地试图将您引向他们最喜欢的人,因为可能对他们有用的并不总是对您有用。 For a serious site you need to properly evaluate what is going to be best and then dedicate a proper amount of effort to setting it up properly and not simply throwing it up and hoping for the best. 对于严重的站点,您需要适当地评估什么才是最好的,然后付出适当的努力来正确设置它,而不是简单地将其扔掉并希望得到最好的。

Now I haven't mentioned Tornado so far. 现在到目前为止,我还没有提到龙卷风。 Using WSGI on top of Tornado is not that good of a choice except for specific uses cases due to problems that can arise with running blocking WSGI on top of ASYNC Tornado. 除了特定的用例之外,在Tornado上使用WSGI并不是一个好的选择,这是由于在ASYNC Tornado上运行阻塞WSGI可能会引起问题。 If you want to go with ASYNC APIs though instead of WSGI, then both Tornado and Twisted are reasonable choices. 如果您想使用ASYNC API而不是WSGI,那么Tornado和Twisted都是合理的选择。 Writing to ASYNC APIs can be a lot more complicated though and you have to be careful in some cases with Tornado in particular if doing a lot of uploading of data due to how Tornado buffers request content for requests before it is handled. 但是,写入ASYNC API可能要复杂得多,在某些情况下,使用Tornado时要特别小心,尤其是在进行大量数据上传时,由于Tornado如何在处理请求之前缓冲请求内容。

One final point. 最后一点。 In complicated systems it is entirely possible that you need to use multiple technologies. 在复杂的系统中,您完全有可能需要使用多种技术。 Do not assume you should use one technology for everything. 不要以为您应该对所有事物都使用一种技术。 Using WSGI web frameworks makes web application programming easier but the blocking nature of WSGI is not necessarily suitable for certain highly concurrent long polling type applications. 使用WSGI Web框架使Web应用程序编程更容易,但是WSGI的阻塞性质不一定适合某些高度并发的长轮询类型的应用程序。 You really need therefore to look at what different parts of a web application require and break it up and use appropriate technologies for each part and not just have one huge monolithic application in one technology that tries to do everything. 因此,您确实需要查看Web应用程序的不同部分所需的内容,并将其分解并为每个部分使用适当的技术,而不仅仅是一种试图完成所有工作的技术中只有一个庞大的整体应用程序。

I would rather use Django + mod_wsgi . 我宁愿使用Django + mod_wsgi But another way is to use SSI . 但是另一种方法是使用SSI Just <!--#exec cmd="python script.py" --> 只是<!--#exec cmd="python script.py" -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM