Daniele Varrazzo [Mon, 17 Oct 2022 02:12:24 +0000 (03:12 +0100)]
feat: add wait_select() function
A few tests show that using select() from Python has a lower overhead.
See #414.
Use this function wherever defined and epoll() is the default select
strategy instead. This is mostly a draft to figure out where this
strategy can be used with success.
Daniele Varrazzo [Mon, 17 Oct 2022 09:42:33 +0000 (10:42 +0100)]
test: add simple test to compare performances in refactoring
This test is inspired to the problem open in #411, and is pretty much a
simple operation in a tight loop. It is used, at the moment, to compare
different ways to test I/O completion strategies with simple and fast
queries under no concurrency.
Daniele Varrazzo [Sun, 27 Nov 2022 14:20:10 +0000 (15:20 +0100)]
perf(c/array): add C implementation of array loader
With this change we get to load an array without the transformer calling
any Python code (if the element loader is a CLoader as well).
We don't need to subclass the binary loader anymore because all the
required info is now taken from the loaded data. As a consequence, we
don't need a BaseArrayLoader anymore.
Daniele Varrazzo [Thu, 20 Oct 2022 21:41:03 +0000 (23:41 +0200)]
fix: get element oid from the array itself in binary format
Getting it from the type was causing problems in CRDB because they seem
to have a different interpretation of what Int2 and Int4 are. Refactor
the binary parser to take a transformer, instead of a loader function,
in order to look up the loader from the oid parsed from the array.
Also refactor the text array parser to take the whole loader instead of
the load function only, which will be useful in order to optimize the
use of C loaders.
This implementation can be still improved: we always call the Python
loader to decode the single elements; we can try and call the C loader
if available.
fix(pool): make sure to throw a RuntimeError opening async pool without a loop
The error would be thrown anyway downstream, when tasks are created, but
other spurious warning might be raised too because certain tasks are not
awaited.
lint: fix type hints with disabled bytearray/memoryview/bytes equivalience
This changeset makes the code compatible with the current Mypy 0.981,
but passes most of the checks that Mypy 0.990 enforces if the byte
strings equivalence is disabled.
This change is backward compatible because bytes has a superset of the
memoryview interface and, in Python, to make pretty much any use of it,
it must be converted to bytes beforehand.
Denis Laxalde [Tue, 4 Oct 2022 15:53:26 +0000 (17:53 +0200)]
fix: sync pipeline after implicit BEGIN
Prior to this change, the following code:
with conn.pipeline():
conn.execute("select 'x'").fetchone()
conn.execute("select 'y'")
would produce the following libpq trace:
F 13 Parse "" "BEGIN" 0
F 14 Bind "" "" 0 0 1 0
F 6 Describe P ""
F 9 Execute "" 0
F 18 Parse "" "select 'x'" 0
F 14 Bind "" "" 0 0 1 0
F 6 Describe P ""
F 9 Execute "" 0
F 4 Flush
B 4 ParseComplete
B 4 BindComplete
B 4 NoData
B 10 CommandComplete "BEGIN"
B 4 ParseComplete
B 4 BindComplete
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 65535 -1 0
B 11 DataRow 1 1 'x'
B 13 CommandComplete "SELECT 1"
F 13 Parse "" "BEGIN" 0
F 14 Bind "" "" 0 0 1 0
F 6 Describe P ""
F 9 Execute "" 0
F 18 Parse "" "select 'y'" 0
F 14 Bind "" "" 0 0 1 0
F 6 Describe P ""
F 9 Execute "" 0
B 4 ParseComplete
B 4 BindComplete
B 4 NoData
B NN NoticeResponse S "WARNING" V "WARNING" C "25001" M "there is already a transaction in progress" F "SSSS" L "SSSS" R "SSSS" \x00
F 4 Sync
B 10 CommandComplete "BEGIN"
B 4 ParseComplete
B 4 BindComplete
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 65535 -1 0
B 11 DataRow 1 1 'y'
B 13 CommandComplete "SELECT 1"
B 5 ReadyForQuery T
where we can see that the BEGIN statement (due to the connection being
in non-autocommit mode) is emitted twice, as notified by the server.
This is because the transaction state after the implicit BEGIN is not
"correct" (i.e. should be INTRANS, but is IDLE) since the result from
respective statement has not been received yet.
By syncing after the BEGIN, we fetch result from this command thus get
the transaction state INTRANS for following queries. This is similar to
what happens with explicit transaction, by using nested pipelines.
build: fix starting Postgres in macOS build script
The brew command fails with:
Could not enable service: 125: Domain does not support specified action
Error: Failure while executing; `/bin/launchctl enable gui/501/homebrew.mxcl.postgresql@14` exited with 125.