Skip to content

[Priority: Med] [Reliability] 增加上游并发控制与背压保护 #276

@liujuanjuan1984

Description

@liujuanjuan1984

🔍 发现的问题 / 原始需求描述

适配器层对上游 OpenCode 缺乏并发限制。在高负载或上游延迟突增场景下,适配器层可能积压大量未决的异步任务,导致内存消耗剧增。

🛠️ 详细实施方案

  • 涉及文件: src/opencode_a2a_server/opencode_upstream_client.py
  • 核心逻辑:
    1. OpencodeUpstreamClient 中引入并发信号量(asyncio.Semaphore)。
    2. 封装 _dispatch_with_concurrency_limit 方法,对所有流式和常规请求生效。
  • 伪代码:
    class OpencodeUpstreamClient:
        def __init__(self, limit: int = 50):
            self._semaphore = asyncio.Semaphore(limit)
        
        async def _call_with_limit(self, ...):
            async with self._semaphore:
                return await self._client.post(...)

🧪 回归测试建议

  • 编写压力测试脚本,在限制并发数为 5 时发起 10 个以上请求,验证多余请求在队列中排队而非立即失败或内存泄露。

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:todoPlanned but not started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions