Resource Configuration
Configure CPU and memory limits for machines.
TIP
There's no limit on how many machines you can create — machine count is never capped. Usage is measured by total vCPU and memory, not the number of machines.Basic Configuration
TypeScriptconst machine = await Machine.create({
name: 'high-performance',
resources: {
cpus: 4,
memoryMb: 2048
}
}); Python from smolvm import MachineConfig, ResourceSpec
config = MachineConfig(
name="high-performance",
resources=ResourceSpec(
cpus=4,
memory_mb=2048
)
) Resource Options
| Option | Type | Default | Description |
|---|---|---|---|
cpus | number | 4 | Number of vCPUs |
memoryMb / memory_mb | number | 8192 | Memory in megabytes (elastic via virtio balloon) |
gpu | boolean | false | Enable GPU acceleration (details) |
network | boolean | default applied by the server if omitted | Enable networking |
overlayGb | number | default applied by the server if omitted | Overlay (writable layer) size in gigabytes |
storageGb | number | default applied by the server if omitted | Persistent storage size in gigabytes |
Default Resources
If not specified, machines use:
- 1 vCPU
- 512 MB memory
Resource Examples
Minimal (CI tasks)
resources: {
cpus: 1,
memoryMb: 256
} Standard (most workloads)
resources: {
cpus: 2,
memoryMb: 1024
} High Performance (ML, compilation)
resources: {
cpus: 4,
memoryMb: 4096
} Best Practices
Match Workload Needs
Don’t over-allocate resources. More vCPUs doesn’t always mean faster:
// For I/O bound tasks, 1-2 CPUs is usually sufficient
const ioMachine = await Machine.create({
name: 'io-task',
resources: { cpus: 1, memoryMb: 512 }
});
// For CPU-intensive tasks, allocate more
const cpuMachine = await Machine.create({
name: 'cpu-task',
resources: { cpus: 4, memoryMb: 2048 }
}); Memory for Large Data
Python data processing often needs more memory:
# Processing large datasets
config = MachineConfig(
name="data-processing",
resources=ResourceSpec(
cpus=2,
memory_mb=4096 # 4GB for pandas/numpy
)
) Compilation Tasks
Compilation benefits from multiple cores:
const machine = await Machine.create({
name: 'builder',
resources: {
cpus: 4, // Parallel compilation
memoryMb: 2048 // Linking needs memory
}
});
await machine.run('rust:alpine', ['cargo', 'build', '--release', '-j4']);