Changelog #107

·

v4: Faster warm starts with processKeepAlive

Eric Allam

Eric Allam

CTO, Trigger.dev

Image for v4: Faster warm starts with processKeepAlive

We've added an experimental processKeepAlive option that keeps the task process alive after run completion, making warm starts even faster.

Currently during a warm start, we still recreate the actual task run process between runs, leading to a completely fresh global environment for each run. This experimental option will keep the task run process alive between run executions, leading to even faster warm starts. This option is respected in both the dev CLI and in deployed tasks.

Installation

Make sure you update your @trigger.dev/sdk and trigger.dev CLI packages to the latest beta version 4.0.0-v4-beta.22:


# Install the latest beta version of the SDK and any other @trigger.dev/* packages
pnpm add @trigger.dev/[email protected]
# Use the latest beta version of the CLI

Usage

To enable this option, add this to your trigger.config.ts:


import { defineConfig } from "@trigger.dev/sdk";
export default defineConfig({
project: "<project ref>",
// This is false by default
experimental_processKeepAlive: true,
maxDuration: 60,
});

You can also pass an object to experimental_processKeepAlive to provide more options:


import { defineConfig } from "@trigger.dev/sdk";
export default defineConfig({
project: "<project ref>",
experimental_processKeepAlive: {
enabled: true,
// After 20 runs execute with a single process, we'll restart the process and start fresh
maxExecutionsPerProcess: 20,
// In dev, you can combine this option with setting a max pool size, giving you the ability to limit the number of processes created on your local dev machine.
devMaxPoolSize: 10,
},
maxDuration: 60,
});

Important considerations

  • Memory usage: Be careful with memory usage and memory leaks, as this will cause memory to persist across run executions.
  • Process sharing: It's possible different tasks get executed in the same persisted process.
  • SDK configuration: If you configure any 3rd party SDKs globally using env vars for API keys, those SDKs will not change between runs. So if you change an env var between runs, the SDK will be "stale" and continue using the old env var value. Instead, you should initialize SDKs using env vars at runtime (in any of the lifecycle hooks or inside the run function of a task).
  • Task cancellation: Cancelling a task will cause the task run process to be restarted. Exiting the process is the only reliable way to actually stop a running function from stopping.
  • Cold starts: This DOES NOT affect cold starts, warm starts only will be improved.

We recommend enabling this option and testing in a staging or preview environment before trying it out in prod, as there could be unknown issues depending on what you are doing in your tasks. #2183

Ready to start building?

Build and deploy your first task in 3 minutes.

Get started now