Read config values from environment for max_conns tuning

- max_conns / idle / per host are now read from env-vars and have
defaults set to 1024 for both values
- logging / metrics are collected in the client transaction
rather than via defer (this may impact throughput)
- function cache moved to use RWMutex to try to improve latency
around locking when updating cache
- logging message added to show latency in running GetReplicas
because this was observed to increase in a linear fashion under
high concurrency
- changes tested against 3-node bare-metal 1.13 K8s cluster
with kubeadm

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (VMware)
2019-01-22 15:59:32 +00:00
committed by Alex Ellis
parent 52c27e227a
commit 299e5a5933
7 changed files with 98 additions and 22 deletions

View File

@ -25,7 +25,7 @@ func (fm *FunctionMeta) Expired(expiry time.Duration) bool {
type FunctionCache struct {
Cache map[string]*FunctionMeta
Expiry time.Duration
Sync sync.Mutex
Sync sync.RWMutex
}
// Set replica count for functionName
@ -37,23 +37,22 @@ func (fc *FunctionCache) Set(functionName string, serviceQueryResponse ServiceQu
fc.Cache[functionName] = &FunctionMeta{}
}
entry := fc.Cache[functionName]
entry.LastRefresh = time.Now()
entry.ServiceQueryResponse = serviceQueryResponse
fc.Cache[functionName].LastRefresh = time.Now()
fc.Cache[functionName].ServiceQueryResponse = serviceQueryResponse
// entry.LastRefresh = time.Now()
// entry.ServiceQueryResponse = serviceQueryResponse
}
// Get replica count for functionName
func (fc *FunctionCache) Get(functionName string) (ServiceQueryResponse, bool) {
fc.Sync.Lock()
defer fc.Sync.Unlock()
replicas := ServiceQueryResponse{
AvailableReplicas: 0,
}
hit := false
fc.Sync.RLock()
defer fc.Sync.RUnlock()
if val, exists := fc.Cache[functionName]; exists {
replicas = val.ServiceQueryResponse
hit = !val.Expired(fc.Expiry)