fade22015f
* Adds new features table to top of v4 upgrade guide * Adds wait idempotency to wait-until, wait-for, and wait-for-token pages * Adds new priority docs page and updates the v4 upgrade guide * Adds new task lifecycle hooks * Removes the message about requiring tasks to be exported * Adds new global lifecycle hooks section * Moves sections from upgrade guide into the table * Adds hidden task page * Improves the global lifecycle hooks section * Updates middleware and locals section * Adds new useWaitToken page to the react hooks section * Adds a new ai.tool section * Moves Docker (legacy) page into self-hosting section * Removes known issues from v4 upgrade guide * Replace “toolTask” with “ai.tool” in the Streams page example * Renames guide to “Migrating from v3” and adds redirect * Remove references to v4 * Removes changelog from migration guide * The installation guide now references `@latest update` * Changes all references from `/sdk/v3` to `/sdk` * Updates @v4-beta to @latest * Fixed broken link * Fixes broken link * Adds an upgrade to v4 using AI section * Fixes 2 broken links * Adds an entry for targetting preview branches * Updates the run statuses * Adds boolean helpers section to the runs and realtime pages * Updates the concurrency page * Updates the test page to include the new options * Adds SDK and curl options for the preview branch targeting * Updates new bulk actions page * Remove the releasing concurrency section * Got rid of some more @v4-beta mentions * Improved rate limit docs * Improved migrating docs * Removed commented sections of the docs * useWaitToken hook * Fixed the description * Fix for missing test image --------- Co-authored-by: Matt Aitken <matt@mattaitken.com> Co-authored-by: Dan <8297864+D-K-P@users.noreply.github.com>
110 lines
3.5 KiB
Plaintext
110 lines
3.5 KiB
Plaintext
---
|
|
title: "Machines"
|
|
description: "Configure the number of vCPUs and GBs of RAM you want the task to use."
|
|
---
|
|
|
|
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.
|
|
|
|
```ts /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:
|
|
|
|
```ts trigger.config.ts
|
|
import type { TriggerConfig } from "@trigger.dev/sdk";
|
|
|
|
export const config: TriggerConfig = {
|
|
machine: "small-2x",
|
|
// ... other config
|
|
};
|
|
```
|
|
|
|
## Machine configurations
|
|
|
|
| Preset | vCPU | Memory | Disk space |
|
|
| :------------------ | :--- | :----- | :--------- |
|
|
| micro | 0.25 | 0.25 | 10GB |
|
|
| small-1x (default) | 0.5 | 0.5 | 10GB |
|
|
| small-2x | 1 | 1 | 10GB |
|
|
| medium-1x | 1 | 2 | 10GB |
|
|
| medium-2x | 2 | 4 | 10GB |
|
|
| large-1x | 4 | 8 | 10GB |
|
|
| large-2x | 8 | 16 | 10GB |
|
|
|
|
You can view the Trigger.dev cloud pricing for these machines [here](https://trigger.dev/pricing#computePricing).
|
|
|
|
## Overriding the machine when triggering
|
|
|
|
You can also override the task machine when you [trigger](/triggering) it:
|
|
|
|
```ts
|
|
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 task ran out of memory. Try increasing the machine specs. If this doesn't fix it there might be a memory leak.
|
|
|
|
We automatically detect common Out Of Memory errors, including when ffmpeg throws an error because it ran out of memory.
|
|
|
|
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.
|
|
|
|
```ts /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:
|
|
|
|
```ts /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 }) => {
|
|
//...
|
|
},
|
|
});
|
|
```
|
|
|
|
<Note>
|
|
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.
|
|
</Note>
|