From 5405dedd2e1b9e14c9cd4e8bd01e2975e60873c3 Mon Sep 17 00:00:00 2001 From: bigsheeper Date: Wed, 28 Sep 2022 20:58:54 +0800 Subject: [PATCH] Fix DDL rate limit unit, and improve log (#19504) Signed-off-by: bigsheeper Signed-off-by: bigsheeper --- configs/milvus.yaml | 4 ++-- internal/proxy/multi_rate_limiter.go | 2 +- internal/util/paramtable/quota_param.go | 8 ++++++++ internal/util/ratelimitutil/limiter.go | 9 +++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/configs/milvus.yaml b/configs/milvus.yaml index efe4f7cf92..fbf97dfebf 100644 --- a/configs/milvus.yaml +++ b/configs/milvus.yaml @@ -403,8 +403,8 @@ quotaAndLimits: dql: enabled: false searchRate: - max: # vps, default no limit - min: # vps, default 0 + max: # vps (vectors per second), default no limit + min: # vps (vectors per second), default 0 queryRate: max: # qps, default no limit min: # qps, default 0 diff --git a/internal/proxy/multi_rate_limiter.go b/internal/proxy/multi_rate_limiter.go index 49986c258d..ee0e39090b 100644 --- a/internal/proxy/multi_rate_limiter.go +++ b/internal/proxy/multi_rate_limiter.go @@ -124,7 +124,7 @@ func (rl *rateLimiter) registerLimiters() { } log.Info("RateLimiter register for rateType", zap.String("rateType", internalpb.RateType_name[rt]), - zap.Float64("rate", r)) + zap.String("rate", ratelimitutil.Limit(r).String())) limit := ratelimitutil.Limit(r) if limit < 0 { limit = ratelimitutil.Inf diff --git a/internal/util/paramtable/quota_param.go b/internal/util/paramtable/quota_param.go index a001867a04..948513864e 100644 --- a/internal/util/paramtable/quota_param.go +++ b/internal/util/paramtable/quota_param.go @@ -35,6 +35,9 @@ const ( defaultLowWaterLevel = float64(0.8) // defaultHighWaterLevel is the default memory low water level. defaultHighWaterLevel = float64(0.9) + + // secondsPerMinute is used to convert minutes to seconds. + secondsPerMinute = 60.0 ) // quotaConfig is configuration for quota and limitations. @@ -164,6 +167,7 @@ func (p *quotaConfig) initDDLCollectionRate() { return } p.DDLCollectionRate = p.Base.ParseFloatWithDefault("quotaAndLimits.ddl.collectionRate", defaultMax) + p.DDLCollectionRate /= secondsPerMinute // [0 ~ Inf) if p.DDLCollectionRate < 0 { p.DDLCollectionRate = defaultMax @@ -176,6 +180,7 @@ func (p *quotaConfig) initDDLPartitionRate() { return } p.DDLPartitionRate = p.Base.ParseFloatWithDefault("quotaAndLimits.ddl.partitionRate", defaultMax) + p.DDLPartitionRate /= secondsPerMinute // [0 ~ Inf) if p.DDLPartitionRate < 0 { p.DDLPartitionRate = defaultMax @@ -188,6 +193,7 @@ func (p *quotaConfig) initDDLIndexRate() { return } p.DDLIndexRate = p.Base.ParseFloatWithDefault("quotaAndLimits.ddl.indexRate", defaultMax) + p.DDLIndexRate /= secondsPerMinute // [0 ~ Inf) if p.DDLIndexRate < 0 { p.DDLIndexRate = defaultMax @@ -200,6 +206,7 @@ func (p *quotaConfig) initDDLFlushRate() { return } p.DDLFlushRate = p.Base.ParseFloatWithDefault("quotaAndLimits.ddl.flushRate", defaultMax) + p.DDLFlushRate /= secondsPerMinute // [0 ~ Inf) if p.DDLFlushRate < 0 { p.DDLFlushRate = defaultMax @@ -212,6 +219,7 @@ func (p *quotaConfig) initDDLCompactionRate() { return } p.DDLCompactionRate = p.Base.ParseFloatWithDefault("quotaAndLimits.ddl.compactionRate", defaultMax) + p.DDLCompactionRate /= secondsPerMinute // [0 ~ Inf) if p.DDLCompactionRate < 0 { p.DDLCompactionRate = defaultMax diff --git a/internal/util/ratelimitutil/limiter.go b/internal/util/ratelimitutil/limiter.go index e09c338bc0..f61cfcc7ab 100644 --- a/internal/util/ratelimitutil/limiter.go +++ b/internal/util/ratelimitutil/limiter.go @@ -17,6 +17,7 @@ package ratelimitutil import ( + "fmt" "math" "sync" "time" @@ -132,6 +133,14 @@ func (lim *Limiter) advance(now time.Time) (newNow time.Time, newLast time.Time, return now, last, tokens } +// String returns string of Limit. +func (limit Limit) String() string { + if limit == Inf { + return "+inf" + } + return fmt.Sprintf("%.4f", limit) +} + // tokensFromDuration is a unit conversion function from a time duration to the number of tokens // which could be accumulated during that duration at a rate of limit tokens per second. func (limit Limit) tokensFromDuration(d time.Duration) float64 {