在测试flask程序时,出现异常
sqlalchemy session pool over flow
第一次见到问题,手工操作无法重现。
在网上查到有类似的处理
In multi-thread mode, if your concurrent request num is much more than the db connection pool size, it will throw the Queue Pool limit of size 5 overflow 10 reached error. try with this:
engine = create_engine('mysql://', convert_unicode=True,
pool_size=20, max_overflow=100)
to add the pool size
Add: the method above is not a correct way. The actual reason is that db connection pool is used up, and no other available connection. The most probably situation is you miss to release connection. For example:
参考网上资料,自己用locust做大量连接测试,重现一次,从运行记录看,似乎和发生了异常有关。
为了确认,专门做了一个函数,这个函数什么也不做,只是抛出异常。结果,locust只是执行了几
十次连接以后,就开始重现前面所说的session poll异常。非常准确。
问题清楚了,剩下的事情变得简单。把after_req