技能 硬件工程 优化 Fly.io 基础设施成本

优化 Fly.io 基础设施成本

v20260423
flyio-cost-tuning
本指南提供了一套完整的 Fly.io 成本优化方案。它指导用户如何通过配置自动休眠/挂起服务、精细调整虚拟机规格(Right-sizing),以及清理未使用的存储卷,从而有效降低云基础设施的运行和托管费用,实现资源最大化利用。
获取技能
296 次下载
概览

Fly.io Cost Tuning

Overview

Fly.io charges per-second for running machines plus storage. Key levers: auto-stop idle machines, suspend instead of stop, right-size VMs, and clean up unused volumes.

Pricing Quick Reference

Resource Free Tier Cost
shared-cpu-1x (256mb) 3 VMs free ~$1.94/month each
shared-cpu-1x (512mb) included ~$3.88/month
shared-cpu-2x (1gb) - ~$11.62/month
Volumes 3GB free $0.15/GB/month
Bandwidth 100GB free $0.02/GB after
IPv4 1 free per org $2/month each

Instructions

Strategy 1: Auto-Stop Idle Machines

# fly.toml — stop machines when no traffic
[http_service]
  auto_stop_machines = "stop"     # Full stop (cheapest, ~5s cold start)
  auto_start_machines = true
  min_machines_running = 0        # Allow all machines to stop
  # Use min_machines_running = 1 only for production apps

Strategy 2: Suspend for Faster Resume

# Suspend keeps memory state — resumes in ~100ms but costs ~$0.50/month
[http_service]
  auto_stop_machines = "suspend"

Strategy 3: Audit and Clean Up

# List all apps and their machine counts
fly apps list

# Find idle/stopped machines
fly machine list -a my-app --json | jq '.[] | select(.state != "started") | {id, state, region}'

# Destroy unused apps
fly apps destroy old-app --yes

# List and delete orphaned volumes
fly volumes list -a my-app
fly volumes destroy vol_xxx

Strategy 4: Right-Size VMs

# Check memory usage to see if oversized
fly ssh console -a my-app -C "cat /proc/meminfo | head -3"

# Downgrade if using <50% of allocated memory
fly scale vm shared-cpu-1x --memory 256 -a my-app

Cost Monitoring

# Check current month's usage
fly billing  # Shows org-level billing

# Estimate per-app cost
fly scale show -a my-app  # See VM count and size

Resources

Next Steps

For architecture design, see flyio-reference-architecture.

信息
Category 硬件工程
Name flyio-cost-tuning
版本 v20260423
大小 2.52KB
更新时间 2026-04-26
语言