-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the
containerV2
flag to compute initial heap percentage using p…
…rocessor count, and disable setting the `ActiveProcessorCount` JVM option (#361) When the experimental `containerV2` is set, 1) compute the heap percentage as 75% of the heap minus 3mb per processor, with a minimum value of 50%, and 2) don't set the `-XX:ActiveProcessorCount` JVM option.
- Loading branch information
Showing
11 changed files
with
334 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type: improvement | ||
improvement: | ||
description: When the experimental `containerV2` is set, 1) compute the heap percentage | ||
as 75% of the heap minus 3mb per processor, with a minimum value of 50%, and 2) | ||
don't set the -XX:ActiveProcessorCount JVM option. | ||
links: | ||
- https://github.com/palantir/go-java-launcher/pull/361 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...n_test/testdata/launcher-custom-experimental-container-v2-with-initial-ram-percentage.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
configType: java | ||
configVersion: 1 | ||
jvmOpts: | ||
- '-XX:InitialRAMPercentage=70.0' | ||
experimental: | ||
containerV2: true |
6 changes: 6 additions & 0 deletions
6
...ation_test/testdata/launcher-custom-experimental-container-v2-with-max-ram-percentage.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
configType: java | ||
configVersion: 1 | ||
jvmOpts: | ||
- '-XX:MaxRAMPercentage=70.0' | ||
experimental: | ||
containerV2: true |
3 changes: 2 additions & 1 deletion
3
...r-custom-experimental-processor-count.yml → ...imental-container-v2-with-xms-and-xmx.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
configType: java | ||
configVersion: 1 | ||
jvmOpts: | ||
- '-Xms1g' | ||
- '-Xmx1g' | ||
experimental: | ||
overrideActiveProcessorCount: true | ||
containerV2: true |
5 changes: 5 additions & 0 deletions
5
integration_test/testdata/launcher-custom-experimental-container-v2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
configType: java | ||
configVersion: 1 | ||
jvmOpts: [] | ||
experimental: | ||
containerV2: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2023 Palantir Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package launchlib | ||
|
||
import ( | ||
"io" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
memGroupName = "memory" | ||
memLimitName = "memory.limit_in_bytes" | ||
) | ||
|
||
type MemoryLimit interface { | ||
MemoryLimitInBytes() (uint64, error) | ||
} | ||
|
||
var DefaultMemoryLimit = NewCGroupMemoryLimit(os.DirFS("/")) | ||
|
||
type CGroupMemoryLimit struct { | ||
pather CGroupPather | ||
fs fs.FS | ||
} | ||
|
||
func NewCGroupMemoryLimit(filesystem fs.FS) MemoryLimit { | ||
return CGroupMemoryLimit{ | ||
pather: NewCGroupV1Pather(filesystem), | ||
fs: filesystem, | ||
} | ||
} | ||
|
||
func (c CGroupMemoryLimit) MemoryLimitInBytes() (uint64, error) { | ||
memoryCGroupPath, err := c.pather.Path(memGroupName) | ||
if err != nil { | ||
return 0, errors.Wrap(err, "failed to get memory cgroup path") | ||
} | ||
|
||
memLimitFilepath := filepath.Join(memoryCGroupPath, memLimitName) | ||
memLimitFile, err := c.fs.Open(convertToFSPath(memLimitFilepath)) | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "unable to open memory.limit_in_bytes at expected location: %s", memLimitFilepath) | ||
} | ||
memLimitBytes, err := io.ReadAll(memLimitFile) | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "unable to read memory.limit_in_bytes") | ||
} | ||
memLimit, err := strconv.Atoi(strings.TrimSpace(string(memLimitBytes))) | ||
if err != nil { | ||
return 0, errors.New("unable to convert memory.limit_in_bytes value to expected type") | ||
} | ||
return uint64(memLimit), nil | ||
} |
Oops, something went wrong.