mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 00:21:29 +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
|
@ -66,22 +66,45 @@ func (o *Observer) background() {
|
||||||
}
|
}
|
||||||
|
|
||||||
outbounds := hs.Select(o.config.SubjectSelector)
|
outbounds := hs.Select(o.config.SubjectSelector)
|
||||||
sort.Strings(outbounds)
|
|
||||||
|
|
||||||
o.updateStatus(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 {
|
for _, v := range outbounds {
|
||||||
result := o.probe(v)
|
go func(v string) {
|
||||||
o.updateStatusForResult(v, &result)
|
result := o.probe(v)
|
||||||
if o.finished.Done() {
|
o.updateStatusForResult(v, &result)
|
||||||
|
ch <- struct{}{}
|
||||||
|
}(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
for range outbounds {
|
||||||
|
select {
|
||||||
|
case <-ch:
|
||||||
|
case <-o.finished.Wait():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sleepTime := time.Second * 10
|
|
||||||
if o.config.ProbeInterval != 0 {
|
|
||||||
sleepTime = time.Duration(o.config.ProbeInterval)
|
|
||||||
}
|
|
||||||
time.Sleep(sleepTime)
|
|
||||||
}
|
}
|
||||||
|
time.Sleep(sleepTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,18 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/app/observatory"
|
"github.com/xtls/xray-core/app/observatory"
|
||||||
"github.com/xtls/xray-core/infra/conf/cfgcommon/duration"
|
"github.com/xtls/xray-core/infra/conf/cfgcommon/duration"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ObservatoryConfig struct {
|
type ObservatoryConfig struct {
|
||||||
SubjectSelector []string `json:"subjectSelector"`
|
SubjectSelector []string `json:"subjectSelector"`
|
||||||
ProbeURL string `json:"probeURL"`
|
ProbeURL string `json:"probeURL"`
|
||||||
ProbeInterval duration.Duration `json:"probeInterval"`
|
ProbeInterval duration.Duration `json:"probeInterval"`
|
||||||
|
EnableConcurrency bool `json:"enableConcurrency"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ObservatoryConfig) Build() (proto.Message, error) {
|
func (o *ObservatoryConfig) Build() (proto.Message, error) {
|
||||||
return &observatory.Config{SubjectSelector: o.SubjectSelector, ProbeUrl: o.ProbeURL, ProbeInterval: int64(o.ProbeInterval)}, nil
|
return &observatory.Config{SubjectSelector: o.SubjectSelector, ProbeUrl: o.ProbeURL, ProbeInterval: int64(o.ProbeInterval), EnableConcurrency: o.EnableConcurrency}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue