Skip to content

Commit

Permalink
build: resize DB and ECS
Browse files Browse the repository at this point in the history
Ref. metriport/metriport-internal#1040

Signed-off-by: Rafael Leite <[email protected]>
  • Loading branch information
leite08 committed Jul 30, 2024
1 parent 944ec93 commit 0b48c3c
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions infra/lib/fhir-server-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,58 @@ import { vCPU } from "./shared/fargate";
import { addDefaultMetricsToTargetGroup } from "./shared/target-group";
import { isProd, isSandbox, mbToBytes } from "./util";

export function settings() {
type Settings = {
cpu: number;
memoryLimitMiB: number;
taskCountMin: number;
taskCountMax: number;
minDBCap: number;
maxDBCap: number;
/** Causes the duration of each completed statement to be logged if the statement ran for at least the specified amount of time. https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT */
minSlowLogDurationInMs: number;
/** The load balancer idle timeout, in seconds. Can be between 1 and 4000 seconds */
maxExecutionTimeout: Duration;
listenToPort: number;
};

export function settings(): Settings {
const config = getConfig();
const isLarge = isProd(config) || isSandbox(config);
return {
cpu: isLarge ? 2 * vCPU : 1 * vCPU,
memoryLimitMiB: isLarge ? 4096 : 2048,
taskCountMin: isLarge ? 6 : 1,
taskCountMax: isLarge ? 10 : 5,
minDBCap: isLarge ? 4 : 1,
maxDBCap: isLarge ? 32 : 8,
minSlowLogDurationInMs: 600, // https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT
// The load balancer idle timeout, in seconds. Can be between 1 and 4000 seconds
const defaults = {
minSlowLogDurationInMs: 600,
maxExecutionTimeout: Duration.minutes(15),
listenToPort: 8080,
};
if (isProd(config)) {
return {
...defaults,
cpu: 2 * vCPU,
memoryLimitMiB: 4096,
taskCountMin: 6,
taskCountMax: 10,
minDBCap: 10,
maxDBCap: 48,
};
}
if (isSandbox(config)) {
return {
...defaults,
cpu: 1 * vCPU,
memoryLimitMiB: 1024,
taskCountMin: 1,
taskCountMax: 5,
minDBCap: 3,
maxDBCap: 12,
};
}
return {
...defaults,
cpu: 0.5 * vCPU,
memoryLimitMiB: 1024,
taskCountMin: 1,
taskCountMax: 5,
minDBCap: 0.5,
maxDBCap: 8,
};
}

interface FHIRServerProps extends StackProps {
Expand Down

0 comments on commit 0b48c3c

Please sign in to comment.