Skip to content

Commit aa23ef3

Browse files
committed
Setting max concurrency in Function
1 parent 4d27883 commit aa23ef3

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

internal/api/api.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,27 @@ func CreateOrUpdateFunction(c echo.Context) error {
155155

156156
// Check that the selected runtime exists
157157
if f.Runtime != container.CUSTOM_RUNTIME {
158-
_, ok := container.RuntimeToInfo[f.Runtime]
158+
runtime, ok := container.RuntimeToInfo[f.Runtime]
159159
if !ok {
160160
return c.JSON(http.StatusNotFound, "Invalid runtime.")
161161
}
162+
if f.MaxConcurrency > 1 && !runtime.ConcurrencySupported {
163+
log.Printf("Forcing max concurrency = 1 for runtime %s\n", f.Runtime)
164+
f.MaxConcurrency = 1
165+
}
166+
} else {
167+
if f.MaxConcurrency > 1 {
168+
log.Printf("Forcing max concurrency = 1 for runtime %s\n", f.Runtime)
169+
f.MaxConcurrency = 1
170+
}
171+
}
172+
173+
if f.MemoryMB < 1 {
174+
return c.String(http.StatusUnprocessableEntity, "Invalid memory limit")
175+
}
176+
177+
if f.MaxConcurrency <= 0 {
178+
f.MaxConcurrency = 1
162179
}
163180

164181
err = f.SaveToEtcd()

internal/cli/cli.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ var asyncInvocation bool
102102
var verbose bool
103103
var returnOutput bool
104104
var update bool
105+
var maxConcurrency int16
105106

106107
func Init() {
107108
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
@@ -123,6 +124,7 @@ func Init() {
123124
createCmd.Flags().StringVarP(&runtime, "runtime", "", "python38", "runtime for the function")
124125
createCmd.Flags().StringVarP(&handler, "handler", "", "", "function handler (runtime specific)")
125126
createCmd.Flags().Int64VarP(&memory, "memory", "", 128, "memory (in MB) for the function")
127+
createCmd.Flags().Int16VarP(&maxConcurrency, "max_concurrency", "C", 1, "max concurrency for the function (if supported by the runtime)")
126128
createCmd.Flags().Float64VarP(&cpuDemand, "cpu", "", 0.0, "estimated CPU demand for the function (1.0 = 1 core)")
127129
createCmd.Flags().StringVarP(&src, "src", "", "", "source for the function (single file, directory or TAR archive) (not necessary for runtime==custom)")
128130
createCmd.Flags().StringVarP(&customImage, "custom_image", "", "", "custom container image (only if runtime == 'custom')")
@@ -315,6 +317,7 @@ func create(cmd *cobra.Command, args []string) {
315317
Name: funcName,
316318
Handler: handler,
317319
Runtime: runtime,
320+
MaxConcurrency: maxConcurrency,
318321
MemoryMB: memory,
319322
CPUDemand: cpuDemand,
320323
TarFunctionCode: encoded,

internal/container/runtimes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package container
22

33
// RuntimeInfo contains information about a supported function runtime env.
44
type RuntimeInfo struct {
5-
Image string
6-
InvocationCmd []string
5+
Image string
6+
InvocationCmd []string
7+
ConcurrencySupported bool
78
}
89

910
const CUSTOM_RUNTIME = "custom"
1011

1112
var refreshedImages = map[string]bool{}
1213

1314
var RuntimeToInfo = map[string]RuntimeInfo{
14-
"python310": {"grussorusso/serverledge-python310", []string{"python", "/entrypoint.py"}},
15-
// "nodejs17": {"grussorusso/serverledge-nodejs17", []string{"node", "/entrypoint.js"}},
16-
"nodejs17ng": {"grussorusso/serverledge-nodejs17ng", []string{}},
15+
"python310": {"grussorusso/serverledge-python310", []string{"python", "/entrypoint.py"}, true},
16+
"nodejs17ng": {"grussorusso/serverledge-nodejs17ng", []string{}, false},
1717
}

internal/function/function.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Function struct {
1818
Runtime string // example: python310
1919
MemoryMB int64 // MB
2020
CPUDemand float64 // 1.0 -> 1 core
21+
MaxConcurrency int16 // intra-container maximum concurrency
2122
Handler string // example: "module.function_name"
2223
TarFunctionCode string // input is .tar
2324
CustomImage string // used if custom runtime is chosen

0 commit comments

Comments
 (0)