mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 01:28:27 +08:00
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>
This commit is contained in:
parent
8e293dc1ce
commit
74b7de3814
@ -20,6 +20,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/cockroachdb/errors"
|
"github.com/cockroachdb/errors"
|
||||||
|
|
||||||
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -51,6 +53,14 @@ func Init(opts ...Option) (*Manager, error) {
|
|||||||
return sourceManager, nil
|
return sourceManager, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var formattedKeys = typeutil.NewConcurrentMap[string, string]()
|
||||||
|
|
||||||
func formatKey(key 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…
x
Reference in New Issue
Block a user