Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 226: Pass jvm options #247

Merged
merged 10 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions example/cr-detailed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ spec:
# Default is 60
codahaleStatsOutputFrequencySeconds: "30"

# Pass the JVM options to Bookkeeper
bookkeeperJVMOptions:
memoryOpts: ["-Xms2g", "-XX:MaxDirectMemorySize=2g"]
gcOpts: ["-XX:MaxGCPauseMillis=20"]
gcLoggingOpts: ["-XX:NumberOfGCLogFiles=10"]
extraOpts: []

pravega:
image:
repository: pravega/pravega
Expand Down Expand Up @@ -134,3 +141,7 @@ spec:
pravegaservice.enableTls: "true"
pravegaservice.certFile: "/etc/secret-volume/segmentStore01.pem"
pravegaservice.keyFile: "/etc/secret-volume/segmentStore01.key.pem"

# Pass the JVM options to controller and segmentstore
controllerJvmOptions: ["-XX:MaxDirectMemorySize=1g"]
segmentStoreJVMOptions: ["-XX:MaxDirectMemorySize=1g"]
45 changes: 45 additions & 0 deletions pkg/apis/pravega/v1alpha1/bookkeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ type BookkeeperSpec struct {
// in bookkeeper. Some examples can be found here
// https://github.com/apache/bookkeeper/blob/master/docker/README.md
Options map[string]string `json:"options"`

// JVM is the JVM options for bookkeeper. It will be passed to the JVM for performance tuning.
// If this field is not specified, the operator will use a set of default
// options that is good enough for general deployment.
BookkeeperJVMOptions *BookkeeperJVMOptions `json:"bookkeeperJVMOptions"`
}

func (s *BookkeeperSpec) withDefaults() (changed bool) {
Expand Down Expand Up @@ -130,6 +135,15 @@ func (s *BookkeeperSpec) withDefaults() (changed bool) {
s.Options = map[string]string{}
}

if s.BookkeeperJVMOptions == nil {
changed = true
s.BookkeeperJVMOptions = &BookkeeperJVMOptions{}
}

if s.BookkeeperJVMOptions.withDefaults() {
changed = true
}

Tristan1900 marked this conversation as resolved.
Show resolved Hide resolved
return changed
}

Expand All @@ -154,6 +168,37 @@ func (s *BookkeeperImageSpec) withDefaults() (changed bool) {
return changed
}

type BookkeeperJVMOptions struct {
MemoryOpts []string `json:"memoryOpts"`
GcOpts []string `json:"gcOpts"`
GcLoggingOpts []string `json:"gcLoggingOpts"`
ExtraOpts []string `json:"extraOpts"`
}

func (s *BookkeeperJVMOptions) withDefaults() (changed bool) {
if s.MemoryOpts == nil {
changed = true
s.MemoryOpts = []string{}
}

if s.GcOpts == nil {
changed = true
s.GcOpts = []string{}
}

if s.GcLoggingOpts == nil {
changed = true
s.GcLoggingOpts = []string{}
}

if s.ExtraOpts == nil {
changed = true
s.ExtraOpts = []string{}
}

return changed
}

