diff --git a/README.md b/README.md index d87f759e609..79d77f5486c 100644 --- a/README.md +++ b/README.md @@ -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 | - +| use50PercentHeap (Optional) | boolean | Boolean flag to use 50% of physical memory as heap. Default is 1GB. e.g., `--context use50PercentHeap=true` | * Before starting this step, ensure that your AWS CLI is correctly configured with access credentials. * Also ensure that you're running these commands in the current directory diff --git a/lib/infra/infra-stack.ts b/lib/infra/infra-stack.ts index 1d7eca2a970..3350cae586b 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 use50PercentHeap: boolean, } export class InfraStack extends Stack { @@ -468,6 +469,20 @@ export class InfraStack extends Stack { })); } + // Check if JVM Heap Memory is set. Default is 1G in the jvm.options file + // @ts-ignore + 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, + })); + } + // @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..c9de89d6b87 100644 --- a/lib/os-cluster-entrypoint.ts +++ b/lib/os-cluster-entrypoint.ts @@ -148,6 +148,9 @@ export class OsClusterEntrypoint { const suffix = `${scope.node.tryGetContext('suffix')}`; + const use50heap = `${scope.node.tryGetContext('use50PercentHeap')}`; + const use50PercentHeap = use50heap === 'true'; + const network = new NetworkStack(scope, 'opensearch-network-stack', { cidrBlock: cidrRange, maxAzs: 3, @@ -192,6 +195,7 @@ export class OsClusterEntrypoint { mlNodeStorage, jvmSysPropsString: jvmSysProps, additionalConfig: ymlConfig, + use50PercentHeap, ...props, });