基准瓶和烧瓶 - 出了什么问题?

时间:2015-01-03 05:47:23

标签: python performance flask bottle

我正在尝试对瓶子和瓶子进行基准测试以做出一些新的项目决定。我看到瓶子惨不忍睹,而烧瓶似乎有效。我无法相信这些框架相距甚远(是吗?!)。我猜我做的事情既简单又错误。我完全弄不清楚原因。

客户端

第一步我尝试使用Wrk作为生成负载的客户端进行基准测试。我的Wrk cmdline看起来像这样

./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

烧瓶

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

Flask服务器

#!/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安装)。

抓住我的头!

1 个答案:

答案 0 :(得分:5)

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

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

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