Skip to content

dfc2: move to a cheaper instance type (m6a.large → t3a.large), only once the measurements allow it - #26

Draft
atalyaalon wants to merge 2 commits into
claude/laughing-galileo-165xk1-shutdown-dfcfrom
claude/laughing-galileo-165xk1-machine-size
Draft

atalyaalon wants to merge 2 commits into
claude/laughing-galileo-165xk1-shutdown-dfcfrom
claude/laughing-galileo-165xk1-machine-size

Conversation

@atalyaalon

@atalyaalon atalyaalon commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Deployment status (2026-11-28): nothing from this PR is live

  • Live on the servers: only the monthly backup schedule from #24. It went out early when a branch push triggered the deploy workflows (details).
  • Not live: this instance type change. It only happens on terraform apply, which has not been run. dfc2 is still m6a.large.

💰 Estimated saving: $13/month ($156/year) on dfc2

  • m6a.large ~$76/month → t3a.large ~$63/month (on-demand, eu-central-1, approximate).
  • Same 2 CPUs and 8 GB of memory. The difference is that t3a CPU is burstable: it's cheap when mostly idle, and bills extra if it stays busy for long.
  • ⛔ Don't merge until the conditions below are met. They depend on @tkalir's measurements requested in #25.

Related PRs

# PR What
— data-for-change/anyway#2964 PostgreSQL 18 upgrade (anyway#2965 is stacked on it)
1 data-for-change/anyway#2965 Local dev restore uses the latest complete dump
2 data-for-change/dfc-iac#24 Monthly DB backups, clean-up, 1-year expiry, deploys only from main
3 data-for-change/dfc-iac#25 Free uptime + backup monitoring, and the measurements this PR needs
4 This PR, data-for-change/dfc-iac#26 dfc2 instance type

Stacked on #25 (base claude/laughing-galileo-165xk1-monitoring), so this diff shows only this PR's change.

Change

  • modules/dfc/variables.tf: new instance_type variable (default m6a.large, so the dfc server doesn't change) and a cpu_credits variable (default unlimited).
  • modules/dfc/main_docker.tf:
    • uses var.instance_type
    • adds a credit_specification only for burstable t* types
    • unlimited means the CPU is never slowed down; time above the baseline is billed at ~$0.05 per vCPU-hour instead
  • modules.tf: module "dfc2" sets instance_type = "t3a.large".

⛔ Conditions to merge (all must be true)

Based on the measurements requested from @tkalir in #25, including while the heaviest Airflow DAGs run:

  1. Memory:

    • the peak used in free -m on dfc2 stays under ~6 GB while the heaviest DAGs run
    • dmesg shows no out-of-memory kills

    t3a.large has the same 8 GB as today, so this mostly confirms there's headroom. If item 1 (moving dfc's Vault/Redash to dfc2) happens first, add their memory.

  2. CPU:

    • the 2-week average CPUUtilization on dfc2 is under ~25%
    • periods above 30% are short: at most a few hours a week, e.g. the weekly ETL

    t3a.large's free baseline is 30%. Time above it costs extra, and if it adds up to more than about 260 vCPU-hours a month, it cancels the saving.

  3. Timing:

    • not during an Airflow run, and not on the 1st of the month (backup day)
    • someone is available to check the site for ~30 minutes afterwards

If the numbers point elsewhere, change the value in modules.tf before merging, or close this PR:

Measurements show Set instance_type to Price/month
Peak memory under ~3 GB (including anything moved from dfc), CPU mostly idle t3a.medium (4 GB) ~$32
The conditions above t3a.large (this PR) ~$63
Average CPU often above ~30% close this PR (stay on m6a.large) ~$76
Peak memory above ~6.5 GB, or out-of-memory kills m6a.xlarge (16 GB) ~$151

✅ Checks before terraform apply

  1. Where the data disk is mounted. Make sure /data is in /etc/fstab by UUID or LABEL, not by a device name like /dev/nvme1n1. Device names can change on a stop/start.
    bin/apps-dfc2.py ssh "cat /etc/fstab; lsblk -f"
    If /data is missing from fstab, or uses a device name, fix that first. Otherwise the server can boot without /data, and Postgres would start on an empty directory.
  2. The instance type is available in the same zone:
    aws ec2 describe-instance-type-offerings --region eu-central-1 --location-type availability-zone \
      --filters Name=location,Values=eu-central-1b Name=instance-type,Values=t3a.large
  3. Take a fresh snapshot of the data and root disks (EC2 → Volumes → dfc2-main-docker → Create snapshot), or note that this month's DLM snapshot exists.
  4. Check the plan:

