Resource configuration
Choose memory, CPU, and scaling for a deployed DVM, and keep long-running jobs alive.
Most DVMs should start with the generated defaults. Add a dvmkit block to package.json only when the workload or measured production behavior requires something different.
{
"dvmkit": {
"memory_mb": 1024,
"cpu_count": 1,
"cpu_kind": "shared",
"min_machines_running": 0,
"max_machines": 1
}
}| Field | Range | Meaning |
|---|---|---|
memory_mb | 256–16384 | RAM per machine |
cpu_count | 1–16 | vCPUs per machine |
cpu_kind | shared or performance | Shared or dedicated-performance CPU class |
min_machines_running | 0–100 | Machines kept warm |
max_machines | 1–100 | Maximum concurrent machines |
max_machines must be at least min_machines_running. With cpu_kind: "performance", memory_mb must be at least 2048 per CPU (2048 for one CPU, 4096 for two); the default memory is smaller, so set memory_mb whenever you choose performance CPUs. These ranges are platform safety bounds. Your plan can impose lower limits; a rejected deploy names the requested resource and allowed limit. An unlimited plan has no plan cap but still uses the 100-machine platform ceiling.
Pick memory from the work
- 256 MB: HTTP calls, JSON parsing, small text transforms.
- 512 MB: moderate documents or images and larger response assembly.
- 1024 MB: headless browsers, ffmpeg, yt-dlp, or Python subprocesses.
- 2048 MB and above: large local models, long media, or datasets.
These are starting points. Use dvmctl status and logs to measure the deployed process, then move one tier at a time. An out-of-memory kill calls for more memory or a smaller working set, not more machines.
Keep scaling simple
min_machines_running: 0 allows scale-to-zero. With one Machine awake, the SDK keeps it running while a handler runs, including during long jobs. The first request after idle still waits for the Machine to resume. Choose always-on when you need instant first responses and accept the standing cost. Long jobs with several Machines awake need a different setting; see long-running jobs.
Keep max_machines: 1 until concurrent jobs are queueing long enough to matter. More machines increase parallel capacity and the maximum running cost. They do not make one CPU-bound job faster.
Shared CPUs suit services that wait on APIs, storage, or networks. Use performance CPUs only after measurement shows local CPU is the bottleneck.
Long-running jobs
For a long job, choose scaling for the number of Machines that can be awake, budget for the full running time, and avoid replacing the process while it works.
Keep the Machine up while it works
With SDK 0.28.0 or later and one Machine awake, a periodic keepalive request keeps the Machine running while a handler runs. It can suspend a few minutes after the job ends. The default min_machines_running: 0 and max_machines: 1 let occasional long jobs use scale-to-zero.
In probe runs, one awake Machine stayed running through 25-minute jobs with no caller traffic. The keepalive is best-effort, and longer jobs have not been measured.
Several awake Machines
With several Machines awake, the keepalive does not protect the job. Fly can suspend the Machine doing the work while leaving another running. For long-job DVMs that need several Machines, set min_machines_running equal to max_machines:
{
"dvmkit": {
"min_machines_running": 2,
"max_machines": 2
}
}min_machines_running: 1 on its own is not enough when max_machines is higher. The floor keeps some Machine running, not necessarily the one doing your job, so the busy Machine can still be stopped while an idle one stays up.
A job waiting on the caller does not need this. While a prompt or payment request is open the job is not working, and the caller's answer is an incoming request that wakes the Machine. The job then continues, or replays from its completed steps. How long the caller has to answer is the DVM's idleTimeout; see configureDVM.
What always-on costs
Compute is billed for every second a Machine is awake. With scale-to-zero, that includes the full job and the awake time before it suspends. The keepalive does not make that time free.
An always-on Machine is billed for every hour of the month. At current hosting rates, one shared-CPU Machine costs about $10 a month with 512 MB and about $18 a month with 1024 MB. Your plan's monthly hosting credit counts toward that. Those figures come from the hosting rate of 0.25¢ per shared-CPU hour plus 2.2¢ per GB of memory per hour, rounded up to the next 0.1¢ per Machine-hour, over a 720-hour month.
Don't deploy in the middle of a job
dvmctl deploy, dvmctl restart, and dvmctl rollback replace the running process without waiting for jobs to finish. A job that is working when this happens stops, and it is marked failed about 5 minutes later. Deploy, restart, or roll back only when no long job is running.
Examples
A network-bound text service:
{
"dvmkit": {
"memory_mb": 256,
"cpu_kind": "shared",
"min_machines_running": 0,
"max_machines": 1
}
}A container that runs Chromium or ffmpeg:
{
"dvmkit": {
"memory_mb": 1024,
"cpu_kind": "shared",
"min_machines_running": 0,
"max_machines": 1
}
}Run dvmctl validate after every configuration change and dvmctl deploy --dry-run before applying it. See deploying for the surrounding identity and payment decisions.