Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qianfan http client 不支持连接池配置,无法复用连接,默认的session连接池大小只有10,将client 作为全局时,并发高一点就会出现连接池异常 #863

Open
zhengshuheng opened this issue Nov 11, 2024 · 0 comments

Comments

@zhengshuheng
Copy link

System Info

qianfan 0.4.10.1

Reproduction

文档解析知识增强场景下,我们需要并发请求模型,希望复用连接提高效率,发现qianfan http-client不支持连接池配置及外部传递http-client对象。
qianfan http client 不支持连接池配置,无法复用连接,将client 作为全局时,并发高一点就会出现连接池异常
https://github.com/baidubce/bce-qianfan-sdk/blob/main/python/qianfan/resources/http_client.py
其中的第45行新建了sesssion。
同时https://github.com/baidubce/bce-qianfan-sdk/blob/main/python/qianfan/resources/requestor/base.py 第348行_client不支持外部传递http_client对象,控制连接池。

建议改造示例:
base.py 支持 自定义client :self._client = kwargs.get("http_client", HTTPClient(**kwargs))
http_client.py 支持 自定义连接池配置:
self._session = requests.Session()

    # 配置连接池
    adapter = HTTPAdapter(
        pool_connections=kwargs.get("pool_connections",10),  # 每个主机最大连接数
        pool_maxsize=kwargs.get("pool_connections", 100),
        max_retries=Retry(total=3, backoff_factor=0.1)
    )
    self._session.mount('http://', adapter)
    self._session.mount('https://', adapter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant