How to create a multithreaded application on Flask + SQLAlchemy?

Doing my first large application in Python: Flask + SQL Alchemy
The database is MySQL.

The point is that inside the app, you can create jobs. Each job runs in a multithreaded mode.
Inside each thread there is a lot of readings and record in database.

The problem is that for a sufficiently large number of thread (50+) MySQL just dies.
The important point is that each task runs in a separate process. Inside the process has already created threads.
I can't figure out exactly where the bottleneck is. Are simple operations to read / write data. The data volumes are not large.
Guided by its past extensive experience in PHP, I know that MySQL should be easy to withstand such loads.

Configure SQL Alchemy:

Create the db object:
db = SQLAlchemy(app)

Then I import and use in other scripts.

It seems to me that not correctly I do in some places.
For example, I need in real time to make the increment value in the database. This is the only working version of the code:
task = Task.query.filter_by(
db.session.query(Task).filter_by({'progress': task.progress + 1})

Key question: how correctly to organize work with a similar application on SQL Alchemy?
How to use session? And is it possible to track the time source and create a large load on MySQL?
The server is extremely powerful and is not a bottleneck. Can be specific MySQL configuration?
July 4th 19 at 22:54
0 answer

Find more questions by tags FlaskMySQL