Skip to content

Commit c79c657

Browse files
Set MaxDirectMemorySize to 20% of limit memory
1 parent fcf4bfc commit c79c657

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

controllers/spec/common.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
v1 "k8s.io/api/batch/v1"
4040
corev1 "k8s.io/api/core/v1"
4141
k8serrors "k8s.io/apimachinery/pkg/api/errors"
42+
"k8s.io/apimachinery/pkg/api/resource"
4243
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4344
"k8s.io/apimachinery/pkg/types"
4445
"k8s.io/apimachinery/pkg/util/intstr"
@@ -436,13 +437,13 @@ func makePodTemplate(container *corev1.Container, filebeatContainer *corev1.Cont
436437
}
437438

438439
func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, generateLogConfigCommand, logLevel, details, extraDependenciesDir, uid string,
439-
javaOpts []string, hasPulsarctl, hasWget, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
440+
memory *resource.Quantity, javaOpts []string, hasPulsarctl, hasWget, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
440441
state *v1alpha1.Stateful,
441442
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig,
442443
maxPendingAsyncRequests *int32, logConfigFileName string) []string {
443444
processCommand := setShardIDEnvironmentVariableCommand() + " && " + generateLogConfigCommand +
444445
strings.Join(getProcessJavaRuntimeArgs(name, packageFile, clusterName, logLevel, details,
445-
extraDependenciesDir, uid, javaOpts, authProvided, tlsProvided, secretMaps, state, tlsConfig,
446+
extraDependenciesDir, uid, memory, javaOpts, authProvided, tlsProvided, secretMaps, state, tlsConfig,
446447
authConfig, maxPendingAsyncRequests, logConfigFileName), " ")
447448
if downloadPath != "" && !utils.EnableInitContainers {
448449
// prepend download command if the downPath is provided
@@ -1184,7 +1185,7 @@ func setShardIDEnvironmentVariableCommand() string {
11841185
}
11851186

11861187
func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details, extraDependenciesDir, uid string,
1187-
javaOpts []string, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
1188+
memory *resource.Quantity, javaOpts []string, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
11881189
state *v1alpha1.Stateful,
11891190
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig,
11901191
maxPendingAsyncRequests *int32, logConfigFileName string) []string {
@@ -1206,6 +1207,8 @@ func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details
12061207
},
12071208
" ")
12081209
}
1210+
// maxDirectMemory takes 20% of the total memory, while MaxRamPercentage is 70%, the rest 10% is for misc usage
1211+
maxDirectMemory := resource.NewScaledQuantity(memory.Value()/5, 0)
12091212
args := []string{
12101213
"exec",
12111214
"java",
@@ -1218,6 +1221,7 @@ func getProcessJavaRuntimeArgs(name, packageName, clusterName, logLevel, details
12181221
"-Dpulsar.allocator.exit_on_oom=true",
12191222
setLogLevel,
12201223
"-XX:MaxRAMPercentage=70",
1224+
"-XX:MaxDirectMemorySize=" + getDecimalSIMemory(maxDirectMemory),
12211225
"-XX:+UseG1GC",
12221226
"-XX:+HeapDumpOnOutOfMemoryError",
12231227
"-XX:HeapDumpPath=/pulsar/tmp/heapdump-%p.hprof",
@@ -2027,6 +2031,14 @@ func getPythonSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef) []str
20272031
return ret
20282032
}
20292033

2034+
// Java command requires memory values in resource.DecimalSI format
2035+
func getDecimalSIMemory(quantity *resource.Quantity) string {
2036+
if quantity.Format == resource.DecimalSI {
2037+
return quantity.String()
2038+
}
2039+
return resource.NewQuantity(quantity.Value(), resource.DecimalSI).String()
2040+
}
2041+
20302042
func getGenericSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef, language string) []string {
20312043
var ret []string
20322044
if len(secretMaps) > 0 {

controllers/spec/function.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
237237
generateFunctionDetailsInJSON(function),
238238
spec.Java.ExtraDependenciesDir,
239239
string(function.UID),
240+
spec.Resources.Limits.Memory(),
240241
spec.Java.JavaOpts, hasPulsarctl, hasWget,
241242
spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
242243
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig,

controllers/spec/sink.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func MakeSinkCommand(sink *v1alpha1.Sink) []string {
231231
parseJavaLogLevel(spec.Java),
232232
generateSinkDetailsInJSON(sink),
233233
spec.Java.ExtraDependenciesDir, string(sink.UID),
234+
spec.Resources.Limits.Memory(),
234235
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
235236
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
236237
GenerateJavaLogConfigFileName(spec.Java))

controllers/spec/source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func makeSourceCommand(source *v1alpha1.Source) []string {
178178
parseJavaLogLevel(spec.Java),
179179
generateSourceDetailsInJSON(source),
180180
spec.Java.ExtraDependenciesDir, string(source.UID),
181+
spec.Resources.Limits.Memory(),
181182
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
182183
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
183184
GenerateJavaLogConfigFileName(spec.Java))

0 commit comments

Comments
 (0)