mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 20:46:41 +00:00
Make use of cache in scaling
- this reinstates the cache to reduce the count of lookups to the provider when checking if scaling is needed. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
117707df14
commit
b4c12f824b
@ -38,6 +38,17 @@ type FunctionScaleResult struct {
|
|||||||
// the minimum replicas metadata
|
// the minimum replicas metadata
|
||||||
func (f *FunctionScaler) Scale(functionName string) FunctionScaleResult {
|
func (f *FunctionScaler) Scale(functionName string) FunctionScaleResult {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
if cachedResponse, hit := f.Cache.Get(functionName); hit &&
|
||||||
|
cachedResponse.AvailableReplicas > 0 {
|
||||||
|
return FunctionScaleResult{
|
||||||
|
Error: nil,
|
||||||
|
Available: true,
|
||||||
|
Found: true,
|
||||||
|
Duration: time.Since(start),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
queryResponse, err := f.Config.ServiceQuery.GetReplicas(functionName)
|
queryResponse, err := f.Config.ServiceQuery.GetReplicas(functionName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,7 +101,9 @@ func (f *FunctionScaler) Scale(functionName string) FunctionScaleResult {
|
|||||||
|
|
||||||
for i := 0; i < int(f.Config.MaxPollCount); i++ {
|
for i := 0; i < int(f.Config.MaxPollCount); i++ {
|
||||||
queryResponse, err := f.Config.ServiceQuery.GetReplicas(functionName)
|
queryResponse, err := f.Config.ServiceQuery.GetReplicas(functionName)
|
||||||
f.Cache.Set(functionName, queryResponse)
|
if err == nil {
|
||||||
|
f.Cache.Set(functionName, queryResponse)
|
||||||
|
}
|
||||||
totalTime := time.Since(start)
|
totalTime := time.Since(start)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -104,7 +117,8 @@ func (f *FunctionScaler) Scale(functionName string) FunctionScaleResult {
|
|||||||
|
|
||||||
if queryResponse.AvailableReplicas > 0 {
|
if queryResponse.AvailableReplicas > 0 {
|
||||||
|
|
||||||
log.Printf("[Scale] function=%s 0 => %d successful - %f seconds", functionName, queryResponse.AvailableReplicas, totalTime.Seconds())
|
log.Printf("[Scale] function=%s 0 => %d successful - %f seconds",
|
||||||
|
functionName, queryResponse.AvailableReplicas, totalTime.Seconds())
|
||||||
|
|
||||||
return FunctionScaleResult{
|
return FunctionScaleResult{
|
||||||
Error: nil,
|
Error: nil,
|
||||||
|
Reference in New Issue
Block a user