MagicStack / MagicStack/asyncpg

Prepared Statement connection is active and wait for ClientRead.

Offen
#1,276 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
468
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Hi team,

Right now, asyncpg does prepared statements in two steps.
1. Parse, Describe, Flush.
2. Bind, Execute, Sync.

Two coroutines represent these two steps. In a highly concurrent setup, the wall-clock gap between these two steps can be large. Why is it causing a problem for me? Command `Flush` does not change the connection state, i.e., `active`. So I observe a lot of queries show up as
```
wait_event_type | wait_event | state
-----------------+------------+--------
Client | ClientRead | active
```
in `pg_stat_activity`. This causes a lot of unnecessary confusion for our database monitors/observability tools. The connection is essentially idle between these two steps, so I think it is better to report it as `wait_event=ClientRead` but `state=idle`? Meanwhile, the command `Sync` will change the connection state to `idle`, so after step 2, the connection becomes idle.

My ask is: could we use `Sync` instead of `Flush` in step 1?

Moreover, there could be more than one `bind` step, so the sequence could be
```
1. Parse, Describe, Flush.
2. Bind, Execute, Sync.
3. Bind, Execute, Sync.
...
```
In this case, the connection is active only between step 1 and step 2, but idle for all other step gaps. I kind of feel this behavior is inconsistent.
I might have neglected some basic design about PostgreSQL [extended query](https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY). Hope to hear from you soon!

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem im Issue beschriebenen Ablauf für vorbereitete Statements von asyncpg und der Dokumentation zum Extended-Query-Protokoll von PostgreSQL. Ermittle, ob eine Änderung der Flush/Sync-Sequenz die Korrektheit bei mehreren Bind/Execute-Schritten bewahren kann; abgeschlossen ist die Aufgabe, wenn pg_stat_activity den Verbindungsstatus konsistent meldet, ohne vorbereitete Statements zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, python
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.