JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
feat(gateway): 连接池 max_connections/max_keepalive 支持环境变量配置
caozhenhua0000154078f5b409
diff --git a/deploy/enterprise/.env.example b/deploy/enterprise/.env.exampleindex 2aa8bdbb99..d9cba03563 100644--- a/deploy/enterprise/.env.example+++ b/deploy/enterprise/.env.example@@ -235,6 +235,13 @@ GATEWAY_IMAGE=""GATEWAY_CLAW_WS_PING_INTERVAL="20.0" # WebSocket 心跳发送间隔GATEWAY_CLAW_WS_PING_TIMEOUT="20.0" # WebSocket 心跳无响应超时阈值,超过该时间未收到对端pong则断开重连+# Gateway 到单个 AgentServer Pod 的 HTTP 连接池上限(按每个 AS Pod 独立计,非全局)+# max_connections:单个 Pod 同时最多建立的连接数,决定并发 chat 流会不会在 Gateway 侧排队+# max_keepalive:请求结束后保留的闲置连接数(省握手,不影响并发上限)+# 默认 200 / 20;多副本时每副本独立,总并发 ≈ 单副本值 × 副本数+GATEWAY_AGENT_HTTP_MAX_CONNECTIONS=200+GATEWAY_AGENT_HTTP_MAX_KEEPALIVE=20+# 请求级扩展字段白名单,逗号分隔;空值表示关闭。# HTTP 从同名请求头读取,WebSocket 从握手 query 读取;仅白名单字段会透传至 Rail。JIUWENSWARM_REQUEST_EXT_FORWARD_HEADERS=""diff --git a/deploy/enterprise/global_vars.sh b/deploy/enterprise/global_vars.shindex c585335fef..cd360045cc 100755--- a/deploy/enterprise/global_vars.sh+++ b/deploy/enterprise/global_vars.sh@@ -141,6 +141,8 @@ declare -A DEPLOY_VARS=(["GATEWAY_DB_MAX_OVERFLOW"]="20"["GATEWAY_DB_POOL_SIZE"]="2"["GATEWAY_DB_POOL_TIMEOUT"]="30"+ ["GATEWAY_AGENT_HTTP_MAX_CONNECTIONS"]="200"+ ["GATEWAY_AGENT_HTTP_MAX_KEEPALIVE"]="20"["GATEWAY_ENV_FILE_CM_NAME"]="jiuwenclaw-gateway-envfile"["GATEWAY_INSTANCE_ID"]=""["GATEWAY_SCHED_LABEL_ENABLED"]="false"diff --git a/deploy/enterprise/templates/gateway.template.env b/deploy/enterprise/templates/gateway.template.envindex c85e378f47..65ddb67d38 100644--- a/deploy/enterprise/templates/gateway.template.env+++ b/deploy/enterprise/templates/gateway.template.env@@ -26,6 +26,9 @@ AGENT_EXTRA_TOOLS=<<AGENT_EXTRA_TOOLS>>MODE=<<MODE>># Gateway Configuration+# Gateway → AgentServer HTTP 连接池上限(按每个 AS Pod 独立计)+GATEWAY_AGENT_HTTP_MAX_CONNECTIONS=<<GATEWAY_AGENT_HTTP_MAX_CONNECTIONS>>+GATEWAY_AGENT_HTTP_MAX_KEEPALIVE=<<GATEWAY_AGENT_HTTP_MAX_KEEPALIVE>>LOG_MASK_ENABLED=<<LOG_MASK_ENABLED>>LOG_TO_FILE_ENABLED=<<LOG_TO_FILE_ENABLED>>SYNC_CONFIG_ON_STARTUP=FALSEdiff --git a/jiuwenswarm/gateway/routing/http_agent_client.py b/jiuwenswarm/gateway/routing/http_agent_client.pyindex 213ca25d7b..dd2fa4ff46 100644--- a/jiuwenswarm/gateway/routing/http_agent_client.py+++ b/jiuwenswarm/gateway/routing/http_agent_client.py@@ -20,6 +20,7 @@ from jiuwenswarm.common.e2a.constants import ()from jiuwenswarm.common.e2a.models import E2AEnvelopefrom jiuwenswarm.common.e2a.wire_codec import parse_agent_server_wire_chunk+from jiuwenswarm.common.local_env_config import read_envfrom jiuwenswarm.common.schema.agent import AgentResponse, AgentResponseChunkfrom jiuwenswarm.common.security.link_mtls import LinkMTLSConfigfrom jiuwenswarm.gateway.routing.agent_client import (@@ -33,6 +34,16 @@ from jiuwenswarm.gateway.routing.agent_rest_map import (logger = logging.getLogger(__name__)++def _env_int(name: str, default: int) -> int:+ """读进程级环境变量并转 int;非数字/≤0 时回退默认值。"""+ try:+ value = int(float(read_env(name, "").strip()))+ except (TypeError, ValueError):+ return default+ return value if value > 0 else default++_CONNECT_TIMEOUT_SECONDS = 10.0_PUSH_RETRY_SECONDS = 3.0# 企业按 Pod 订阅:连续 TCP 失败才停,避免活 Pod 闪断被立刻 drop。@@ -225,9 +236,11 @@ class HttpSseAgentServerClient(AgentServerClient):def _ensure_http(self) -> httpx.AsyncClient:if self._http is None:link_mtls = self._link_config()+ max_conns = _env_int("GATEWAY_AGENT_HTTP_MAX_CONNECTIONS", 200)+ max_keepalive = _env_int("GATEWAY_AGENT_HTTP_MAX_KEEPALIVE", 20)self._http = httpx.AsyncClient(timeout=httpx.Timeout(self._timeout_s, connect=_CONNECT_TIMEOUT_SECONDS),- limits=httpx.Limits(max_connections=20, max_keepalive_connections=10),+ limits=httpx.Limits(max_connections=max_conns, max_keepalive_connections=max_keepalive),follow_redirects=False,trust_env=False,**link_mtls.client_kwargs(role="agentserver"),