Skip to content

Commit

Permalink
Set -Xms to 50% of the request memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Sep 27, 2023
1 parent 956561f commit 989f597
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
13 changes: 7 additions & 6 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -1093,6 +1093,7 @@ func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details
},
" ")
}
xmsMemory := resource.NewScaledQuantity(memory.Value()/2, 0)
args := []string{
"exec",
"java",
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion controllers/spec/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion controllers/spec/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion controllers/spec/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 989f597

Please sign in to comment.