Skip to content

Commit 8dc5d4c

Browse files
committed
Merge branch 'dev': 阶段0 下载提速优化
2 parents c8f2288 + f7aa5c3 commit 8dc5d4c

3 files changed

Lines changed: 73 additions & 15 deletions

File tree

‎server/deploy.sh‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,31 @@ log_info "准备静态资源目录..."
7474
mkdir -p /opt/Entropydecrease/website /opt/Entropydecrease/downloads
7575

7676
# ---------------------------------------------------------------------------
77-
# 4. 构建并启动服务
77+
# 4. 启用 BBR 拥塞控制(幂等)
78+
# 安装包下载实测单流仅 ~143KB/s、而多并发可达 ~550KB/s,典型的跳网
79+
# 丢包导致单流 TCP 吞吐劣化。BBR 对此类链路提升明显。
80+
# 容器共享宿主机内核,宿主机启用即对 Nginx 生效。
81+
# ---------------------------------------------------------------------------
82+
log_info "检查 TCP 拥塞控制算法..."
83+
CURRENT_CC=$(sysctl -n net.ipv4.tcp_congestion_control 2>/dev/null || echo unknown)
84+
85+
if [ "$CURRENT_CC" = "bbr" ]; then
86+
log_info "BBR 已启用 ✓"
87+
elif sysctl net.ipv4.tcp_available_congestion_control 2>/dev/null | grep -q bbr; then
88+
log_info "启用 BBR(当前: $CURRENT_CC)..."
89+
# 写入失败(如非 root)不应中断部署,仅告警
90+
if printf 'net.core.default_qdisc = fq\nnet.ipv4.tcp_congestion_control = bbr\n' \
91+
> /etc/sysctl.d/99-bbr.conf 2>/dev/null && sysctl --system >/dev/null 2>&1; then
92+
log_info "BBR 已启用(现为: $(sysctl -n net.ipv4.tcp_congestion_control))✓"
93+
else
94+
log_warn "BBR 写入/生效失败(需 root 权限),已跳过,不影响部署"
95+
fi
96+
else
97+
log_warn "当前内核不支持 BBR(需 Linux ≥ 4.9),已跳过"
98+
fi
99+
100+
# ---------------------------------------------------------------------------
101+
# 5. 构建并启动服务
78102
# ---------------------------------------------------------------------------
79103
log_info "构建 Docker 镜像(首次构建约需 3-5 分钟)..."
80104

@@ -85,13 +109,13 @@ log_info "启动所有服务..."
85109
docker compose -f docker-compose.prod.yml --env-file "$ENV_FILE" up -d
86110

87111
# ---------------------------------------------------------------------------
88-
# 5. 等待服务就绪
112+
# 6. 等待服务就绪
89113
# ---------------------------------------------------------------------------
90114
log_info "等待服务启动..."
91115
sleep 10
92116

93117
# ---------------------------------------------------------------------------
94-
# 6. 健康检查
118+
# 7. 健康检查
95119
# ---------------------------------------------------------------------------
96120
log_info "执行健康检查..."
97121

‎server/nginx/nginx.conf‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ http {
1010
default_type application/octet-stream;
1111

1212
sendfile on;
13+
# 配合 sendfile:尽量用满 MSS 发送大文件,减少小包(安装包下载场景收益明显)
14+
tcp_nopush on;
1315
keepalive_timeout 65;
1416
client_max_body_size 2m;
1517

@@ -27,6 +29,8 @@ http {
2729
limit_req_zone $binary_remote_addr zone=ai:10m rate=30r/m;
2830
# 安装包下载并发限制(按 IP),避免大文件下载挤占 API 带宽
2931
limit_conn_zone $binary_remote_addr zone=dl_conn:10m;
32+
# 全站下载总并发(key 为常量):防止大量同时下载耗尽连接与带宽
33+
limit_conn_zone $server_name zone=dl_total:1m;
3034

3135
# Upstream 后端服务
3236
upstream ai_gateway {
@@ -198,9 +202,13 @@ http {
198202
location ^~ /downloads/ {
199203
root /usr/share/nginx;
200204
autoindex off;
201-
# 单连接限速 2MB/s + 单 IP 最多 4 并发,保护 AI 网关/同步服务带宽
205+
# limit_rate 保留作为异常保护上限:实测单流仅 ~143KB/s(受跳网 RTT/
206+
# 丢包限制),远低于 2m,故它不是当前瓶颈,提高无收益。
207+
# 单 IP 并发 8:多线程下载器常开 8~16 连接,限 4 会让超出连接被拒(503);
208+
# 带宽本身是硬顶(总约 550KB/s),放宽并发不会额外抢带宽,仅提升兼容性。
202209
limit_rate 2m;
203-
limit_conn dl_conn 4;
210+
limit_conn dl_conn 8;
211+
limit_conn dl_total 24;
204212

205213
# 更新元数据(latest.yml / latest.json)禁止缓存,
206214
# 否则客户端会长期读到旧版本信息;允许 www 子域跨域读取

‎website/components/DownloadCta.tsx‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,42 @@ export function DownloadCta() {
9090
<p className="text-xs text-kb-text3 mb-2">
9191
约 {sizeMB} MB · 适用于 Windows 10/11 (64位) · 免费开源
9292
</p>
93-
<p className="text-xs mb-8">
94-
<a
95-
href={GITHUB_RELEASES}
96-
target="_blank"
97-
rel="noopener noreferrer"
98-
className="text-kb-text3 underline underline-offset-2 transition-colors duration-300 hover:text-kb-text2"
99-
>
100-
下载缓慢?使用 GitHub 备用源 ↗
101-
</a>
102-
</p>
93+
94+
{/* 下载提速引导:单连接受跳网丢包限制,多线程下载器可明显提速;
95+
服务器已支持 Range 请求(断点续传) */}
96+
<details className="text-xs mb-8 text-left max-w-md mx-auto">
97+
<summary className="cursor-pointer text-kb-text3 transition-colors duration-300 hover:text-kb-text2 text-center">
98+
下载缓慢?点此查看提速方式
99+
</summary>
100+
<div className="mt-4 rounded-xl p-4 space-y-3" style={{ background: "var(--kb-bg-tertiary)" }}>
101+
<p className="text-kb-text2 leading-relaxed">
102+
本站已支持<strong className="text-kb-text">断点续传与分段下载</strong>。浏览器默认只用单连接,
103+
换用多线程下载工具(如 Motrix、IDM、aria2)通常可快几倍。
104+
</p>
105+
{latest && (
106+
<div>
107+
<p className="text-kb-text3 mb-1.5">直链(可复制到下载工具):</p>
108+
<code
109+
className="block break-all rounded-lg px-3 py-2 font-mono text-[11px] text-kb-text2"
110+
style={{ background: "var(--kb-bg-secondary)" }}
111+
>
112+
{downloadUrl}
113+
</code>
114+
</div>
115+
)}
116+
<p className="text-kb-text3">
117+
仍然缓慢?试试{" "}
118+
<a
119+
href={GITHUB_RELEASES}
120+
target="_blank"
121+
rel="noopener noreferrer"
122+
className="underline underline-offset-2 transition-colors duration-300 hover:text-kb-text2"
123+
>
124+
GitHub 备用源 ↗
125+
</a>
126+
</p>
127+
</div>
128+
</details>
103129

104130
{/* 系统要求 */}
105131
<div className="grid grid-cols-2 sm:grid-cols-4 gap-4 text-left">

0 commit comments

Comments
 (0)