MagicStack / MagicStack/asyncpg
Feature request: Support for asynchronous command processing
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 468
- PR 合并指标
- 30 天内没有已合并 PR
描述
libpq has support for something called asynchronous command processing (https://www.postgresql.org/docs/current/libpq-async.html).
Thea idea is fairly simple: you can queue up multiple queries on one connection without waiting for the previous result and then wait for all the results at the end. This avoids waiting for network round trips between queries, which at least in theory should have the same performance benefits as running multiple queries with one network round trip.
It would be useful if asyncpg could support the same concept. The Python API should be fairly straightforward. You just start multiple coroutines with queries and then await all of them together at the end. Something like this:
q1 = conn.fetch('SELECT $1', 1)
q2 = conn.fetch('SELECT $1', 2)
q3 = conn.fetch('SELECT $1', 3)
results = await asyncio.gather(q1, q2, q3) # (currently this raises InterfaceError)
This could have significant performance benefits in situations where you make multiple fast independent queries, especially if there is a large network round-trip delay.
AFAIK implementing this is definitely possible in theory. In practice, the complexity depends a lot on how the internals of asyncpg are structured, which I am not familiar with.
EDIT: This request is motivated by the same goal as https://github.com/MagicStack/asyncpg/issues/839, but my proposal is to specifically use asynchronous command processing without pipelining. If my understanding of the extended query protocol is correct, it should be possible to issue multiple queries without waiting for results between them but with a sync point after each query, which helps avoid the complex error handling rules of pipeline mode. (If my understanding of extended query protocol is not correct, this may be impossible. Feel free to correct me.)
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 issue 中链接的 libpq 异步命令处理文档开始,然后检查 asyncpg 在 conn.fetch 附近的连接 API,以及 gather 协程时当前的 InterfaceError 行为。将提议的非流水线行为与 extended query protocol 进行比较,并确定所请求的 API 和同步语义是否可行;issue 未提供文件或测试入口点。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- postgresql, python
- 领域
- databases
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100