Back to Microsandbox

Optimization

docs/sandboxes/optimization.mdx

0.6.93.6 KB
Original Source

There is no single fastest setup. Start with the defaults, measure your workload, and change one setting at a time.

Run these commands before tuning anything:

bash
msb doctor
msb inspect worker

msb doctor checks host capabilities. msb inspect shows the settings that a sandbox actually uses.

Quick guide

If you want toStart with
Create OCI sandboxes fasterA flat root disk with clone=auto
Spread CPU-heavy work across physical corescpu_placement: spread
Favor cache localitycpu_placement: compact
Tune large memory mappingsKeep THP at madvise, then benchmark always
Control buffered disk pressure on LinuxKeep block writeback at auto

Storage layout: layered or flat

The default layered root shares OCI layers between sandboxes. A flat root turns the image into one ext4 disk and clones it for each sandbox. This can improve creation time and filesystem-heavy workloads on hosts with copy-on-write cloning.

bash
msb pull python:3.12 --materialize flat
msb create python:3.12 --name worker --root-disk flat:8G,clone=auto

clone=auto uses a native copy-on-write clone when available and falls back to a sparse copy. Use the layered root when image layer sharing or maximum portability matters more.

See OCI images for image behavior and Bootstrap for flat root details.

CPU placement

CPU placement controls where vCPU threads run on Linux and Windows.

PolicyBest starting point for
inheritExternal schedulers and macOS
autoGeneral use on a dedicated host
spreadThroughput across physical cores
compactCache locality and host packing

These policies coordinate sandboxes that share the same MSB_HOME. They do not reserve physical cores or isolate other host processes.

See CPU placement for setup and limits.

Transparent huge pages

Transparent huge pages, or THP, control how the guest handles large memory mappings.

PolicyUse it when
madviseYou want the safe default
alwaysBenchmarks show a gain for large, sustained mappings
neverPredictable small-page behavior matters more

THP changes take effect the next time the sandbox boots. Keep madvise unless real workload tests show a clear improvement.

Buffered block writeback

On Linux, block writeback limits how much buffered disk data active sandboxes can hold in host memory.

  • auto chooses safe limits from the host. This is the recommended setting.
  • fixed uses limits that you provide.
  • off disables the limits for new sandboxes.

This setting has no effect on non-Linux hosts, read-only disks, or direct I/O. See Global config for the available fields.

Host interrupt acceleration

On Linux x86 hosts, AMD AVIC and Intel APICv can make virtual interrupt delivery faster. These are host KVM settings, not sandbox settings.

Check their status with msb doctor. Read Linux troubleshooting before changing a KVM module because the change affects every VM on the host.

Optimizations that are not knobs

Microsandbox automatically selects compatible filesystem, guest kernel, interrupt, and vCPU affinity optimizations. These implementation details do not have user-facing settings.

Measure the result

Keep the image, CPU and memory limits, storage, host power settings, and concurrency unchanged while comparing settings. Measure sandbox creation separately from workload performance.