You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apologies in advance as there's probably a straightforward answer to this that I'm missing, but what's the best way now to run consecutive queries without waiting for previous queries? ie without waiting for a round trip.
Ideally, I'd like to be able to use await and Task.WhenAll a la Redis multiplexing, as I'm using F# and it has some constructs that make this particularly ergonomic.
Apologies in advance as there's probably a straightforward answer to this that I'm missing, but what's the best way now to run consecutive queries without waiting for previous queries? ie without waiting for a round trip.
Other than writing a custom pipelining via channels (that is, having a single thread consuming incoming queries and then batching them together up to a point), yeah, there's probably no other good way to implement this without multiplexing (which from what I remember was removed due to it not scaling that well with cores, @roji should know better).
From what I know libpq does have pipeline mode build-in, so maybe that's something we can explore as well? Though obviously that's going to be completely outside of ADO.NET.
For now, marking as a feature to explore for future releases.
Ideally, I'd like to be able to use await and Task.WhenAll a la Redis multiplexing, as I'm using F# and it has some constructs that make this particularly ergonomic.
If you want to run multiple queries in parallel, then you currently need to have a separate NpgsqlConnection for each one; you can have a block opening a new connection and executing some query, and then do Task.WhenAll on many such blocks. However, doing the same thing over a single connection - which is what multiplexing provided - is not currently possible in the driver; we experimented with this in various ways, and at least our implementation at the time had various problems and limitations. This isn't something I see us looking into in the near future as it's quite a major undertaking.
I guess there isn't too much harm in using multiple connections in order to minimize round trip time. Maybe that limits the maximum number of concurrent users at the service level though since the thread pool is a finite resource, so batching might be the way to go either way?
Activity
CodesInChaos commentedon Nov 11, 2026
Raw Npgsql supports batching. I'm not aware of a similar mechanism in EF Core.
reinux commentedon Nov 17, 2026
I'm using raw npgsql, so that should work. Is pipelining a thing at all, or was that scrapped along with multiplexing?
vonzshik commentedon Nov 17, 2026
Other than writing a custom pipelining via channels (that is, having a single thread consuming incoming queries and then batching them together up to a point), yeah, there's probably no other good way to implement this without multiplexing (which from what I remember was removed due to it not scaling that well with cores, @roji should know better).
From what I know libpq does have pipeline mode build-in, so maybe that's something we can explore as well? Though obviously that's going to be completely outside of ADO.NET.
For now, marking as a feature to explore for future releases.
roji commentedon Nov 17, 2026
If you want to run multiple queries in parallel, then you currently need to have a separate NpgsqlConnection for each one; you can have a block opening a new connection and executing some query, and then do Task.WhenAll on many such blocks. However, doing the same thing over a single connection - which is what multiplexing provided - is not currently possible in the driver; we experimented with this in various ways, and at least our implementation at the time had various problems and limitations. This isn't something I see us looking into in the near future as it's quite a major undertaking.
reinux commentedon Nov 18, 2026
I guess there isn't too much harm in using multiple connections in order to minimize round trip time. Maybe that limits the maximum number of concurrent users at the service level though since the thread pool is a finite resource, so batching might be the way to go either way?