Reputation: 77
I am using flask-sqlalchemy library in python to management my database(my sql). However when I test query, it give me this error:
sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 10
Test code is simple:
def test_query(self, i):
random = str(i)
result = Dao.query_user_by_nick("kael")
print("end query at %s, id: %s" % (datetime.datetime.now(), random), "\n result: " + str(len(result)))
threads = []
for i in range(0,100):
test = threading.Thread(target=test_query, args=(self, str(i)))
threads.append(test)
for t in threads:
t.start()
The implement of query_user_by_nick is:
@classmethod
def query_user_by_nick(self,name):
user = User.query.filter_by(nick_name=name).all()
return user
When I running the query in multi-thread, this error will always always happen, and I have no idea why it will be. I also insert some data in multi-thread and it works fine. I searched around and nothing inspired me. Someone said the connection will be limited to 15, but this database will be query very frequently and can not be just like 15 query at some time or similar. I am happy if anyone could give me any suggestion. Thanks in advance.
Upvotes: 1
Views: 2815
Reputation: 2173
If you think your database can handle it, you should be able to increase the SQLAlchemy pool settings via http://flask-sqlalchemy.pocoo.org/2.1/config/ :
Upvotes: 4