Reduce contention

This commit is contained in:
Frank Denis 2019-10-21 18:50:20 +02:00
parent a0614510e9
commit 3ddb134190
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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