Potential starvation with connection pool
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先,使用 asyncio.TaskGroup、100 个 workers 和 asyncpg.pool.create_pool(max_size=10) 运行提供的 Python 复现程序。检查 pool.acquire(timeout=10) 在竞争下的行为,并确定观察到的 TimeoutError 是反映了饥饿,还是预期的调度;完成标准是记录 fairness guarantee,或识别出一个可复现的 pool 缺陷。
由索引模型根据 Issue 内容生成。
描述
I have the following piece of code where I initialize 100 workers and a connection pool of size 10. Each worker loops and trys to acquire a connection and hold it for 200ms.
import asyncio
import asyncpg
async def worker(pool: asyncpg.Pool):
while True:
async with pool.acquire(timeout=10):
# hold the connection for 200ms
await asyncio.sleep(0.2)
async def main():
async with asyncpg.pool.create_pool(max_size=10) as pool:
async with asyncio.TaskGroup() as tg:
for _ in range(100):
tg.create_task(worker(pool))
asyncio.run(main())
When running on my laptop, this code reliably crashes with a TimeoutError after a few minutes, meaning that at least one worker failed to acquire a connection after 10 seconds. Given that there're 10 workers per connection and each worker holds the connection for 200ms, I would expect workers to be able to acquire a connection every 2 seconds.
This looks like starvation to me. Are there fairness guarantees regarding connection pools? Is there anything I could do other than just increasing the max pool size?
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 474
- 平均合并
- 3 天 14 小时
- 30 天内合并 PR
- 17
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MagicStack/asyncpg 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 72/100
MagicStack/asyncpg#1342 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
MagicStack/asyncpg#1340 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 28/100
MagicStack/asyncpg#1337 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
MagicStack/asyncpg#1330 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 38/100
MagicStack/asyncpg#1322 ·
维护者通常 1 天内回复
查看 MagicStack/asyncpg 的全部 Issue
相似的 Issue
-
New Internship未关闭new_internship
难度 1/5 1 小时以内 新手友好度 70/100
-
[BUG] Reports tab: "Unban" button tooltip shows raw `{{ip}}` placeholder instead of the IP address未关闭bug javascript ui
难度 2/5 1-3 小时 新手友好度 68/100
bunkerity/bunkerweb#4001 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 92/100
PedestrianDynamics/pyFDS-Evac#476 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
google/differential-privacy#516 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
adobe-fonts/source-serif#153 ·