Skip to content

Commit

Permalink
Add option to use 50 percent memory as heap (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Singh <sngri@amazon.com>
  • Loading branch information
rishabh6788 committed May 3, 2023
1 parent 874c58c commit d3b12a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ In order to deploy both the stacks the user needs to provide a set of required a
| account (Optional) | string | User provided aws account |
| dataNodeStorage (Optional) | string | User provided ebs block storage size, defaults to 100Gb |
| mlNodeStorage (Optional) | string | User provided ebs block storage size, defaults to 100Gb |
| jvmHeapSize (Optional) | integer | User provided JVM heap memory size (integer) in Gb, defaults to 1Gb, e.g. `--context jvmHeapSize=2` to set heap to 2Gb |
| use50PercentHeap (Optional) | boolean | Boolean flag to use 50% of physical memory as heap. Default is 1GB. e.g., `--context use50PercentHeap=true` |



Expand Down
14 changes: 8 additions & 6 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface infraProps extends StackProps{
readonly mlNodeStorage: number,
readonly jvmSysPropsString?: string,
readonly additionalConfig?: string,
readonly jvmHeapSize?: number,
readonly use50PercentHeap: boolean,
}

export class InfraStack extends Stack {
Expand Down Expand Up @@ -471,11 +471,13 @@ export class InfraStack extends Stack {

// Check if JVM Heap Memory is set. Default is 1G in the jvm.options file
// @ts-ignore
if (props.jvmHeapSize > 1) {
const minHeap = `-Xms${props.jvmHeapSize}g`;
const maxHeap = `-Xmx${props.jvmHeapSize}g`;
cfnInitConfig.push(InitCommand.shellCommand(`set -ex; cd opensearch; sed -i -e "s/^-Xms[0-9a-z]*$/${minHeap}/g" config/jvm.options;
sed -i -e "s/^-Xmx[0-9a-z]*$/${maxHeap}/g" config/jvm.options;`, {
if (props.use50PercentHeap) {
cfnInitConfig.push(InitCommand.shellCommand(`set -ex; cd opensearch;
totalMem=\`expr $(free -g | awk '/^Mem:/{print $2}') + 1\`;
heapSizeInGb=\`expr $totalMem / 2\`;
if [ $heapSizeInGb -lt 32 ];then minHeap="-Xms"$heapSizeInGb"g";maxHeap="-Xmx"$heapSizeInGb"g";else minHeap="-Xms32g";maxHeap="-Xmx32g";fi
sed -i -e "s/^-Xms[0-9a-z]*$/$minHeap/g" config/jvm.options;
sed -i -e "s/^-Xmx[0-9a-z]*$/$maxHeap/g" config/jvm.options;`, {
cwd: '/home/ec2-user',
ignoreErrors: false,
}));
Expand Down
12 changes: 3 additions & 9 deletions lib/os-cluster-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class OsClusterEntrypoint {
let dataNodeStorage: number;
let mlNodeStorage: number;
let ymlConfig: string = 'undefined';
let jvmHeapSize: number = 1;

const vpcId: string = scope.node.tryGetContext('vpcId');
const securityGroupId = scope.node.tryGetContext('securityGroupId');
Expand Down Expand Up @@ -149,13 +148,8 @@ export class OsClusterEntrypoint {

const suffix = `${scope.node.tryGetContext('suffix')}`;

const heapSize = `${scope.node.tryGetContext('jvmHeapSize')}`;
if (heapSize !== 'undefined') {
jvmHeapSize = parseInt(heapSize, 10);
if (Number.isNaN(jvmHeapSize)) {
throw new Error('heapSize parameter has to be a number');
}
}
const use50heap = `${scope.node.tryGetContext('use50PercentHeap')}`;
const use50PercentHeap = use50heap === 'true';

const network = new NetworkStack(scope, 'opensearch-network-stack', {
cidrBlock: cidrRange,
Expand Down Expand Up @@ -201,7 +195,7 @@ export class OsClusterEntrypoint {
mlNodeStorage,
jvmSysPropsString: jvmSysProps,
additionalConfig: ymlConfig,
jvmHeapSize,
use50PercentHeap,
...props,
});

Expand Down

0 comments on commit d3b12a8

Please sign in to comment.