MagicStack / MagicStack/asyncpg
Regression in copy records performance between 0.30.0 and 0.31.0
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 468
- PR 合并指标
- 30 天内没有已合并 PR
描述
When run on different versions (0.30.0 vs 0.31.0), the following script reproduces the issue and consistently shows a performance regression of approximately 22%:
import asyncio
import asyncpg
import time
COUNT = 5_000
async def run():
conn = await asyncpg.connect("postgresql://user:password@localhost/postgres")
await conn.execute("CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, username TEXT, email TEXT, age INT)")
RECORDS = [("John Doe", "john.doe@example.com", 42)] * 10_000
start = time.perf_counter()
for _ in range(COUNT):
await conn.copy_records_to_table("users", records=RECORDS, columns=["username", "email", "age"])
end = time.perf_counter()
await conn.close()
return end - start
if __name__ == "__main__":
total = asyncio.run(run())
print(f"Total time: {total:.5f} seconds")
print(f"Average time per loop: {total / COUNT:.8f} seconds")
(common) [e.lee@OC0000842]$ pip install asyncpg==0.30.0
(common) [e.lee@OC0000842]$ python -m example
Total time: 89.15468 seconds
Average time per loop: 0.01783094 seconds
(common) [e.lee@OC0000842]$ pip install asyncpg==0.31.0
(common) [e.lee@OC0000842]$ python -m example
Total time: 108.57080 seconds
Average time per loop: 0.02171416 seconds
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用 asyncpg 0.30.0 和 0.31.0 针对 PostgreSQL 运行提供的 asyncio 脚本,确认报告的 copy_records_to_table 耗时差异。跟踪 copy_records_to_table 的路径,以确定这些版本之间发生了什么变化;当回归问题得到解释且基准测试不再显示报告的性能下降时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- postgresql, python
- 领域
- databases, performance
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100