From 989f597e6cae8a835db6e425cc4bd0761d89be1b Mon Sep 17 00:00:00 2001 From: jiangpengcheng Date: Wed, 27 Sep 2023 15:08:28 +0800 Subject: [PATCH] Set -Xms to 50% of the request memory --- controllers/spec/common.go | 13 +++++++------ controllers/spec/function.go | 3 ++- controllers/spec/sink.go | 3 ++- controllers/spec/source.go | 3 ++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/controllers/spec/common.go b/controllers/spec/common.go index 4c498615..9b5e0999 100644 --- a/controllers/spec/common.go +++ b/controllers/spec/common.go @@ -336,14 +336,14 @@ func makePodTemplate(container *corev1.Container, filebeatContainer *corev1.Cont } } -func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, generateLogConfigCommand, logLevel, details, memory, extraDependenciesDir, uid string, +func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, generateLogConfigCommand, logLevel, details, extraDependenciesDir, uid string, memory *resource.Quantity, javaOpts []string, hasPulsarctl, hasWget, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef, state *v1alpha1.Stateful, tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig, maxPendingAsyncRequests *int32, logConfigFileName string) []string { processCommand := setShardIDEnvironmentVariableCommand() + " && " + generateLogConfigCommand + strings.Join(getProcessJavaRuntimeArgs(name, packageFile, clusterName, logLevel, details, - memory, extraDependenciesDir, uid, javaOpts, authProvided, tlsProvided, secretMaps, state, tlsConfig, + extraDependenciesDir, uid, memory, javaOpts, authProvided, tlsProvided, secretMaps, state, tlsConfig, authConfig, maxPendingAsyncRequests, logConfigFileName), " ") if downloadPath != "" && !utils.EnableInitContainers { // prepend download command if the downPath is provided @@ -1070,8 +1070,8 @@ func setShardIDEnvironmentVariableCommand() string { return fmt.Sprintf("%s=${POD_NAME##*-} && echo shardId=${%s}", EnvShardID, EnvShardID) } -func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details, memory, extraDependenciesDir, uid string, - javaOpts []string, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef, +func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details, extraDependenciesDir, uid string, + memory *resource.Quantity, javaOpts []string, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef, state *v1alpha1.Stateful, tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig, maxPendingAsyncRequests *int32, logConfigFileName string) []string { @@ -1093,6 +1093,7 @@ func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details }, " ") } + xmsMemory := resource.NewScaledQuantity(memory.Value()/2, 0) args := []string{ "exec", "java", @@ -1103,8 +1104,8 @@ func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details "-Dpulsar.function.log.dir=logs/functions", "-Dpulsar.function.log.file=" + fmt.Sprintf("%s-${%s}", name, EnvShardID), setLogLevel, - "-Xmx" + memory, - "-Xms" + memory, + "-Xmx" + getDecimalSIMemory(memory), + "-Xms" + getDecimalSIMemory(xmsMemory), "-XX:+UseG1GC", strings.Join(javaOpts, " "), "org.apache.pulsar.functions.instance.JavaInstanceMain", diff --git a/controllers/spec/function.go b/controllers/spec/function.go index 30e771fd..ae511d3b 100644 --- a/controllers/spec/function.go +++ b/controllers/spec/function.go @@ -219,8 +219,9 @@ func makeFunctionCommand(function *v1alpha1.Function) []string { generateJavaLogConfigCommand(spec.Java, spec.LogTopicAgent), parseJavaLogLevel(spec.Java), generateFunctionDetailsInJSON(function), - getDecimalSIMemory(spec.Resources.Requests.Memory()), spec.Java.ExtraDependenciesDir, + spec.Java.ExtraDependenciesDir, string(function.UID), + spec.Resources.Requests.Memory(), spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "", spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, diff --git a/controllers/spec/sink.go b/controllers/spec/sink.go index c729a4c3..ca8235bb 100644 --- a/controllers/spec/sink.go +++ b/controllers/spec/sink.go @@ -212,7 +212,8 @@ 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), + spec.Java.ExtraDependenciesDir, string(sink.UID), + spec.Resources.Requests.Memory(), 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)) diff --git a/controllers/spec/source.go b/controllers/spec/source.go index 6e26e77b..f17ea6e5 100644 --- a/controllers/spec/source.go +++ b/controllers/spec/source.go @@ -159,7 +159,8 @@ 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), + spec.Java.ExtraDependenciesDir, string(source.UID), + spec.Resources.Requests.Memory(), 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))