Skip to content

Commit

Permalink
Add option to use 50 percent memory as heap (#23) (#65)
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Singh <[email protected]>
  • Loading branch information
rishabh6788 authored Oct 24, 2023
1 parent bab64d4 commit 8d27deb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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 |

| 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
Expand Down
15 changes: 15 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 use50PercentHeap: boolean,
}

export class InfraStack extends Stack {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/os-cluster-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -192,6 +195,7 @@ export class OsClusterEntrypoint {
mlNodeStorage,
jvmSysPropsString: jvmSysProps,
additionalConfig: ymlConfig,
use50PercentHeap,
...props,
});

Expand Down

0 comments on commit 8d27deb

Please sign in to comment.