Choosing DB pool_size for a Flask-SQLAlchemy app running on Gunicorn : <p>I have a Flask-SQLAlchmey app running in Gunicorn connected to a PostgreSQL database, and I'm having trouble finding out what the <code>pool_size</code> value should be and how many database connections I should expect.</p>

<p>This is my understanding of how things work:</p>

<ul>
<li>Processes in Python 3.7 DON'T share memory</li>
<li>Each Gunicorn worker is it's own process</li>
<li>Therefore, each Gunicorn worker will get it's own copy of the database connection pool and it won't be shared with any other worker</li>
<li>Threads in Python DO share memory</li>
<li>Therefore, any threads within a Gunicorn worker WILL share a database connection pool</li>
</ul>

<p>Is that correct so far? If that is correct, then for a synchronous Flask app running in Gunicorn: </p>

<ul>
<li>Is the maximum number of database connections = (number of workers) * (number of threads per worker)?</li>
<li>And within a worker, will it ever use more connections from a pool than there are workers?</li>
</ul>

<p>Is there a reason why <code>pool_size</code> should be larger than the number of threads? So, for a gunicorn app launched with <code>gunicorn --workers=5 --threads=2 main:app</code> should <code>pool_size</code> be 2? And if I am only using workers, and not using threads, is there any reason to have a <code>pool_size</code> greater than 1?</p>
