Skip to content

Machines

The machine configuration controls CPU and memory allocated to a task run. Higher specs cost more but improve performance for CPU/memory-bound tasks.

Machine Presets

PresetvCPURAMDisk
micro0.250.25 GB10 GB
small-1x (default)0.50.5 GB10 GB
small-2x11 GB10 GB
medium-1x12 GB10 GB
medium-2x24 GB10 GB
large-1x48 GB10 GB
large-2x816 GB10 GB

View pricing at trigger.dev/pricing.

Setting Machine on a Task

ts
import { task } from "@trigger.dev/sdk";

export const heavyTask = task({
  id: "heavy-task",
  machine: "large-1x",
  run: async (payload, { ctx }) => { /* ... */ },
});

Global Default

Set default machine for all tasks in trigger.config.ts:

ts
import type { TriggerConfig } from "@trigger.dev/sdk";

export const config: TriggerConfig = {
  machine: "small-2x",
};

Overriding at Trigger Time

Useful when specific payloads need more resources:

ts
await tasks.trigger(
  "heavy-task",
  { message: "hello world" },
  { machine: "large-2x" }
);

Out-of-Memory (OOM) Errors

Error message: TASK_PROCESS_OOM_KILLED. Your run was terminated due to exceeding the machine's memory limit.

Auto-detected in:

  • Node.js V8 heap limit exceeded
  • Process exceeds machine memory limit
  • Child process (e.g., ffmpeg) exceeds memory and exits with non-zero code

Throw Explicit OOM Error

ts
import { task, OutOfMemoryError } from "@trigger.dev/sdk";

export const yourTask = task({
  id: "your-task",
  machine: "medium-1x",
  run: async (payload) => {
    // Detect OOM before it happens and throw explicitly
    throw new OutOfMemoryError();
  },
});

Auto-Retry with Larger Machine

ts
export const yourTask = task({
  id: "your-task",
  machine: "medium-1x",
  retry: {
    outOfMemory: {
      machine: "large-1x", // only triggers on OOM, doesn't change default
    },
  },
  run: async (payload) => { /* ... */ },
});

Resource Monitoring

Log memory and CPU at regular intervals:

ts
import { tasks } from "@trigger.dev/sdk";
import { ResourceMonitor } from "../resourceMonitor.js";

tasks.middleware("resource-monitor", async ({ ctx, next }) => {
  const resourceMonitor = new ResourceMonitor({ ctx });
  if (process.env.RESOURCE_MONITOR_ENABLED === "1") {
    resourceMonitor.startMonitoring(1_000); // every 1 second
  }
  await next();
  resourceMonitor.stopMonitoring();
});

Monitor a child process:

ts
const monitor = new ResourceMonitor({ ctx, processName: "ffmpeg" });

Self-Hosting: Machine Overrides

Set MACHINE_PRESETS_OVERRIDE_PATH to a JSON file to customize machine specs:

json
{
  "defaultMachine": "small-1x",
  "machines": {
    "micro":    { "cpu": 0.25, "memory": 0.25 },
    "small-1x": { "cpu": 0.5,  "memory": 0.5 },
    "small-2x": { "cpu": 1,    "memory": 1 }
  }
}

Built from official Trigger.dev documentation