[英]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 服务器的稳定性有点不确定,所以我正在评估这三个选项:
Questions:问题:
Flask vs Bottle comes down to a couple of things for me. Flask vs Bottle 对我来说归结为几件事。
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.要处理该限制,您可以不按特定顺序执行以下任何操作。
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.