-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PgRowPublisherOperation should consider Subscriber demand #33
Comments
Do you think there is a need to tune the fetch size per request, or could it be a SessionParameter? |
Both, assuming request maps to a statement execution and not to a single server req/resp exchange. You want to be able to tune defaults for an application. Some queries require additional tuning (see JDBC's FetchSize) to optimize for e.g. large or small data sets. |
I have thought some more on this:
Based on the above points I still thinks this is a valid feature request, but as it's nontrivial to implement and the specification might change again I will focus on lower hanging fruit for now. |
I'd like to elaborate a bit on your first point:
That's exactly the case. No demand will stop traffic on the connection and unblock the connection once the command is either canceled or registers additional demand. That is basically what should happen on non-multiplexed connections. In the first moment, this seems an odd thought because: Why would one want this to happen? If you do not share the connection but use it linearly (send a statement, consume results, send next statement, …), this pattern makes totally sense as you do not read more data at a time than necessary. Thus, you don't allocate more memory than needed (based on subscriber demand) to process incoming data – you leave all data outside your application/JVM. If you do share the connection or even want to run interleaved queries, requirements might change a bit. I'm not entirely familiar with the Postgres wire protocol, but I know from older SQL server versions that a single transport connection was bound to single query execution and didn't allow for interleaved SQL batches (until MARS was implemented). In such a scenario, you would not want to prevent interleaved queries, and thus you want to unblock the connection (consume a response) to issue the next query while a cursor/result is not fully consumed. The price for this feature is paid with higher memory consumption as you need to consume a response and keep it in memory until its subscriber asks for more data. At this point, a driver might want to consider the actual demand and allow for optimizations. You want to reduce the number of roundtrips while aligning the fetch size to the actual demand.
I concur. This feature needs additional thought. |
This is the case with the Postgres protocol too, a connection cannot be multiplexed. See https://www.postgresql.org/docs/current/protocol.html. |
PgRowPublisherOperation
acceptsFlow.Subscriber
that requests a number of data signalsn
(typically rows) viaSubscription.request(n)
.PgRowPublisherOperation
should consider demand to:fetchSize(long rows)
onRowPublisherOperation
in ADBA spec)n
rows from a cursor (when using cursored fetching)n
rows as soon asSubscriber
requests additional rowsTypically, it's hard to fetch exactly
n
rows, but the point here is to fetch more or lessn
rows to satisfy demand and pre-buffer some additional rows (smart prefetching) to reduce latency between I/O and processing.The text was updated successfully, but these errors were encountered: