forked from TrueCloudLab/frostfs-node
[#1157] network/cache: Optimize client
fetch from multiClient
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
a4261243fc
commit
2a69aaf976
1 changed files with 11 additions and 6 deletions
11
pkg/network/cache/multi.go
vendored
11
pkg/network/cache/multi.go
vendored
|
@ -235,16 +235,21 @@ func (x *multiClient) RawForAddress(addr network.Address, f func(client *rawclie
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *multiClient) client(addr network.Address) clientcore.Client {
|
func (x *multiClient) client(addr network.Address) clientcore.Client {
|
||||||
x.mtx.Lock()
|
|
||||||
|
|
||||||
strAddr := addr.String()
|
strAddr := addr.String()
|
||||||
|
|
||||||
|
x.mtx.RLock()
|
||||||
c, cached := x.clients[strAddr]
|
c, cached := x.clients[strAddr]
|
||||||
|
x.mtx.RUnlock()
|
||||||
|
|
||||||
|
if !cached {
|
||||||
|
x.mtx.Lock()
|
||||||
|
|
||||||
|
c, cached = x.clients[strAddr]
|
||||||
if !cached {
|
if !cached {
|
||||||
c = x.createForAddress(addr)
|
c = x.createForAddress(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mtx.Unlock()
|
x.mtx.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue