实时显示发现的url数量
This commit is contained in:
+19
-2
@@ -69,6 +69,9 @@ type Crawler struct {
|
|||||||
// 运行时活跃线程计数(atomic,每轮 epoch 自动归零前重新开始计数)
|
// 运行时活跃线程计数(atomic,每轮 epoch 自动归零前重新开始计数)
|
||||||
activeWorkers int64
|
activeWorkers int64
|
||||||
|
|
||||||
|
// 本轮发现的新链接计数(atomic,供前端实时监控)
|
||||||
|
newLinksCount int64
|
||||||
|
|
||||||
// ---- Priority Worker(独立 goroutine,不受主 workers 限制)----
|
// ---- Priority Worker(独立 goroutine,不受主 workers 限制)----
|
||||||
priorityCh chan string // Priority URL 任务队列(用户手动添加)
|
priorityCh chan string // Priority URL 任务队列(用户手动添加)
|
||||||
priorityChildCh chan string // Priority 子链接队列(子 URL 继续由 priority worker 爬取)
|
priorityChildCh chan string // Priority 子链接队列(子 URL 继续由 priority worker 爬取)
|
||||||
@@ -93,7 +96,8 @@ type CrawlStatus struct {
|
|||||||
QueueLength int `json:"queue_length"` // 本轮队列长度
|
QueueLength int `json:"queue_length"` // 本轮队列长度
|
||||||
CompletedCount int `json:"completed_count"` // 本轮已完成的 URL 数
|
CompletedCount int `json:"completed_count"` // 本轮已完成的 URL 数
|
||||||
VisitedTotal int `json:"visited_total"` // 已收录 URL 总数
|
VisitedTotal int `json:"visited_total"` // 已收录 URL 总数
|
||||||
NextPoolSize int `json:"next_pool_size"` // 下一轮链接池大小(newLinks 调度后的队列长度)
|
NewLinksCount int64 `json:"new_links_count"` // 本轮已发现的新链接数(实时更新)
|
||||||
|
NextPoolSize int `json:"next_pool_size"` // 下一轮链接池大小(调度后的队列长度)
|
||||||
IsRunning bool `json:"is_running"` // 是否正在运行
|
IsRunning bool `json:"is_running"` // 是否正在运行
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,11 +461,15 @@ func (c *Crawler) Run(entryURL string, maxEpoch int) {
|
|||||||
// 每轮 epoch 从 config 读取最新 workers 值,支持运行时动态调整
|
// 每轮 epoch 从 config 读取最新 workers 值,支持运行时动态调整
|
||||||
workers := config.CrawlerWorkers()
|
workers := config.CrawlerWorkers()
|
||||||
|
|
||||||
|
// 重置新链接计数器
|
||||||
|
atomic.StoreInt64(&c.newLinksCount, 0)
|
||||||
|
|
||||||
// 更新爬取状态:新一轮开始
|
// 更新爬取状态:新一轮开始
|
||||||
c.updateCrawlStatus(func(cs *CrawlStatus) {
|
c.updateCrawlStatus(func(cs *CrawlStatus) {
|
||||||
cs.CurrentEpoch = ep + 1
|
cs.CurrentEpoch = ep + 1
|
||||||
cs.QueueLength = len(queue)
|
cs.QueueLength = len(queue)
|
||||||
cs.CompletedCount = 0
|
cs.CompletedCount = 0
|
||||||
|
cs.NewLinksCount = 0
|
||||||
})
|
})
|
||||||
|
|
||||||
// 每轮开始前:拉取 priority URLs,插入队列前端
|
// 每轮开始前:拉取 priority URLs,插入队列前端
|
||||||
@@ -526,11 +534,16 @@ func (c *Crawler) Run(entryURL string, maxEpoch int) {
|
|||||||
// 分配权重
|
// 分配权重
|
||||||
w := 1.0 / float64(n)
|
w := 1.0 / float64(n)
|
||||||
|
|
||||||
// 子 URL 进入 newLinks 调度,由普通 BFS 下一轮处理。
|
// 子 URL 进入 newLinks 调度,由普通 BFS 下一轮处理。
|
||||||
// (priority worker 通过 priorityChildCh 独立爬取子 URL,两者互不干扰)
|
// (priority worker 通过 priorityChildCh 独立爬取子 URL,两者互不干扰)
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
for _, h := range children {
|
for _, h := range children {
|
||||||
newLinks = append(newLinks, URLWeight{URL: h, Weight: w})
|
newLinks = append(newLinks, URLWeight{URL: h, Weight: w})
|
||||||
|
// 实时自增计数(供前端监控)
|
||||||
|
atomic.AddInt64(&c.newLinksCount, 1)
|
||||||
|
c.updateCrawlStatus(func(cs *CrawlStatus) {
|
||||||
|
cs.NewLinksCount = atomic.LoadInt64(&c.newLinksCount)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
}(u)
|
}(u)
|
||||||
@@ -545,6 +558,10 @@ func (c *Crawler) Run(entryURL string, maxEpoch int) {
|
|||||||
select {
|
select {
|
||||||
case gc := <-c.normalChildCh:
|
case gc := <-c.normalChildCh:
|
||||||
newLinks = append(newLinks, gc)
|
newLinks = append(newLinks, gc)
|
||||||
|
atomic.AddInt64(&c.newLinksCount, 1) // 孙链接也要计入
|
||||||
|
c.updateCrawlStatus(func(cs *CrawlStatus) {
|
||||||
|
cs.NewLinksCount = atomic.LoadInt64(&c.newLinksCount)
|
||||||
|
})
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
drained = true
|
drained = true
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>SESE 爬取管理</title>
|
<title>SESE 爬取管理</title>
|
||||||
<script type="module" crossorigin src="/assets/index-yf_Ps55i.js"></script>
|
<script type="module" crossorigin src="/assets/index-G5PISGmH.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-DNzRL3Ws.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-DNzRL3Ws.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
+1
-1
Submodule sese-engine-ui updated: 63c40d69d4...558d91b0a4
Reference in New Issue
Block a user