PostgresqlDatabase multithreading performance problem
@coleifer  >but the performance is worse than sequential running. anyone have any ideas?

Python uses a global interpreter lock so only 1 thread is ever executing python code. If your code is CPU-bound then, due to context-switching, you will waste time overall.

You can try using multiple processes to circumvent this issue. Although my job is IO-bound(multi-threading is not a bad choice), I implemented the multi process version too but the problem still persist with peewee then I implemented the function using psycopg2 adapter and the performance became 4 times faster(with multi threading).
@coleifer  Was it also 4x faster single-threaded with psycopg2? No, single-threaded version of psycopg2 almost takes time equal to single-threaded peewee. I made a little script that inserts 100K rows and queries it single-threaded, using 4 threads and 4 processes. The single-thread and 4-thread run about the same, but the multiprocess version runs in about half the time.

The psycopg2-only version is faster, but this is somewhat expected since it carries none of the python-side overhead. It is also marginally faster (10%) when run multi-threaded.

I profiled the code and it looks to me like the bulk of the time in peewee is spent generating sql and serializing result rows to model instances, which is to be expected.
Hello,
I have a postgresql db connection:

```
database = PostgresqlDatabase(config_server['database_name'],
                              **{'host': config_server['host'], 'port': config_server['port'],
                                 'user': config_server['user'],
                                 'password': config_server['password']
                                 })

```
and each thread(4 thread) runs the below function with different date_time parameter, we must run the below function 100 times:

```
def get_estimations_v1(date_time, db) -> pd.DataFrame:
    Estimation._meta.set_table_name('est_' + date_time.strftime("%Y%m%d"))

    try:
        db.connect(reuse_if_open=True)
        query = Estimation.select().where(
            Estimation.date_time.between(date_time - timedelta(minutes=1), date_time))

         estimations = pd.DataFrame(list(query.dicts()))
         return estimations

    except Exception as ce:
        logger.error('load of estimations failed for {}, {}', date_time, str(ce))
        return
    finally:
        db.close()
        return

```
but the performance is worse than sequential running. anyone have any ideas?
