A
A
Alexander Ivanov2018-09-30 23:31:40
Python
Alexander Ivanov, 2018-09-30 23:31:40

Can postgres handle asynchronous requests?

The bottom line is this: I want to rewrite one project to asynchronous (More from the desire to touch what and how). Nowhere did I find an answer to the question: Can the database itself process requests asynchronously? That is - what's the point, for example, to use an asynchronous framework for the database, if the database will still process requests in the queue? That is, in fact, if each web request is a separate coroutine, then with the asynchronous framework we simply eliminate the framework’s blocking when accessing the database, or does it really increase the performance of working with the database?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2018-09-30
@Lazoreth

libpq is capable of asynchronous query execution in the sense that a query is sent for execution and returns control to the application without waiting for the query to complete.
One connection to the database at a time can only perform one request. You can't run one query and run another through the same connection without waiting for it to complete. Through another connection - you can.
Whether the requests in the database itself will be serialized into a queue or executed in parallel is a question for these same requests. Readers are quite difficult to block with something, writers can often conflict for blocking.

P
planc, 2018-09-30
@planc

async does not speed up data processing, it allows you to smooth out the slowness of the network
, clients are slow and while data is coming from them, cpu is idle, the database is standing
nearby and answers will come from it quickly
Miguel on pycon gave a good example, async server is a chess grandmaster who plays with noobs
he doesn’t play with each one in turn, he makes a move and goes on
, so in this case, bd is the grandmaster’s brains,
they will quickly process requests

A
Andrey K, 2018-10-01
@kuftachev

The database holds a certain number of connections depending on the settings and power of the server, and then you need to either study the database normally in order to understand how everything works there, or not to worry and know that smart people work there and they understand.
And so, of course, in most modern databases there will be both asynchrony and multithreading ... As far as transaction isolation levels allow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question