mirror of https://github.com/milvus-io/milvus.git
enhance: Cache formatted key for param item (#31388)
See also #30806 `formatKey` may cost lots of CPU on string processing under high QPS scenario, this PR adds a formattedKeys cache preventing string operation in each param get value. --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>pull/30936/head
parent
8e293dc1ce
commit
74b7de3814
|
@ -20,6 +20,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
|
||||
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -51,6 +53,14 @@ func Init(opts ...Option) (*Manager, error) {
|
|||
return sourceManager, nil
|
||||
}
|
||||
|
||||
var formattedKeys = typeutil.NewConcurrentMap[string, string]()
|
||||
|
||||
func formatKey(key string) string {
|
||||
return strings.NewReplacer("/", "", "_", "", ".", "").Replace(strings.ToLower(key))
|
||||
cached, ok := formattedKeys.Get(key)
|
||||
if ok {
|
||||
return cached
|
||||
}
|
||||
result := strings.NewReplacer("/", "", "_", "", ".", "").Replace(strings.ToLower(key))
|
||||
formattedKeys.Insert(key, result)
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue