mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-12 16:26:37 +00:00
discosrv: Tunable limiter settings
This commit is contained in:
parent
f97dd9d8d3
commit
fee8289c0a
@ -40,7 +40,10 @@ var (
|
|||||||
limited = 0
|
limited = 0
|
||||||
unknowns = 0
|
unknowns = 0
|
||||||
debug = false
|
debug = false
|
||||||
limiter = lru.New(1024)
|
lruSize = 1024
|
||||||
|
limitAvg = 1
|
||||||
|
limitBurst = 10
|
||||||
|
limiter *lru.Cache
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -54,8 +57,13 @@ func main() {
|
|||||||
flag.BoolVar(×tamp, "timestamp", true, "Timestamp the log output")
|
flag.BoolVar(×tamp, "timestamp", true, "Timestamp the log output")
|
||||||
flag.IntVar(&statsIntv, "stats-intv", 0, "Statistics output interval (s)")
|
flag.IntVar(&statsIntv, "stats-intv", 0, "Statistics output interval (s)")
|
||||||
flag.StringVar(&statsFile, "stats-file", "/var/log/discosrv.stats", "Statistics file name")
|
flag.StringVar(&statsFile, "stats-file", "/var/log/discosrv.stats", "Statistics file name")
|
||||||
|
flag.IntVar(&lruSize, "limit-cache", lruSize, "Limiter cache entries")
|
||||||
|
flag.IntVar(&limitAvg, "limit-avg", limitAvg, "Allowed average package rate, per 10 s")
|
||||||
|
flag.IntVar(&limitBurst, "limit-burst", limitBurst, "Allowed burst size, packets")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
limiter = lru.New(lruSize)
|
||||||
|
|
||||||
log.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
if !timestamp {
|
if !timestamp {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
@ -130,7 +138,7 @@ func limit(addr *net.UDPAddr) bool {
|
|||||||
log.Println("New limiter for", key)
|
log.Println("New limiter for", key)
|
||||||
}
|
}
|
||||||
// One packet per ten seconds average rate, burst ten packets
|
// One packet per ten seconds average rate, burst ten packets
|
||||||
limiter.Add(key, ratelimit.NewBucket(10*time.Second, 10))
|
limiter.Add(key, ratelimit.NewBucket(10*time.Second/time.Duration(limitAvg), int64(limitBurst)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user