我写了一个非常简单的烧瓶网络服务,它只是在被点击并托管在AWS EC2 t2.micro机器(1GB RAM 1CPU)上时返回文本hey23
为了执行这个python应用程序,我使用uwsgi作为我的app服务器。最后,我将我的完整设置置于Nginx之后。
所以我的筹码是Flask+uwsgi+Nginx
一切都很好,很好。我只对执行时间抱怨。使用wrk测量的平均延迟时间约为370毫秒,考虑到此服务正在进行的工作量,这太多了。
Running 30s test @ http://XX.XXX.XX.XX/printtest
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 370.98ms 178.90ms 1.96s 91.78%
Req/Sec 93.72 36.72 270.00 69.55%
33124 requests in 30.11s, 5.41MB read
Socket errors: connect 0, read 0, write 0, timeout 15
Non-2xx or 3xx responses: 1173
Requests/sec: 1100.26
Transfer/sec: 184.14KB
hello-test.py
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route("/print23")
def helloprint():
return "hey23"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, threaded=True)
uwsgi.ini
[uwsgi]
#application's base folder
base = /var/www/demoapp
master = true
#python module to import
app = hello-test
module = %(app)
home = %(base)/venv
pythonpath = %(base)
#socket file's location
socket = /var/www/demoapp/%n.sock
#permissions for the socket file
chmod-socket = 644
#the variable that holds a flask application inside the module imported at line #6
callable = app
disable-logging = True
#location of log files
logto = /var/log/uwsgi/%n.log
max-worker-lifetime = 30
processes = 10
threads = 2
enable-threads = True
cheaper = 2
cheaper-initial = 5
cheaper-step = 1
cheaper-algo = spare
cheaper-overload = 5
即使我忘记了wrk基准测试,即使发布了来自POSTMAN client的GET请求,我也会遇到类似的延迟。
这里有什么问题?无论如何,一些外卖
hey23
字符串。
Nginx没有任何问题。然后我错过了什么?