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