Reduce contention
This commit is contained in:
parent
a0614510e9
commit
3ddb134190
|
@ -65,14 +65,15 @@ func (plugin *PluginCacheResponse) Eval(pluginsState *PluginsState, msg *dns.Msg
|
|||
msg: *msg,
|
||||
}
|
||||
plugin.cachedResponses.Lock()
|
||||
defer plugin.cachedResponses.Unlock()
|
||||
if plugin.cachedResponses.cache == nil {
|
||||
plugin.cachedResponses.cache, err = lru.NewARC(pluginsState.cacheSize)
|
||||
if err != nil {
|
||||
plugin.cachedResponses.Unlock()
|
||||
return err
|
||||
}
|
||||
}
|
||||
plugin.cachedResponses.cache.Add(cacheKey, cachedResponse)
|
||||
plugin.cachedResponses.Unlock()
|
||||
updateTTL(msg, cachedResponse.expiration)
|
||||
|
||||
return nil
|
||||
|
|
|
@ -191,9 +191,9 @@ func (serversInfo *ServersInfo) estimatorUpdate() {
|
|||
|
||||
func (serversInfo *ServersInfo) getOne() *ServerInfo {
|
||||
serversInfo.Lock()
|
||||
defer serversInfo.Unlock()
|
||||
serversCount := len(serversInfo.inner)
|
||||
if serversCount <= 0 {
|
||||
serversInfo.Unlock()
|
||||
return nil
|
||||
}
|
||||
if serversInfo.lbEstimator {
|
||||
|
@ -211,6 +211,7 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
|
|||
candidate = rand.Intn(Min(serversCount, 2))
|
||||
}
|
||||
serverInfo := serversInfo.inner[candidate]
|
||||
serversInfo.Unlock()
|
||||
dlog.Debugf("Using candidate [%s] RTT: %d", (*serverInfo).Name, int((*serverInfo).rtt.Value()))
|
||||
|
||||
return serverInfo
|
||||
|
|
Loading…
Reference in New Issue