What happens on apply

  • Terraform stops the instance, changes its type and starts it again. Expect ~3–5 minutes of downtime for everything on dfc2: www.anyway.co.il, safety-data, airflow and reports.
  • The Elastic IP and both disks stay attached. Containers restart by themselves (restart: unless-stopped).

✅ Checks after apply

  1. The new type is in place:
    aws ec2 describe-instances --region eu-central-1 --filters Name=tag:Name,Values=dfc2-main-docker \
      --query 'Reservations[].Instances[].[InstanceType,State.Name]' --output text
  2. Disks and containers are up:
    bin/apps-dfc2.py ssh "df -h /data; docker ps --format '{{.Names}} {{.Status}}'"
  3. Sites: run Monitor uptime by hand (from Free uptime + DB backup monitoring, remove paid Route53 health checks #25), or open www.anyway.co.il and safety-data.anyway.co.il.
  4. Airflow: the next scheduled DAG runs succeed, and airflow.anyway.co.il/health is healthy.
  5. For the next 2 weeks, check the CloudWatch metric CPUSurplusCreditsCharged for the instance (EC2 → Monitoring). If it's regularly above 0, the instance pays for extra CPU and the saving shrinks. Consider going back.

Rollback

Set instance_type back to m6a.large in modules.tf and terraform apply. That's another ~3–5 minute stop/start, and no data is touched.

Later

  • Buy the Savings Plan only after the final instance type is known. Use a Compute Savings Plan, which also covers t3a.
  • Do this after item 1 (shutting down dfc) if that's planned soon, so dfc2 is sized for the combined load.

Testing

  • I couldn't run terraform validate or terraform plan here, because the Terraform registry is blocked. CI's terraform plan on this PR is the first check.
  • substr() is used instead of startswith(), because startswith() only exists from Terraform 1.3 and CI uses 1.2.9.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV

@atalyaalon
atalyaalon requested review from tkalir and ziv17 November 28, 2026 07:06
@atalyaalon
atalyaalon force-pushed the claude/laughing-galileo-165xk1-machine-size branch from dcc084c to 48d286f Compare November 28, 2026 07:08
atalyaalon pushed a commit that referenced this pull request Nov 29, 2026
- targeted apply for removing the old disk (no untargeted apply)
- stop if the add-disk plan touches the instance (#26 pulled in)
- final rsync with --modify-window=-1 (or --checksum) so same-second
  DB changes aren't skipped
- find the new disk by its volume-ID serial before mkfs
- run long steps in tmux, daemon-reload after fstab, keep mount
  options, check cron jobs, note rollback data loss and snapshot cost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
atalyaalon pushed a commit that referenced this pull request Nov 30, 2026
- targeted apply for removing the old disk (no untargeted apply)
- stop if the add-disk plan touches the instance (#26 pulled in)
- final rsync with --modify-window=-1 (or --checksum) so same-second
  DB changes aren't skipped
- find the new disk by its volume-ID serial before mkfs
- run long steps in tmux, daemon-reload after fstab, keep mount
  options, check cron jobs, note rollback data loss and snapshot cost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
@atalyaalon
atalyaalon force-pushed the claude/laughing-galileo-165xk1-machine-size branch from 48d286f to 3d54647 Compare November 30, 2026 00:35
@atalyaalon
atalyaalon changed the base branch from claude/laughing-galileo-165xk1-monitoring to claude/laughing-galileo-165xk1-shutdown-dfc November 30, 2026 00:36
@atalyaalon
atalyaalon added this pull request to stack #31 November 30, 2026 01:00
dfc2 moves from m6a.large to t3a.large (same 2 vCPU / 8 GiB, burstable
CPU, ~$13/month cheaper). The dfc server keeps the m6a.large default.
Burstable types get an explicit credit_specification (unlimited by
default, so the CPU is never throttled).

Only merge once the measurements show it fits, see the PR description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
substr(type, 0, 1) == "t" also matched non-burstable trn* types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
atalyaalon pushed a commit that referenced this pull request Nov 30, 2026
- targeted apply for removing the old disk (no untargeted apply)
- stop if the add-disk plan touches the instance (#26 pulled in)
- final rsync with --modify-window=-1 (or --checksum) so same-second
  DB changes aren't skipped
- find the new disk by its volume-ID serial before mkfs
- run long steps in tmux, daemon-reload after fstab, keep mount
  options, check cron jobs, note rollback data loss and snapshot cost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
@atalyaalon
atalyaalon force-pushed the claude/laughing-galileo-165xk1-machine-size branch from 3d54647 to a1db928 Compare November 30, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants