Skip to content

pgsql pipeline mode #13225

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

degtyaryov
Copy link
Contributor

@degtyaryov degtyaryov commented Jan 23, 2024

Hello.

I previously made a pool request #12731

For obvious reasons, this code could not be included in the release PHP-8.3 #12735

I haven't changed anything in the code since then. I moved the code to a separate branch.

I've been using the code in production for over a month, but without using pipeline mode.

I've been using pipeline mode in production for 2 weeks now.

So far I haven't found any problems!

I used pipeline mode:

  • to speed up the execution of consecutive SQL queries of different result format, which are problematic to combine into one SQL query;
  • to reduce the load on the database server using pg_send_prepare + pg_send_execute + pgbouncer(with enabled max_prepared_statements) for frequently used SQL queries. SQL query is also sent by 1 TCP package, no network latency, but server PostgreSQL gets only execute SQL query by name, without prepare.

#13223 (comment)
the changes needs to be applied from an up-to-date master branch. Take your time tough, we won t be merging it quickly.

Merged to master branch.

Adding pg_send_flush_request.
Fix freeze after next execute pg_send_* on PQgetResult in _php_pgsql_link_has_results.
Set nonblocking for pipelining mode.
No flush client buffer in pg_send_* for pipelining mode.
Fix freeze pg_cancel_query. In pipeline mode it should be possible to receive part of the results.

(cherry picked from commit 72f3efe)
Prevent freeze pg_get_result when not sent sync message in pipelining mode.
Fix freeze pg_close for connection in pipelining mode.
Fix freeze on rollback transactions for persistent connection in pipelining mode.
Fix freeze on shutdown.

(cherry picked from commit 1a775ce)
Fix freeze pg_query/pg_query_params/pg_prepare/pg_execute
}
if (leftover) {
php_error_docref(NULL, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first");
#ifdef LIBPQ_HAS_PIPELINING
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A macro or a inline for this whole "repeated all over" block might be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added to the existing code.

It also seemed to me that there were a lot of repeating blocks.

But, I don't plan to optimize other people's code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not so much about optimising but more about factoring, if we update again we won t need to do it more than once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants