简体   繁体   English

Python Bottle vs uwsgi/bottle vs nginx/uwsgi/bottle

[英]Python bottle vs uwsgi/bottle vs nginx/uwsgi/bottle

I am developing a Python based application (HTTP -- REST or jsonrpc interface) that will be used in a production automated testing environment.我正在开发将在生产自动化测试环境中使用的基于 Python 的应用程序(HTTP -- REST 或 jsonrpc 接口)。 This will connect to a Java client that runs all the test scripts.这将连接到运行所有测试脚本的 Java 客户端。 Ie, no need for human access (except for testing the app itself).即,不需要人工访问(除了测试应用程序本身)。

We hope to deploy this on Raspberry Pi's, so I want it to be relatively fast and have a small footprint.我们希望将其部署在 Raspberry Pi 上,因此我希望它相对快速且占用空间小。 It probably won't get an enormous number of requests (at max load, maybe a few per second), but it should be able to run and remain stable over a long time period.它可能不会收到大量请求(在最大负载下,可能每秒几个),但它应该能够运行并在很长一段时间内保持稳定。

I've settled on Bottle as a framework due to its simplicity (one file).由于 Bottle 的简单性(一个文件),我已经将它作为一个框架。 This was a tossup vs Flask.这是对 Flask 的折腾。 Anybody who thinks Flask might be better, let me know why.任何认为 Flask 可能更好的人,请告诉我原因。

I have been a bit unsure about the stability of Bottle's built-in HTTP server, so I'm evaluating these three options:我对 Bottle 内置 HTTP 服务器的稳定性有点不确定,所以我正在评估这三个选项:

  1. Use Bottle only -- As http server + App仅使用 Bottle -- 作为 http 服务器 + 应用程序
  2. Use Bottle on top of uwsgi -- Use uwsgi as the HTTP server在 uwsgi 之上使用 Bottle -- 使用 uwsgi 作为 HTTP 服务器
  3. Use Bottle with nginx/uwsgi将 Bottle 与 nginx/uwsgi 一起使用

Questions:问题:

  • If I am not doing anything but Python/uwsgi, is there any reason to add nginx to the mix?如果我除了 Python/uwsgi 什么都不做,是否有任何理由将 nginx 添加到组合中?
  • Would the uwsgi/bottle (or Flask) combination be considered production-ready? uwsgi/bottle(或 Flask)组合会被认为是生产就绪的吗?
  • Is it likely that I will gain anything by using a separate HTTP server from Bottle's built-in one?通过使用与 Bottle 内置服务器不同的 HTTP 服务器,我是否可能会有所收获?

Flask vs Bottle comes down to a couple of things for me. Flask vs Bottle 对我来说归结为几件事。

  1. How simple is the app.该应用程序多么简单。 If it is very simple, then bottle is my choice.如果简单,那么瓶子就是我的选择。 If not, then I got with Flask.如果没有,那么我得到了 Flask。 The fact that bottle is a single file makes it incredibly simple to deploy with by just including the file in our source.瓶子是单个文件的事实使得部署变得非常简单,只需将文件包含在我们的源代码中即可。 But the fact that bottle is a single file should be a pretty good indication that it does not implement the full wsgi spec and all of its edge cases.但是,bottle 是单个文件这一事实应该很好地表明它没有实现完整的 wsgi 规范及其所有边缘情况。
  2. What does the app do.应用程序有什么作用。 If it is going to have to render anything other than Python->JSON then I go with Flask for its built in support of Jinja2.如果它必须渲染 Python->JSON 以外的任何东西,那么我会选择 Flask,因为它内置了对 Jinja2 的支持。 If I need to do authentication and/or authorization then Flask has some pretty good extensions already for handling those requirements.如果我需要进行身份验证和/或授权,那么 Flask 已经有一些非常好的扩展来处理这些要求。 If I need to do caching, again, Flask-Cache exists and does a pretty good job with minimal setup.如果我需要做缓存,同样,Flask-Cache 存在并且在最少的设置下做得非常好。 I am not entirely sure what is available for bottle extension-wise, so that may still be worth a look.我不完全确定有什么可用于瓶子扩展,所以这可能仍然值得一看。

The problem with using bottle's built in server is that it will be single process / single thread which means you can only handle processing one request at a time.使用 Bottle 内置服务器的问题在于它将是单进程/单线程,这意味着您一次只能处理一个请求。

