Skip to content

Commit 759cbf6

Browse files
authored
optimize jvm parameters (#708)
* optimize jvm parameters * check style * update
1 parent 3e78407 commit 759cbf6

File tree

4 files changed

+8
-27
lines changed

4 files changed

+8
-27
lines changed

controllers/spec/common.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
autov2 "k8s.io/api/autoscaling/v2"
4141
v1 "k8s.io/api/batch/v1"
4242
corev1 "k8s.io/api/core/v1"
43-
"k8s.io/apimachinery/pkg/api/resource"
4443
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4544
"k8s.io/apimachinery/pkg/util/intstr"
4645
"k8s.io/client-go/kubernetes/scheme"
@@ -340,14 +339,14 @@ func makePodTemplate(container *corev1.Container, filebeatContainer *corev1.Cont
340339
}
341340
}
342341

343-
func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, generateLogConfigCommand, logLevel, details, extraDependenciesDir, uid string, memory *resource.Quantity,
342+
func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, generateLogConfigCommand, logLevel, details, extraDependenciesDir, uid string,
344343
javaOpts []string, hasPulsarctl, hasWget, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
345344
state *v1alpha1.Stateful,
346345
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig,
347346
maxPendingAsyncRequests *int32, logConfigFileName string) []string {
348347
processCommand := setShardIDEnvironmentVariableCommand() + " && " + generateLogConfigCommand +
349348
strings.Join(getProcessJavaRuntimeArgs(name, packageFile, clusterName, logLevel, details,
350-
extraDependenciesDir, uid, memory, javaOpts, authProvided, tlsProvided, secretMaps, state, tlsConfig,
349+
extraDependenciesDir, uid, javaOpts, authProvided, tlsProvided, secretMaps, state, tlsConfig,
351350
authConfig, maxPendingAsyncRequests, logConfigFileName), " ")
352351
if downloadPath != "" && !utils.EnableInitContainers {
353352
// prepend download command if the downPath is provided
@@ -1091,7 +1090,7 @@ func setShardIDEnvironmentVariableCommand() string {
10911090
}
10921091

10931092
func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details, extraDependenciesDir, uid string,
1094-
memory *resource.Quantity, javaOpts []string, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
1093+
javaOpts []string, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
10951094
state *v1alpha1.Stateful,
10961095
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig,
10971096
maxPendingAsyncRequests *int32, logConfigFileName string) []string {
@@ -1113,7 +1112,6 @@ func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details
11131112
},
11141113
" ")
11151114
}
1116-
xmsMemory := resource.NewScaledQuantity(memory.Value()/2, 0)
11171115
args := []string{
11181116
"exec",
11191117
"java",
@@ -1124,9 +1122,12 @@ func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details
11241122
"-Dpulsar.function.log.dir=logs/functions",
11251123
"-Dpulsar.function.log.file=" + fmt.Sprintf("%s-${%s}", name, EnvShardID),
11261124
setLogLevel,
1127-
"-Xmx" + getDecimalSIMemory(memory),
1128-
"-Xms" + getDecimalSIMemory(xmsMemory),
1125+
"-XX:InitialRAMPercentage=20",
1126+
"-XX:MaxRAMPercentage=40",
11291127
"-XX:+UseG1GC",
1128+
"-XX:+HeapDumpOnOutOfMemoryError",
1129+
"-XX:HeapDumpPath=/pulsar/tmp/heapdump-%p.hprof",
1130+
"-Xlog:gc*:file=/pulsar/logs/gc.log:time,level,tags:filecount=5,filesize=10M",
11301131
strings.Join(javaOpts, " "),
11311132
"org.apache.pulsar.functions.instance.JavaInstanceMain",
11321133
"--jar",
@@ -1904,15 +1905,6 @@ func getPythonSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef) []str
19041905
return ret
19051906
}
19061907

1907-
func calcInstanceMemoryResources(resources corev1.ResourceRequirements) *resource.Quantity {
1908-
if resources.Requests.Memory() == resources.Limits.Memory() {
1909-
// if request and limit are the same, use the value * 0.9 as the instance (JVM) memory size, to prevent OOM
1910-
return resource.NewQuantity(int64(float64(resources.Requests.Memory().Value())*0.9), resource.DecimalSI)
1911-
}
1912-
// if request and limit are different, use the request value as the instance (JVM) memory size
1913-
return resources.Requests.Memory()
1914-
}
1915-
19161908
func getGenericSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef, language string) []string {
19171909
var ret []string
19181910
if len(secretMaps) > 0 {
@@ -1931,14 +1923,6 @@ func getGenericSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef, lang
19311923
return ret
19321924
}
19331925

1934-
// Java command requires memory values in resource.DecimalSI format
1935-
func getDecimalSIMemory(quantity *resource.Quantity) string {
1936-
if quantity.Format == resource.DecimalSI {
1937-
return quantity.String()
1938-
}
1939-
return resource.NewQuantity(quantity.Value(), resource.DecimalSI).String()
1940-
}
1941-
19421926
func getTLSTrustCertPath(tlsVolume TLSConfig, path string) string {
19431927
return fmt.Sprintf("%s/%s", tlsVolume.GetMountPath(), path)
19441928
}

controllers/spec/function.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
221221
generateFunctionDetailsInJSON(function),
222222
spec.Java.ExtraDependenciesDir,
223223
string(function.UID),
224-
calcInstanceMemoryResources(spec.Resources),
225224
spec.Java.JavaOpts, hasPulsarctl, hasWget,
226225
spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
227226
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig,

controllers/spec/sink.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ func MakeSinkCommand(sink *v1alpha1.Sink) []string {
213213
parseJavaLogLevel(spec.Java),
214214
generateSinkDetailsInJSON(sink),
215215
spec.Java.ExtraDependenciesDir, string(sink.UID),
216-
calcInstanceMemoryResources(spec.Resources),
217216
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
218217
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
219218
generateJavaLogConfigFileName(spec.Java))

controllers/spec/source.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func makeSourceCommand(source *v1alpha1.Source) []string {
160160
parseJavaLogLevel(spec.Java),
161161
generateSourceDetailsInJSON(source),
162162
spec.Java.ExtraDependenciesDir, string(source.UID),
163-
calcInstanceMemoryResources(spec.Resources),
164163
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
165164
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
166165
generateJavaLogConfigFileName(spec.Java))

0 commit comments

Comments
 (0)