The machine configuration is optional. Using higher spec machines will increase the cost of running the task but can also improve the performance of the task if it is CPU or memory bound.
/trigger/heavy-task.ts
import { task } from "@trigger.dev/sdk";

export const heavyTask = task({
  id: "heavy-task",
  machine: "large-1x",
  run: async ({ payload, ctx }) => {
    //...
  },
});
The default machine is small-1x which has 0.5 vCPU and 0.5 GB of RAM. You can change the default machine in your trigger.config.ts file:
trigger.config.ts
import type { TriggerConfig } from "@trigger.dev/sdk";

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

Machine configurations

PresetvCPUMemoryDisk space
micro0.250.2510GB
small-1x (default)0.50.510GB
small-2x1110GB
medium-1x1210GB
medium-2x2410GB
large-1x4810GB
large-2x81610GB
You can view the Trigger.dev cloud pricing for these machines here.

Overriding the machine when triggering

You can also override the task machine when you trigger it:
await tasks.trigger<typeof heavyTask>(
  "heavy-task",
  { message: "hello world" },
  { machine: "large-2x" }
);
This is useful when you know that a certain payload will require more memory than the default machine. For example, you know it’s a larger file or a customer that has a lot of data.

Out Of Memory (OOM) errors

Sometimes you might see one of your runs fail with an “Out Of Memory” error.
TASK_PROCESS_OOM_KILLED. Your run was terminated due to exceeding the machine’s memory limit. Try increasing the machine preset in your task options or replay using a larger machine.
We automatically detect common Out Of Memory errors:
  • When using Node.js, if the V8 heap limit is exceeded (this can happen when creating large long-lived objects)
  • When the entire process exceeds the memory limit of the machine the run is executing on.
  • When a child process, such as ffmpeg, causes the memory limit of the machine to be exceeded, and exits with a non-zero code.

Memory/Resource monitoring

To better understand why an OOM error occurred, we’ve published a helper class that will log memory debug information at regular intervals. First, add this ResourceMonitor class to your project:
Then, in your task, you can create an instance of the ResourceMonitor class and start monitoring memory, disk, and CPU usage:
/src/trigger/example.ts
import { task, logger, wait } from "@trigger.dev/sdk";
import { ResourceMonitor } from "../resourceMonitor.js";

// Middleware to enable the resource monitor
tasks.middleware("resource-monitor", async ({ ctx, next }) => {
  const resourceMonitor = new ResourceMonitor({
    ctx,
  });

  // Only enable the resource monitor if the environment variable is set
  if (process.env.RESOURCE_MONITOR_ENABLED === "1") {
    resourceMonitor.startMonitoring(1_000);
  }

  await next();

  resourceMonitor.stopMonitoring();
});

export const resourceMonitorTest = task({
  id: "resource-monitor-test",
  run: async (payload: any, { ctx }) => {
    const interval = createMemoryPressure();

    await setTimeout(180_000);

    clearInterval(interval);

    return {
      message: "Hello, resources!",
    };
  },
});
This will produce logs that look like this: Resource monitor logs If you are spawning a child process and you want to monitor its memory usage, you can pass the processName option to the ResourceMonitor class:
/src/trigger/example.ts
const resourceMonitor = new ResourceMonitor({
  ctx,
  processName: "ffmpeg",
});
This will produce logs that includes the memory and CPU usage of the ffmpeg process: Resource monitor logs

Explicit OOM errors

You can explicitly throw an Out Of Memory error in your task. This can be useful if you use a native package that detects it’s going to run out of memory and then stops before it runs out. If you can detect this, you can then throw this error.
/trigger/heavy-task.ts
import { task } from "@trigger.dev/sdk";
import { OutOfMemoryError } from "@trigger.dev/sdk";

export const yourTask = task({
  id: "your-task",
  machine: "medium-1x",
  run: async (payload: any, { ctx }) => {
    //...

    throw new OutOfMemoryError();
  },
});
If OOM errors happen regularly you need to either optimize the memory-efficiency of your code, or increase the machine.

Retrying with a larger machine

If you are seeing rare OOM errors, it might make sense to add a setting to your task to retry with a large machine when an OOM happens:
/trigger/heavy-task.ts
import { task } from "@trigger.dev/sdk";

export const yourTask = task({
  id: "your-task",
  machine: "medium-1x",
  retry: {
    outOfMemory: {
      machine: "large-1x",
    },
  },
  run: async (payload: any, { ctx }) => {
    //...
  },
});
This will only retry the task if you get an OOM error. It won’t permanently change the machine that a new run starts on, so if you consistently see OOM errors you should change the machine in the machine property.