From 875b19b2b4660d02881da5a2e843d95fb040987b Mon Sep 17 00:00:00 2001 From: hexoscott <70711990+hexoscott@users.noreply.github.com> Date: Tue, 8 Nov 2022 16:20:47 +0000 Subject: [PATCH] switch to standard lock to help cache perf (#730) --- kv/kvcache/cache.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kv/kvcache/cache.go b/kv/kvcache/cache.go index d84a8fdb1..25d93703f 100644 --- a/kv/kvcache/cache.go +++ b/kv/kvcache/cache.go @@ -358,8 +358,10 @@ func (c *Coherent) View(ctx context.Context, tx kv.Tx) (CacheView, error) { } func (c *Coherent) getFromCache(k []byte, id uint64, code bool) (*Element, *CoherentRoot, error) { - c.lock.RLock() - defer c.lock.RUnlock() + // using the full lock here rather than RLock as RLock causes a lot of calls to runtime.usleep degrading + // performance under load + c.lock.Lock() + defer c.lock.Unlock() r, ok := c.roots[id] if !ok { return nil, r, fmt.Errorf("too old ViewID: %d, latestStateVersionID=%d", id, c.latestStateVersionID)