diff --git a/README.md b/README.md index d87f759e609..a5cd988f87f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/infra/infra-stack.ts b/lib/infra/infra-stack.ts index 1d7eca2a970..74a05fc34a3 100644 --- a/lib/infra/infra-stack.ts +++ b/lib/infra/infra-stack.ts @@ -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 { @@ -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 diff --git a/lib/os-cluster-entrypoint.ts b/lib/os-cluster-entrypoint.ts index 0d508c5e975..93c51c6d4c9 100644 --- a/lib/os-cluster-entrypoint.ts +++ b/lib/os-cluster-entrypoint.ts @@ -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'); @@ -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, @@ -192,6 +201,7 @@ export class OsClusterEntrypoint { mlNodeStorage, jvmSysPropsString: jvmSysProps, additionalConfig: ymlConfig, + jvmHeapSize, ...props, });