discosrv: Tunable limiter settings

This commit is contained in:
Jakob Borg 2014-06-27 22:39:03 +02:00
parent f97dd9d8d3
commit fee8289c0a

View File

@ -40,7 +40,10 @@ var (
limited = 0
unknowns = 0
debug = false
limiter = lru.New(1024)
lruSize = 1024
limitAvg = 1
limitBurst = 10
limiter *lru.Cache
)
func main() {
@ -54,8 +57,13 @@ func main() {
flag.BoolVar(&timestamp, "timestamp", true, "Timestamp the log output")
flag.IntVar(&statsIntv, "stats-intv", 0, "Statistics output interval (s)")
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()
limiter = lru.New(lruSize)
log.SetOutput(os.Stdout)
if !timestamp {
log.SetFlags(0)
@ -130,7 +138,7 @@ func limit(addr *net.UDPAddr) bool {
log.Println("New limiter for", key)
}
// 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