]> git.ipfire.org Git - thirdparty/psycopg.git/commit
perf: avoid unnecessary recvfrom() in cursor.stream()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 1 May 2022 22:56:42 +0000 (00:56 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 2 May 2022 00:53:13 +0000 (02:53 +0200)
commit7aba716e92bde573a63c2798172c4d3eed41a680
treeaa9d4dd7362866bc84a16d86e291036c649e61de
parentffe68f8d6deca4a241f29f121577c81b04550ad0
perf: avoid unnecessary recvfrom() in cursor.stream()

Call PQisBusy() before PQconsumeInput() on fetching results. If not
busy, don't call PQconsumeInput() at all but just go to fetching results
and notifications.

This is especially useful in single-row mode because most of the times
the libpq can produce several results after a single network fetch.
Previously we were calling PQconsumeInput() also when results were
already on the client and there was nothing new to read, which forced
the libpq to run a select() to tell apart a lack of data from an EOF,
see `the grumble`_, and caused the overhead reported in #286.

Close #286.

.. _the grumble: https://github.com/postgres/postgres/blob/ed57cac84d1c5642737dab1e4c4b8cb4f0c4305f/src/interfaces/libpq/fe-misc.c#L681
docs/news.rst
psycopg/psycopg/generators.py
psycopg_c/psycopg_c/_psycopg/generators.pyx