Add feature: scale from zero to 1 replicas

This change allows functions to be "idled" or scaled to zero
replicas and then be invoked later on. There is a penalty to
scaling up - the API gateway proxy will block until the function
is ready.

A cache is included to off-set the calls to upstream API to check
on readiness along with unit tests.

Testing via scaling to zero replicas and then invoking function.
On Swarm I observed 3 seconds on an Intel Nuc i5 for scaling back
from zero replicas.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (VMware)
2018-05-14 17:26:44 +01:00
committed by Alex Ellis
parent 31810a4cf2
commit e67d45caa1
4 changed files with 288 additions and 2 deletions

View File

@ -113,10 +113,18 @@ func main() {
}
r := mux.NewRouter()
// max wait time to start a function = maxPollCount * functionPollInterval
scalingConfig := handlers.ScalingConfig{
MaxPollCount: uint(1000),
FunctionPollInterval: time.Millisecond * 10,
CacheExpiry: time.Second * 5, // freshness of replica values before going stale
}
scalingProxy := handlers.MakeScalingHandler(faasHandlers.Proxy, queryFunction, scalingConfig)
// r.StrictSlash(false) // This didn't work, so register routes twice.
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", faasHandlers.Proxy)
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.Proxy)
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", scalingProxy)
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", scalingProxy)
r.HandleFunc("/system/info", handlers.MakeInfoHandler(handlers.MakeForwardingProxyHandler(
reverseProxy, forwardingNotifiers, urlResolver))).Methods(http.MethodGet)