MagicStack / MagicStack/asyncpg
Prepared Statement connection is active and wait for ClientRead.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 8.1k
- Fork
- 468
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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!
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il flusso delle istruzioni preparate di asyncpg descritto nell’issue e con la documentazione del protocollo extended-query di PostgreSQL. Determina se la modifica della sequenza Flush/Sync può preservare la correttezza con più passaggi Bind/Execute; il lavoro è completato quando pg_stat_activity riporta lo stato della connessione in modo coerente senza compromettere le istruzioni preparate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- postgresql, python
- Ambito
- databases
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100