Skip to content

Commit

Permalink
Add parameter to configure heap size (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Singh <sngri@amazon.com>
  • Loading branch information
rishabh6788 committed Apr 20, 2023
1 parent 5307477 commit 874c58c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ 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 |



* Before starting this step, ensure that your AWS CLI is correctly configured with access credentials.
Expand Down
13 changes: 13 additions & 0 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface infraProps extends StackProps{
readonly mlNodeStorage: number,
readonly jvmSysPropsString?: string,
readonly additionalConfig?: string,
readonly jvmHeapSize?: number,
}

export class InfraStack extends Stack {
Expand Down Expand Up @@ -468,6 +469,18 @@ 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;`, {
cwd: '/home/ec2-user',
ignoreErrors: false,
}));
}

// @ts-ignore
if (props.additionalConfig.toString() !== 'undefined') {
// @ts-ignore
Expand Down
10 changes: 10 additions & 0 deletions lib/os-cluster-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ 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 @@ -148,6 +149,14 @@ 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 network = new NetworkStack(scope, 'opensearch-network-stack', {
cidrBlock: cidrRange,
maxAzs: 3,
Expand Down Expand Up @@ -192,6 +201,7 @@ export class OsClusterEntrypoint {
mlNodeStorage,
jvmSysPropsString: jvmSysProps,
additionalConfig: ymlConfig,
jvmHeapSize,
...props,
});

Expand Down

0 comments on commit 874c58c

Please sign in to comment.