// BookkeeperStorageSpec is the configuration of the volumes used in BookKeeper
type BookkeeperStorageSpec struct {
// LedgerVolumeClaimTemplate is the spec to describe PVC for the BookKeeper ledger
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/pravega/v1alpha1/pravega.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ type PravegaSpec struct {
// https://github.com/pravega/pravega/blob/master/config/config.properties
Options map[string]string `json:"options"`

// ControllerJvmOptions is the JVM options for controller. It will be passed to the JVM
// for performance tuning. If this field is not specified, the operator will use a set of default
// options that is good enough for general deployment.
ControllerJvmOptions []string `json:"controllerjvmOptions"`

// SegmentStoreJVMOptions is the JVM options for Segmentstore. It will be passed to the JVM
// for performance tuning. If this field is not specified, the operator will use a set of default
// options that is good enough for general deployment.
SegmentStoreJVMOptions []string `json:"segmentStoreJVMOptions"`

// CacheVolumeClaimTemplate is the spec to describe PVC for the Pravega cache.
// This field is optional. If no PVC spec, stateful containers will use
// emptyDir as volume
Expand Down Expand Up @@ -139,6 +149,16 @@ func (s *PravegaSpec) withDefaults() (changed bool) {
s.Options = map[string]string{}
}

if s.ControllerJvmOptions == nil {
changed = true
s.ControllerJvmOptions = []string{}
}

if s.SegmentStoreJVMOptions == nil {
changed = true
s.SegmentStoreJVMOptions = []string{}
}

if s.CacheVolumeClaimTemplate == nil {
changed = true
s.CacheVolumeClaimTemplate = &v1.PersistentVolumeClaimSpec{
Expand Down
114 changes: 114 additions & 0 deletions pkg/apis/pravega/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/controller/pravega/bookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func MakeBookieConfigMap(pravegaCluster *v1alpha1.PravegaCluster) *corev1.Config
"-XX:MaxRAMFraction=2",
)
}
memoryOpts = util.OverrideDefaultJVMOptions(memoryOpts, pravegaCluster.Spec.Bookkeeper.BookkeeperJVMOptions.MemoryOpts)

gcOpts := []string{
"-XX:+UseG1GC",
Expand All @@ -230,6 +231,7 @@ func MakeBookieConfigMap(pravegaCluster *v1alpha1.PravegaCluster) *corev1.Config
"-XX:+DisableExplicitGC",
"-XX:-ResizePLAB",
}
gcOpts = util.OverrideDefaultJVMOptions(gcOpts, pravegaCluster.Spec.Bookkeeper.BookkeeperJVMOptions.GcOpts)

gcLoggingOpts := []string{
"-XX:+PrintGCDetails",
Expand All @@ -239,11 +241,18 @@ func MakeBookieConfigMap(pravegaCluster *v1alpha1.PravegaCluster) *corev1.Config
"-XX:NumberOfGCLogFiles=5",
"-XX:GCLogFileSize=64m",
}
gcLoggingOpts = util.OverrideDefaultJVMOptions(gcLoggingOpts, pravegaCluster.Spec.Bookkeeper.BookkeeperJVMOptions.GcLoggingOpts)

extraOpts := []string{}
if pravegaCluster.Spec.Bookkeeper.BookkeeperJVMOptions.ExtraOpts != nil {
extraOpts = pravegaCluster.Spec.Bookkeeper.BookkeeperJVMOptions.ExtraOpts
}

configData := map[string]string{
"BOOKIE_MEM_OPTS": strings.Join(memoryOpts, " "),
"BOOKIE_GC_OPTS": strings.Join(gcOpts, " "),
"BOOKIE_GC_LOGGING_OPTS": strings.Join(gcLoggingOpts, " "),
"BOOKIE_EXTRA_OPTS": strings.Join(extraOpts, " "),
"ZK_URL": pravegaCluster.Spec.ZookeeperUri,
"BK_useHostNameAsBookieID": "true",
"PRAVEGA_CLUSTER_NAME": pravegaCluster.ObjectMeta.Name,
Expand Down
10 changes: 8 additions & 2 deletions pkg/controller/pravega/pravega_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ func addSecretVolumeWithMount(podSpec *corev1.PodSpec, p *api.PravegaCluster,
}

func MakeControllerConfigMap(p *api.PravegaCluster) *corev1.ConfigMap {
var javaOpts = []string{
javaOpts := []string{
"-Dpravegaservice.clusterName=" + p.Name,
}

jvmOpts := []string{
"-Xms512m",
"-XX:+ExitOnOutOfMemoryError",
"-XX:+CrashOnOutOfMemoryError",
Expand All @@ -182,13 +186,15 @@ func MakeControllerConfigMap(p *api.PravegaCluster) *corev1.ConfigMap {

if match, _ := util.CompareVersions(p.Spec.Version, "0.4.0", ">="); match {
// Pravega < 0.4 uses a Java version that does not support the options below
javaOpts = append(javaOpts,
jvmOpts = append(jvmOpts,
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UseCGroupMemoryLimitForHeap",
"-XX:MaxRAMFraction=2",
)
}

javaOpts = append(javaOpts, util.OverrideDefaultJVMOptions(jvmOpts, p.Spec.Pravega.ControllerJvmOptions)...)

for name, value := range p.Spec.Pravega.Options {
javaOpts = append(javaOpts, fmt.Sprintf("-D%v=%v", name, value))
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/pravega/pravega_segmentstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func makeSegmentstorePodSpec(p *api.PravegaCluster) corev1.PodSpec {

func MakeSegmentstoreConfigMap(p *api.PravegaCluster) *corev1.ConfigMap {
javaOpts := []string{
"-Dpravegaservice.clusterName=" + p.Name,
}

jvmOpts := []string{
"-Xms1g",
"-XX:+ExitOnOutOfMemoryError",
"-XX:+CrashOnOutOfMemoryError",
Expand All @@ -170,17 +174,18 @@ func MakeSegmentstoreConfigMap(p *api.PravegaCluster) *corev1.ConfigMap {

if match, _ := util.CompareVersions(p.Spec.Version, "0.4.0", ">="); match {
// Pravega < 0.4 uses a Java version that does not support the options below
javaOpts = append(javaOpts,
jvmOpts = append(jvmOpts,
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UseCGroupMemoryLimitForHeap",
"-XX:MaxRAMFraction=2",
)
}

javaOpts = append(javaOpts, util.OverrideDefaultJVMOptions(jvmOpts, p.Spec.Pravega.SegmentStoreJVMOptions)...)

for name, value := range p.Spec.Pravega.Options {
javaOpts = append(javaOpts, fmt.Sprintf("-D%v=%v", name, value))
}

authEnabledStr := fmt.Sprint(p.Spec.Authentication.IsEnabled())
configData := map[string]string{
"AUTHORIZATION_ENABLED": authEnabledStr,
Expand Down
Loading