mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 01:15:41 +08:00
check: added new config checklatencysamples
to support average latency calculating (#282)
This commit is contained in:
parent
cb698713ee
commit
fa97a44e8d
@ -93,7 +93,7 @@ glider -config CONFIG_PATH
|
||||
glider -verbose -listen :8443 -forward SCHEME://HOST:PORT
|
||||
```
|
||||
|
||||
**Show help:** `glider -help`
|
||||
**Help:** `glider -help`
|
||||
|
||||
<details>
|
||||
<summary>click to see details</summary>
|
||||
@ -222,7 +222,7 @@ glider 0.16.0, https://github.com/nadoo/glider
|
||||
|
||||
</details>
|
||||
|
||||
**Show Schemes:** `glider -scheme all`
|
||||
**Schemes:** `glider -scheme all`
|
||||
|
||||
<details>
|
||||
<summary>click to see details</summary>
|
||||
@ -337,7 +337,7 @@ TLS and Websocket with a specified proxy protocol:
|
||||
|
||||
</details>
|
||||
|
||||
**Show Examples:** `glider -example`
|
||||
**Examples:** `glider -example`
|
||||
|
||||
<details>
|
||||
<summary>click to see details</summary>
|
||||
|
@ -66,6 +66,7 @@ check=disable: disable health check`)
|
||||
flag.IntVar(&conf.Strategy.CheckInterval, "checkinterval", 30, "fowarder check interval(seconds)")
|
||||
flag.IntVar(&conf.Strategy.CheckTimeout, "checktimeout", 10, "fowarder check timeout(seconds)")
|
||||
flag.IntVar(&conf.Strategy.CheckTolerance, "checktolerance", 0, "fowarder check tolerance(ms), switch only when new_latency < old_latency - tolerance, only used in lha mode")
|
||||
flag.IntVar(&conf.Strategy.CheckLatencySamples, "checklatencysamples", 1, "use the average latency of the latest N checks")
|
||||
flag.BoolVar(&conf.Strategy.CheckDisabledOnly, "checkdisabledonly", false, "check disabled fowarders only")
|
||||
flag.IntVar(&conf.Strategy.MaxFailures, "maxfailures", 3, "max failures to change forwarder status to disabled")
|
||||
flag.IntVar(&conf.Strategy.DialTimeout, "dialtimeout", 3, "dial timeout(seconds)")
|
||||
|
@ -24,16 +24,17 @@ type Config struct {
|
||||
|
||||
// Strategy configurations.
|
||||
type Strategy struct {
|
||||
Strategy string
|
||||
Check string
|
||||
CheckInterval int
|
||||
CheckTimeout int
|
||||
CheckTolerance int
|
||||
CheckDisabledOnly bool
|
||||
MaxFailures int
|
||||
DialTimeout int
|
||||
RelayTimeout int
|
||||
IntFace string
|
||||
Strategy string
|
||||
Check string
|
||||
CheckInterval int
|
||||
CheckTimeout int
|
||||
CheckTolerance int
|
||||
CheckLatencySamples int
|
||||
CheckDisabledOnly bool
|
||||
MaxFailures int
|
||||
DialTimeout int
|
||||
RelayTimeout int
|
||||
IntFace string
|
||||
}
|
||||
|
||||
// NewConfFromFile returns a new config from file.
|
||||
@ -46,6 +47,7 @@ func NewConfFromFile(ruleFile string) (*Config, error) {
|
||||
f.StringVar(&p.Strategy.Check, "check", "http://www.msftconnecttest.com/connecttest.txt#expect=200", "check=tcp[://HOST:PORT]: tcp port connect check\ncheck=http://HOST[:PORT][/URI][#expect=STRING_IN_RESP_LINE]\ncheck=file://SCRIPT_PATH: run a check script, healthy when exitcode=0, environment variables: FORWARDER_ADDR\ncheck=disable: disable health check")
|
||||
f.IntVar(&p.Strategy.CheckInterval, "checkinterval", 30, "fowarder check interval(seconds)")
|
||||
f.IntVar(&p.Strategy.CheckTimeout, "checktimeout", 10, "fowarder check timeout(seconds)")
|
||||
f.IntVar(&p.Strategy.CheckLatencySamples, "checklatencysamples", 1, "use the average latency of the latest N checks")
|
||||
f.IntVar(&p.Strategy.CheckTolerance, "checktolerance", 0, "fowarder check tolerance(ms), switch only when new_latency < old_latency - tolerance, only used in lha mode")
|
||||
f.BoolVar(&p.Strategy.CheckDisabledOnly, "checkdisabledonly", false, "check disabled fowarders only")
|
||||
f.IntVar(&p.Strategy.MaxFailures, "maxfailures", 3, "max failures to change forwarder status to disabled")
|
||||
|
@ -266,13 +266,23 @@ func (p *FwdrGroup) check(fwdr *Forwarder, checker Checker) {
|
||||
}
|
||||
|
||||
wait = 1
|
||||
fwdr.SetLatency(int64(elapsed))
|
||||
log.F("[check] %s: %s(%d), SUCCESS. elapsed: %s",
|
||||
p.name, fwdr.Addr(), fwdr.Priority(), elapsed)
|
||||
p.setLatency(fwdr, elapsed)
|
||||
log.F("[check] %s: %s(%d), SUCCESS. elapsed: %s, Latency: %s",
|
||||
p.name, fwdr.Addr(), fwdr.Priority(), elapsed, time.Duration(fwdr.Latency()))
|
||||
fwdr.Enable()
|
||||
}
|
||||
}
|
||||
|
||||
func (p *FwdrGroup) setLatency(fwdr *Forwarder, elapsed time.Duration) {
|
||||
newLatency := int64(elapsed)
|
||||
if cnt := p.config.CheckLatencySamples; cnt > 1 {
|
||||
if lastLagency := fwdr.Latency(); lastLagency > 0 {
|
||||
newLatency = (lastLagency*(int64(cnt)-1) + int64(elapsed)) / int64(cnt)
|
||||
}
|
||||
}
|
||||
fwdr.SetLatency(newLatency)
|
||||
}
|
||||
|
||||
// Round Robin.
|
||||
func (p *FwdrGroup) scheduleRR(dstAddr string) *Forwarder {
|
||||
return p.avail[atomic.AddUint32(&p.index, 1)%uint32(len(p.avail))]
|
||||
|
Loading…
Reference in New Issue
Block a user