我有基于Flask的简单应用程序,MariaDB作为数据库。 它与uwsgi一起运行 processes = 4 线程= 100 和unix socket,如前端是configure nginx。
首先,我曾经使用sqlite,之后我转移到了MySQL,我在使用ab进行测试时遇到了错误,例如使用concurence请求:
ab -n 10 -c 2 "http://my_host:80/"
我收到的错误如下:
fails ( UWSGI hang with error)
le "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 42, in defaulterrorhandler
raise errorvalue
OperationalError: (_mysql_exceptions.OperationalError) (2006, 'MySQL server has gone away') [SQL: u'SELECT model.id AS model_id, model.name AS model_name, model.age AS model_age, district.name AS district_name, image.filename AS image_filename \nFROM model INNER JOIN district ON model.district = district.id INNER JOIN image ON model.id = image.model_id GROUP BY model.id \n LIMIT %s'] [parameters: (5,)]
运行良好。
ab -n 10000 -c 1 "http://my_host:80/"
伙计们,请问,我做错了什么?缺少哪部分配置?
UPD: 我进入db_session进入路线:
@app.route('/')
def show_models():
db_session = Session()
userList = db_session.query(Model.id, Model.name, Model.age, District.name, Image.filename).\
join(District, Model.district == District.id).\
join(Image, Model.id == Image.model_id).group_by(Model.id).limit(5).all()
return render_template('show_models.html', models=userList)
并开始出现如下错误:
File "/usr/lib/python2.7/site-packages/sqlalchemy/pool.py", line 1131, in _do_get
(self.size(), self.overflow(), self._timeout))
TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30
之后我在这里添加了 db_session.close()
看起来好像已经解决了!
ab -n 100 -c 100 "http://my_host:80/"
Complete requests: 100
Failed requests: 0
Write errors: 0
UPD2:
我在这里也添加了: db_session.close()
我得到了:
Concurrency Level: 100
Time taken for tests: 2916.838 seconds
Complete requests: 500000
Failed requests: 7
(Connect: 0, Receive: 0, Length: 7, Exceptions: 0)
Write errors: 0
Non-2xx responses: 7
一些错误与MySQL有关"超过最大连接数"