Prepared Statement connection is active and wait for ClientRead.

オープン
#1,276 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
postgresql, python
領域
databases

調査の方向性

issue で説明されている asyncpg の prepared-statement フローと、PostgreSQL の extended-query プロトコルのドキュメントから始めます。複数の Bind/Execute ステップがある場合に、Flush/Sync のシーケンスを変更しても正しさを維持できるか判断します。完了の条件は、prepared statements を壊すことなく、pg_stat_activity が接続状態を一貫して報告することです。

索引モデルが issue の本文から書いたものです。

説明

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. Hope to hear from you soon!

主要言語
Python
スター
8.1k
フォーク
469
平均マージ
18分
マージ済み PR(30日)
4

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MagicStack/asyncpg のほかの issue

MagicStack/asyncpg の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。