mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 20:16:37 +00:00
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:
committed by
Alex Ellis
parent
31810a4cf2
commit
e67d45caa1
@ -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)
|
||||
|
Reference in New Issue
Block a user