To deal with that limitation you can do any of the following in no particular order.要处理该限制,您可以不按特定顺序执行以下任何操作。

  1. Eventlet's wsgi wrapping the bottle.app (single threaded, non-blocking I/O, single process) Eventlet 的 wsgi 包装了 Bottle.app(单线程、非阻塞 I/O、单进程)
  2. uwsgi or gunicorn (the latter being simpler) which is most ofter set up as single threaded, multi-process (workers) uwsgi 或 gunicorn(后者更简单),最常设置为单线程、多进程(工人)
  3. nginx in front of uwsgi. uwsgi 前面的 nginx。

3 is most important if you have static assets you want to serve up as you can serve those with nginx directly.如果您想要提供静态资产,那么 3 是最重要的,因为您可以直接使用 nginx 提供这些资产。
2 is really easy to get going (esp. gunicorn) - though I use uwsgi most of the time because it has more configurability to handle some things that I want. 2 真的很容易上手(尤其是 gunicorn)——尽管我大部分时间都使用 uwsgi,因为它具有更多的可配置性来处理我想要的一些事情。
1 is really simple and performs well... plus there is no external configuration or command line flags to remember. 1 真的很简单,性能也很好……而且不需要记住外部配置或命令行标志。

2017 UPDATE - We now use Falcon instead of Bottle 2017 年更新 - 我们现在使用 Falcon 而不是 Bottle

I still love Bottle, but we reached a point last year where it couldn't scale to meet our performance requirements (100k requests/sec at <100ms).我仍然喜欢 Bottle,但去年我们达到了无法扩展以满足我们的性能要求(100k 请求/秒 <100 毫秒)的地步。 In particular, we hit a performance bottleneck with Bottle's use of thread-local storage.特别是,我们遇到了 Bottle 使用线程本地存储的性能瓶颈。 This forced us to switch to Falcon , and we haven't looked back since.这迫使我们改用Falcon ,此后我们再也没有回头。 Better performance and a nicely designed API.更好的性能和设计精美的 API。

I like Bottle but I also highly recommend Falcon , especially where performance matters.我喜欢 Bottle,但我也强烈推荐Falcon ,尤其是在性能很重要的地方。


I faced a similar choice about a year ago--needed a web microframework for a server tier I was building out.大约一年前,我面临类似的选择——需要一个 Web 微框架用于我正在构建的服务器层。 Found these slides (and the accompanying lecture) to be very helpful in sifting through the field of choices: Web micro-framework BATTLE!发现这些幻灯片(以及随附的讲座)对筛选选择领域非常有帮助: Web 微框架 BATTLE!

I chose Bottle and have been very happy with it.我选择了 Bottle,对它非常满意。 It's simple, lightweight (a plus if you're deploying on Raspberry Pis), easy to use, intuitive, has the features I need, and has been supremely extensible whenever I've needed to add features of my own.它简单、轻量级(如果您在 Raspberry Pi 上部署则是加分项)、易于使用、直观、具有我需要的功能,并且在我需要添加自己的功能时都具有极高的可扩展性。 Many plugins are available.许多插件可用。

Don't use Bottle's built-in HTTP server for anything but dev.不要将 Bottle 的内置 HTTP 服务器用于除开发之外的任何内容。

I've run Bottle in production with a lot of success;我在生产中运行 Bottle 并取得了很大的成功; it's been very stable on Apache/mod_wsgi.它在 Apache/mod_wsgi 上非常稳定。 nginx/uwsgi "should" work similarly but I don't have experience with it. nginx/uwsgi“应该”类似地工作,但我没有经验。

I also suggest you look at running bottle via gevent.pywsgi server.我还建议您通过 gevent.pywsgi 服务器查看运行 Bottle。 It's awesome, super simple to setup, asynchronous, and very fast.它很棒,设置超级简单,异步且非常快。

Plus bottle has an adapter built for it already, so even easier. Plus 瓶子已经为它内置了一个适配器,所以更容易。

I love bottle, and this concept that it is not meant for large projects is ridiculous.我喜欢瓶子,这种不适合大型项目的概念是荒谬的。 It's one of the most efficient and well written frameworks, and can be easily molded without a lot of hand wringing.它是最高效、写得最好的框架之一,并且可以轻松塑造而无需费力费力。

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

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