Skip to content

Commit 309e96c

Browse files
committed
docs(rivetkit): raise serverless start payload limit
1 parent fc4d9c4 commit 309e96c

7 files changed

Lines changed: 33 additions & 4 deletions

File tree

examples/kitchen-sink/package.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/kitchen-sink/src/index.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rivetkit-rust/packages/rivetkit-core/src/engine_process.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use crate::error::EngineProcessError;
1212

1313
const ENGINE_RUNTIME: &str = "engine";
1414
const RIVETKIT_RUNTIME: &str = "rivetkit";
15+
const DEFAULT_MALLOC_ARENA_MAX: &str = "2";
16+
const DEFAULT_MALLOC_TRIM_THRESHOLD: &str = "131072";
1517

1618
#[derive(Debug, Deserialize)]
1719
struct EngineHealthResponse {
@@ -110,6 +112,7 @@ impl EngineProcessManager {
110112
.stdin(Stdio::null())
111113
.stdout(Stdio::from(stdout_file))
112114
.stderr(Stdio::from(stderr_file));
115+
set_default_allocator_env(&mut command);
113116

114117
// Put the engine in its own process group so terminal signals
115118
// (Ctrl+C, Ctrl+Z, SIGHUP on terminal close) targeting our foreground
@@ -176,6 +179,15 @@ impl EngineProcessManager {
176179
}
177180
}
178181

182+
fn set_default_allocator_env(command: &mut Command) {
183+
if std::env::var_os("MALLOC_ARENA_MAX").is_none() {
184+
command.env("MALLOC_ARENA_MAX", DEFAULT_MALLOC_ARENA_MAX);
185+
}
186+
if std::env::var_os("MALLOC_TRIM_THRESHOLD_").is_none() {
187+
command.env("MALLOC_TRIM_THRESHOLD_", DEFAULT_MALLOC_TRIM_THRESHOLD);
188+
}
189+
}
190+
179191
impl Drop for EngineProcessManager {
180192
fn drop(&mut self) {
181193
if let Some(handle) = self.watcher.take() {

rivetkit-typescript/packages/rivetkit/src/registry/config/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import {
2525
isDev,
2626
} from "@/utils/env-vars";
2727
import { EnvoyConfigSchema } from "./envoy";
28-
import { ConfigurePoolSchema, ServerlessConfigSchema } from "./serverless";
28+
import {
29+
ConfigurePoolSchema,
30+
DEFAULT_SERVERLESS_MAX_START_PAYLOAD_BYTES,
31+
ServerlessConfigSchema,
32+
} from "./serverless";
2933

3034
export const ActorsSchema = z.record(
3135
z.string(),
@@ -505,7 +509,7 @@ export const DocServerlessConfigSchema = z
505509
.number()
506510
.optional()
507511
.describe(
508-
"Maximum POST /start body size in bytes. Default: 1048576",
512+
`Maximum POST /start body size in bytes. Default: ${DEFAULT_SERVERLESS_MAX_START_PAYLOAD_BYTES}`,
509513
),
510514
publicEndpoint: z
511515
.string()

rivetkit-typescript/packages/rivetkit/src/registry/config/serverless.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { z } from "zod/v4";
22
import { getRivetPublicEndpoint, getRivetPublicToken } from "@/utils/env-vars";
33

4+
export const DEFAULT_SERVERLESS_MAX_START_PAYLOAD_BYTES = 16 * 1024 * 1024;
5+
46
export const ConfigurePoolSchema = z
57
.object({
68
name: z.string().optional(),
@@ -17,7 +19,10 @@ export const ConfigurePoolSchema = z
1719
export const ServerlessConfigSchema = z.object({
1820
// MARK: Routing
1921
basePath: z.string().optional().default("/api/rivet"),
20-
maxStartPayloadBytes: z.number().optional().default(1_048_576),
22+
maxStartPayloadBytes: z
23+
.number()
24+
.optional()
25+
.default(DEFAULT_SERVERLESS_MAX_START_PAYLOAD_BYTES),
2126

2227
// MARK: Public Endpoint Configuration
2328
/**

website/src/content/docs/actors/limits.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ These limits apply to the [SQLite database](/docs/actors/state#sqlite-database)
9393

9494
### KV Preloading
9595

96-
When an actor starts, the engine can pre-fetch KV data declared in the actor name metadata and deliver it alongside the start command. This removes round-trips to storage during actor startup. RivetKit emits the preload manifest from its own key layout and exposes per-actor overrides via `options`. Operators can still enforce a global cap in the [engine config](/docs/self-hosting/configuration) with `pegboard.preload_max_total_bytes`.
96+
When an actor starts, the engine can pre-fetch KV data declared in the actor name metadata and deliver it alongside the start command. This removes round-trips to storage during actor startup. RivetKit emits the preload manifest from its own key layout and exposes per-actor overrides via `options`. Operators can still enforce a global cap in the [engine config](/docs/self-hosting/configuration) with `pegboard.preload_max_total_bytes`. In serverless mode, this data is serialized into the `/api/rivet/start` request body along with actor config and protocol metadata, so the accepted body size must be larger than the preload budget. RivetKit defaults `serverless.maxStartPayloadBytes` to 16 MiB to leave margin for the default 1 MiB preload budget and larger SQLite startup page preloads.
9797

9898
| Name | Soft Limit | Hard Limit | Description |
9999
|------|------------|------------|-------------|

website/src/content/docs/general/production-checklist.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ We recommend passing this page to your coding agent to verify your configuration
2121
### Serverless
2222

2323
- **Check platform timeouts.** Rivet handles migration between invocations automatically, but shorter timeouts increase migration frequency. See [Timeouts](/docs/general/runtime-modes#timeouts).
24+
- **Verify `/api/rivet/start` body size limits.** Serverless actor starts carry actor config and preloaded KV or SQLite startup data in the request body. Keep `serverless.maxStartPayloadBytes` and your platform or proxy body limit at **16 MiB or higher**, or lower the preload budget if your platform cannot accept that size. See [Limits](/docs/actors/limits#kv-preloading).
2425
- **Configure max runners.** Go to Settings > Providers > Edit Provider > Max Runners to set the limit. The default is 100,000 runners. This is effectively your max actor count.
2526

2627
### Runner

0 commit comments

Comments
 (0)