Skip to content

Commit

Permalink
fix memory padding when requests and limits are equal
Browse files Browse the repository at this point in the history
  • Loading branch information
freeznet committed Sep 20, 2023
1 parent 7a441b6 commit 9703fe3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,15 @@ func getPythonSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef) []str
return ret
}

func calcInstanceMemoryResources(resources corev1.ResourceRequirements) string {
if resources.Requests.Memory() == resources.Limits.Memory() {
// if request and limit are the same, use the value * 0.9 as the instance (JVM) memory size, to prevent OOM
return getDecimalSIMemory(resource.NewQuantity(int64(float64(resources.Requests.Memory().Value())*0.9), resource.DecimalSI))
}
// if request and limit are different, use the request value as the instance (JVM) memory size
return getDecimalSIMemory(resources.Requests.Memory())
}

// Java command requires memory values in resource.DecimalSI format
func getDecimalSIMemory(quantity *resource.Quantity) string {
if quantity.Format == resource.DecimalSI {
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
generateJavaLogConfigCommand(spec.Java, spec.LogTopicAgent),
parseJavaLogLevel(spec.Java),
generateFunctionDetailsInJSON(function),
getDecimalSIMemory(spec.Resources.Requests.Memory()), spec.Java.ExtraDependenciesDir,
calcInstanceMemoryResources(spec.Resources), spec.Java.ExtraDependenciesDir,
string(function.UID),
spec.Java.JavaOpts, hasPulsarctl, hasWget,
spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func MakeSinkCommand(sink *v1alpha1.Sink) []string {
generateJavaLogConfigCommand(spec.Java, spec.LogTopicAgent),
parseJavaLogLevel(spec.Java),
generateSinkDetailsInJSON(sink),
getDecimalSIMemory(spec.Resources.Requests.Memory()), spec.Java.ExtraDependenciesDir, string(sink.UID),
calcInstanceMemoryResources(spec.Resources), spec.Java.ExtraDependenciesDir, string(sink.UID),
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
generateJavaLogConfigFileName(spec.Java))
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func makeSourceCommand(source *v1alpha1.Source) []string {
generateJavaLogConfigCommand(spec.Java, spec.LogTopicAgent),
parseJavaLogLevel(spec.Java),
generateSourceDetailsInJSON(source),
getDecimalSIMemory(spec.Resources.Requests.Memory()), spec.Java.ExtraDependenciesDir, string(source.UID),
calcInstanceMemoryResources(spec.Resources), spec.Java.ExtraDependenciesDir, string(source.UID),
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
generateJavaLogConfigFileName(spec.Java))
Expand Down

0 comments on commit 9703fe3

Please sign in to comment.