mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Add concurrency option for outbound observation
Add `enableConcurrency` option, false by default. If it's set as `true`, start probing outbounds concurrently in every circle of observation. Wait `probeInterval` between observation circles.
This commit is contained in:
parent
abb8ba8b0e
commit
28b17b529d
2 changed files with 38 additions and 14 deletions
|
@ -66,22 +66,45 @@ func (o *Observer) background() {
|
|||
}
|
||||
|
||||
outbounds := hs.Select(o.config.SubjectSelector)
|
||||
sort.Strings(outbounds)
|
||||
|
||||
o.updateStatus(outbounds)
|
||||
|
||||
sleepTime := time.Second * 10
|
||||
if o.config.ProbeInterval != 0 {
|
||||
sleepTime = time.Duration(o.config.ProbeInterval)
|
||||
}
|
||||
|
||||
if !o.config.EnableConcurrency {
|
||||
sort.Strings(outbounds)
|
||||
for _, v := range outbounds {
|
||||
result := o.probe(v)
|
||||
o.updateStatusForResult(v, &result)
|
||||
if o.finished.Done() {
|
||||
return
|
||||
}
|
||||
time.Sleep(sleepTime)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
ch := make(chan struct{}, len(outbounds))
|
||||
|
||||
for _, v := range outbounds {
|
||||
result := o.probe(v)
|
||||
o.updateStatusForResult(v, &result)
|
||||
if o.finished.Done() {
|
||||
go func(v string) {
|
||||
result := o.probe(v)
|
||||
o.updateStatusForResult(v, &result)
|
||||
ch <- struct{}{}
|
||||
}(v)
|
||||
}
|
||||
|
||||
for range outbounds {
|
||||
select {
|
||||
case <-ch:
|
||||
case <-o.finished.Wait():
|
||||
return
|
||||
}
|
||||
sleepTime := time.Second * 10
|
||||
if o.config.ProbeInterval != 0 {
|
||||
sleepTime = time.Duration(o.config.ProbeInterval)
|
||||
}
|
||||
time.Sleep(sleepTime)
|
||||
}
|
||||
time.Sleep(sleepTime)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue