Skip to content

perf(preheat): drain split ranges concurrently and reserve transfer slots for foreground - #124

Merged
mangoknight merged 1 commit into
dingodb:mainfrom
mangoknight:perf/preheat-parallel-ranges
Sep 24, 2026
Merged

mangoknight merged 1 commit into
dingodb:mainfrom
mangoknight:perf/preheat-parallel-ranges

Conversation

@mangoknight

@mangoknight mangoknight commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Two structural limits kept a preheat from using more upstream connections.

1. Split ranges drained in order

FileDownload consumed range outputs in file order and each range buffers only ~8MB, so later ranges blocked and a split file still had about one active stream. Preheat only counts bytes, so it sets the new TaskParam.Unordered and drainOutputs drains all ranges concurrently. Client downloads keep file order.

2. Background work could hold every transfer slot

A preheat could occupy all HuggingFace transfer slots and stall small foreground downloads. Preheat requests now carry transfersettings.WithBackground and take a bgGates slot first, capping background at limit − min(8, max(1, limit/4)) (8→6, 16→12, 64→56). No settings or UI change.

Tests

  • TestDrainOutputsUnorderedDoesNotWaitForEarlierRanges / TestDrainOutputsOrderedKeepsFileOrder.
  • TestBackgroundLeavesForegroundSlots (removing the cap fails it).

🤖 Generated with Claude Code

两个问题让预热即使开了分片、调高了连接数也快不起来,或者一快就饿死前台。

一、分片被按序消费,切了等于没切
FileDownload 逐个调用 task.OutResult(),第 0 片消费完才轮到第 1 片。每片
的输出队列只能缓冲 min(remoteFileBufferSize, 片长) = 8MB,后面的片下满 8MB
就阻塞在发往队列那一步,单个文件实际上仍约 1 条流在跑。客户端下载需要字节
有序,这样做没错;但预热只统计字节数(stockLen.Add),顺序无关。

新增 TaskParam.Unordered,预热打开它。drainOutputs 对 Unordered 并发消费
各片输出;客户端下载路径不变。

二、后台预热能占满传输闸门
hd-04 实测:预热占住全部 HuggingFace 传输槽时,用户下载一个未缓存的几百
字节文件卡了 150 秒。把闸门从 8 临时调到 16 后恢复,但一旦分片放开,预热
又会占满。

预热的请求带上 WithBackground 标记,后台传输先占 bgGates 槽再占普通槽,
后台上限 = 上限 − min(8, max(1, 上限/4))。默认 8 时后台 6、前台保底 2;
64 时后台 56、前台保底 8。配置项与管理界面均不变。

背景:同一 VM、同一马鞍山出口、同一时刻,aria2c 64 连接 177 MB/s,每条约
2.8 MB/s;dingospeed 预热 8 条连接合计约 8~14 MB/s。hf-mirror 限的是单连接,
总速度取决于连接数。本次修掉阻碍连接数上去的两处结构问题;连接数本身仍由
download.remoteFileRangeSize 与 transfer-settings 的 huggingface 上限决定。

测试:
- TestDrainOutputsUnorderedDoesNotWaitForEarlierRanges:前一片未完成时,
  后一片输出照常送达;改回按序后该测试失败。
- TestDrainOutputsOrderedKeepsFileOrder:客户端路径保持文件顺序。
- TestBackgroundLeavesForegroundSlots:后台占满其上限 6 时,再多一个后台
  请求必须等待(对照),前台 2 个请求在约 0.3ms 内拿到槽;去掉后台上限后
  该测试报 "background exceeded its limit"。

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012f8up6uMsz5RiVdFQfdUnx
@mangoknight
mangoknight added this pull request to the merge queue Sep 24, 2026
Merged via the queue into dingodb:main with commit f2ae437 Sep 24, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants