Serve only one request and garbage collect (#1978)
Adding once only execution pattern to pool manager based functions. This is for use cases where you don't want to share the samne pod for another execution instance!
This commit is contained in:
@@ -357,6 +357,10 @@ type (
|
||||
// RequestsPerPod indicates the maximum number of concurrent requests that can be served by a specialized pod
|
||||
// This is optional. If not specified default value will be taken as 1
|
||||
RequestsPerPod int `json:"requestsPerPod,omitempty"`
|
||||
|
||||
// OnceOnly specifies if specialized pod will serve exactly one request in its lifetime and would be garbage collected after serving that one request
|
||||
// This is optional. If not specified default value will be taken as false
|
||||
OnceOnly bool `json:"onceOnly,omitempty"`
|
||||
}
|
||||
|
||||
// InvokeStrategy is a set of controls over how the function executes.
|
||||
|
||||
@@ -53,6 +53,10 @@ var (
|
||||
Type: "integer",
|
||||
Description: "RequestsPerPod indicates the maximum number of concurrent requests that can be served by a specialized pod.\n This is optional. If not specified default value will be taken as 1",
|
||||
},
|
||||
"onceOnly": {
|
||||
Type: "boolean",
|
||||
Description: "OnceOnly specifies if specialized pod will serve exactly one request in its lifetime and would be garbage collected after serving that one request.\nThis is optional. If not specified default value will be taken as false",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
+2
-2
@@ -56,7 +56,7 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
|
||||
executor.logger.Debug("checking for cached function service",
|
||||
zap.String("function_name", fn.ObjectMeta.Name),
|
||||
zap.String("function_namespace", fn.ObjectMeta.Namespace))
|
||||
if t == fv1.ExecutorTypePoolmgr {
|
||||
if t == fv1.ExecutorTypePoolmgr && !fn.Spec.OnceOnly {
|
||||
concurrency := fn.Spec.Concurrency
|
||||
if concurrency == 0 {
|
||||
concurrency = 500
|
||||
@@ -90,7 +90,7 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
|
||||
http.Error(w, errMsg, http.StatusTooManyRequests)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
} else if t == fv1.ExecutorTypeNewdeploy {
|
||||
fsvc, err := et.GetFuncSvcFromCache(fn)
|
||||
if err == nil {
|
||||
if et.IsValid(fsvc) {
|
||||
|
||||
@@ -36,6 +36,7 @@ func Commands() *cobra.Command {
|
||||
flag.FnExecutorType, flag.FnCfgMap, flag.FnSecret,
|
||||
flag.FnSpecializationTimeout, flag.FnExecutionTimeout,
|
||||
flag.FnIdleTimeout, flag.FnConcurrency, flag.FnRequestsPerPod,
|
||||
flag.FnOnceOnly,
|
||||
|
||||
// TODO retired pkg & trigger related flags from function cmd
|
||||
flag.PkgCode, flag.PkgSrcArchive, flag.PkgDeployArchive,
|
||||
@@ -87,6 +88,7 @@ func Commands() *cobra.Command {
|
||||
flag.FnExecutorType, flag.FnSecret, flag.FnCfgMap,
|
||||
flag.FnSpecializationTimeout, flag.FnExecutionTimeout,
|
||||
flag.FnIdleTimeout, flag.FnConcurrency, flag.FnRequestsPerPod,
|
||||
flag.FnOnceOnly,
|
||||
|
||||
flag.PkgCode, flag.PkgSrcArchive, flag.PkgDeployArchive,
|
||||
flag.PkgSrcChecksum, flag.PkgDeployChecksum, flag.PkgInsecure,
|
||||
|
||||
@@ -104,6 +104,8 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
requestsPerPod := input.Int(flagkey.FnRequestsPerPod)
|
||||
|
||||
fnOnceOnly := input.Bool(flagkey.FnOnceOnly)
|
||||
|
||||
pkgName := input.String(flagkey.FnPackageName)
|
||||
|
||||
secretNames := input.StringSlice(flagkey.FnSecret)
|
||||
@@ -304,6 +306,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
IdleTimeout: &fnIdleTimeout,
|
||||
Concurrency: fnConcurrency,
|
||||
RequestsPerPod: requestsPerPod,
|
||||
OnceOnly: fnOnceOnly,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +163,9 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
function.Spec.RequestsPerPod = input.Int(flagkey.FnRequestsPerPod)
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.FnOnceOnly) {
|
||||
function.Spec.OnceOnly = input.Bool(flagkey.FnOnceOnly)
|
||||
}
|
||||
if len(pkgName) == 0 {
|
||||
pkgName = function.Spec.Package.PackageRef.Name
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ var (
|
||||
FnIdleTimeout = Flag{Type: Int, Name: flagkey.FnIdleTimeout, Usage: "The length of time (in seconds) that a function is idle before pod(s) are eligible for recycling", DefaultValue: 120}
|
||||
FnConcurrency = Flag{Type: Int, Name: flagkey.FnConcurrency, Aliases: []string{"con"}, Usage: "Maximum number of pods specialized concurrently to serve requests", DefaultValue: 500}
|
||||
FnRequestsPerPod = Flag{Type: Int, Name: flagkey.FnRequestsPerPod, Aliases: []string{"rpp"}, Usage: "Maximum number of concurrent requests that can be served by a specialized pod", DefaultValue: 1}
|
||||
FnOnceOnly = Flag{Type: Bool, Name: flagkey.FnOnceOnly, Aliases: []string{"yolo"}, Usage: "Specifies if specialized pod will serve exactly one request in its lifetime"}
|
||||
|
||||
HtName = Flag{Type: String, Name: flagkey.HtName, Usage: "HTTP trigger name"}
|
||||
HtMethod = Flag{Type: String, Name: flagkey.HtMethod, Usage: "HTTP Method: GET|POST|PUT|DELETE|HEAD", DefaultValue: http.MethodGet}
|
||||
|
||||
@@ -65,6 +65,7 @@ const (
|
||||
FnIdleTimeout = "idletimeout"
|
||||
FnConcurrency = "concurrency"
|
||||
FnRequestsPerPod = "requestsperpod"
|
||||
FnOnceOnly = "onceonly"
|
||||
|
||||
HtName = resourceName
|
||||
HtMethod = "method"
|
||||
|
||||
Reference in New Issue
Block a user