7

We're building an ASGI app using fastapi, uvicorn, sqlalchemy and PostgreSQL. The question is: how should we set pool_size in create_async_engine to not make it a bottleneck comparing to a WSGI app with multiple workers?

As far as I understand, in a WSGI app if we run N processes with M threads each (and pool_size=M) we'll get at most N * M connections. But what about ASGI (if we have a single process) - how many connections can be opened? Also pool_size (since we create only one AsyncEngine per process)? Then we should set it as pool_size=N * M?

And, if we simply increase this number, than we'll be able to make more simultaneous awaitable requests to the database, right?

What is the intuition behind it?

Thanks in advance!

Viacheslav Zhukov
  • 1,130
  • 9
  • 15

1 Answers1

0

in sqlalchemy to add pool size and max overflow u can use

engine = create_async_engine(
    settings.ASYNC_SQLALCHEMY_URL,
    echo=settings.SQLALCHEMY_ECHO,
    pool_size=20,
    max_overflow=10,
)

In sqlalchemy you dont have max pool size but recommend pool size is 20

  • 2
    Thanks for your answer. Yes, we're aware about these settings, however, the question is - how does `async` functionality affects tuning process of these parameters? What happens if we issue more `await`able connections than the `pool_size`? Will they get into a queue? And what queue? – Viacheslav Zhukov Jun 15 '22 at 12:48