This commit is contained in:
2026-04-16 21:56:42 +08:00
parent c79192e2ce
commit ee96dd82d2
+5 -3
View File
@@ -624,7 +624,9 @@ func (c *Crawler) Run(entryURL string, maxEpoch int) {
cs.IsRunning = false
})
// 空循环等 normalChildCh,新数据到达后立即从 epoch 0 重新开始
// 加 1000ms 睡眠避免 CPU 空转轮询
// 使用 ticker 避免循环内重复创建 timer
waitTicker := time.NewTicker(100 * time.Millisecond)
defer waitTicker.Stop()
for {
select {
case gc, ok := <-c.normalChildCh:
@@ -642,8 +644,8 @@ func (c *Crawler) Run(entryURL string, maxEpoch int) {
case <-c.stopCh:
// 收到停止信号
return
case <-time.After(1000 * time.Millisecond):
// 每 1000ms 检查一次,降低 CPU 占用
case <-waitTicker.C:
// 每 100ms 检查一次,降低 CPU 占用
}
}
restartEpochLoop: