【问题标题】:benchmarking bottle and flask - what is wrong?基准瓶和烧瓶 - 有什么问题?
【发布时间】:2015-03-04 11:04:34
【问题描述】:

我正在尝试对烧瓶和瓶子进行基准测试,以做出一些新的项目决策。我看到瓶子惨遭失败,而烧瓶似乎可以工作。我不敢相信这些框架相距甚远(是吗?!)。我想我在做一些简单而错误的事情。我完全不知道为什么。

客户

第一步我尝试使用Wrk 作为客户端来生成负载进行基准测试。我的 Wrk 命令行如下所示

./wrk -c 20 -d 30 -t 10 --latency http://localhost:8888/hello/world

瓶子

Bottle 示例服务器如下所示

#!/usr/bin/env python

from bottle import route, run, template

@route('/hello/<name>')
def index(name):
        return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8888)

基准测试的输出是

Running 30s test @ http://localhost:8888/hello/world
  10 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     6.07s     4.44s   13.38s    55.49%
    Req/Sec   184.27    311.26     1.33k    73.56%
  Latency Distribution
     50%    7.29s 
     75%    7.42s 
     90%   13.38s 
     99%   13.38s 
  34208 requests in 30.02s, 5.61MB read
  Socket errors: connect 0, read 0, write 0, timeout 177
Requests/sec:   1139.47
Transfer/sec:    191.40KB

我在服务器日志上看到一大堆错误(我猜与超时有关)

Exception happened during processing of request from ('127.0.0.1', 56893)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

烧瓶

现在我用烧瓶重复了同样的测试

烧瓶服务器

#!/usr/bin/env python

from flask import Flask
app = Flask(__name__)

@app.route("/hello/<name>")
def hello(name):
        return "Hello {0}!".format(name)

if __name__ == "__main__":
    app.run(port=8888)

现在是运行的输出

Running 30s test @ http://localhost:8888/hello/world
  10 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    10.83ms  691.95us  22.49ms   93.54%
    Req/Sec   187.71     22.99   285.00     83.73%
  Latency Distribution
     50%   10.74ms
     75%   11.02ms
     90%   11.42ms
     99%   12.52ms
  55203 requests in 30.00s, 8.69MB read
Requests/sec:   1840.00
Transfer/sec:    296.48KB

这看起来更“正常”。我在我的笔记本电脑(i5/8G/Mint)上执行此操作。无需特殊安装任何一个框架(pip install)。

在这个问题上挠头!

【问题讨论】:

  • 我对瓶子不熟悉,但你可以尝试在 127.0.0.1 而不是 localhost 上运行服务器
  • 我的主机文件有 127.0.0.1 映射到本地主机。使用 IP 会有什么不同?顺便说一句,尝试了它并没有改善。

标签: python performance flask bottle


【解决方案1】:

Flask 和 Bottle 都是 WSGI 应用框架;它们让您通过 WSGI 协议构建 Web 应用程序。

为了让您更轻松地开发代码,这两个框架都带有内置的基本 WSGI 服务器,因此您无需安装单独的东西来测试您的代码。然而,这两种服务器都不适合生产使用;例如,其中一个原因是它们不是为重载而设置的。

我怀疑您想测试框架 的堆叠方式,而不是它们的基本开发服务器。使用正确的WSGI deployment 来测试框架,并确保对两个框架使用相同的配置。注意不要最终测试容器(服务器)处理负载的能力。

【讨论】:

    猜你喜欢
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多