Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use 50 percent memory as heap (#23) #65

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
readonly mlNodeStorage: number,
readonly jvmSysPropsString?: string,
readonly additionalConfig?: string,
readonly use50PercentHeap: boolean,
}

export class InfraStack extends Stack {
Expand Down Expand Up @@ -111,7 +112,7 @@
}

if (props.singleNodeCluster) {
console.log('Single node value is true, creating single node configurations');

Check warning on line 115 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 115 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
singleNodeInstance = new Instance(this, 'single-node-instance', {
vpc: props.vpc,
instanceType: ec2InstanceType,
Expand Down Expand Up @@ -407,7 +408,7 @@

fileContent['cluster.name'] = `${scope.stackName}-${scope.account}-${scope.region}`;

console.log(dump(fileContent).toString());

Check warning on line 411 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 411 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
opensearchConfig = dump(fileContent).toString();
cfnInitConfig.push(InitCommand.shellCommand(`set -ex;cd opensearch; echo "${opensearchConfig}" > config/opensearch.yml`,
{
Expand Down Expand Up @@ -468,6 +469,20 @@
}));
}

// 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
Loading