Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .server-changes/read-replica-snapshots-since.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: improvement
---

Add `RUN_ENGINE_READ_REPLICA_SNAPSHOTS_SINCE_ENABLED` flag (default off) to route the Prisma reads inside `RunEngine.getSnapshotsSince` through the read-only replica client. Offloads the snapshot polling queries (fired by every running task runner) from the primary. When disabled, behavior is unchanged.
1 change: 1 addition & 0 deletions apps/webapp/app/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ const EnvironmentSchema = z
.enum(["log", "error", "warn", "info", "debug"])
.default("info"),
RUN_ENGINE_TREAT_PRODUCTION_EXECUTION_STALLS_AS_OOM: z.string().default("0"),
RUN_ENGINE_READ_REPLICA_SNAPSHOTS_SINCE_ENABLED: z.string().default("0"),

/** How long should the presence ttl last */
DEV_PRESENCE_SSE_TIMEOUT: z.coerce.number().int().default(30_000),
Expand Down
2 changes: 2 additions & 0 deletions apps/webapp/app/v3/runEngine.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function createRunEngine() {
logLevel: env.RUN_ENGINE_WORKER_LOG_LEVEL,
treatProductionExecutionStallsAsOOM:
env.RUN_ENGINE_TREAT_PRODUCTION_EXECUTION_STALLS_AS_OOM === "1",
readReplicaSnapshotsSinceEnabled:
env.RUN_ENGINE_READ_REPLICA_SNAPSHOTS_SINCE_ENABLED === "1",
worker: {
disabled: env.RUN_ENGINE_WORKER_ENABLED === "0",
workers: env.RUN_ENGINE_WORKER_COUNT,
Expand Down
3 changes: 2 additions & 1 deletion internal-packages/run-engine/src/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,8 @@ export class RunEngine {
snapshotId: string;
tx?: PrismaClientOrTransaction;
}): Promise<RunExecutionData[] | null> {
const prisma = tx ?? this.prisma;
const prisma =
tx ?? (this.options.readReplicaSnapshotsSinceEnabled ? this.readOnlyPrisma : this.prisma);
Comment thread
ericallam marked this conversation as resolved.

try {
const snapshots = await getExecutionSnapshotsSince(prisma, runId, snapshotId);
Expand Down
4 changes: 4 additions & 0 deletions internal-packages/run-engine/src/engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export type RunEngineOptions = {
/** Optional maximum TTL for all runs (e.g. "14d"). If set, runs without an explicit TTL
* will use this as their TTL, and runs with a TTL larger than this will be clamped. */
defaultMaxTtl?: string;
/** When true, `getSnapshotsSince` reads through the read-only replica client instead
* of the primary. Defaults to false. Callers passing an explicit `tx` always use
* that client regardless of this flag. */
readReplicaSnapshotsSinceEnabled?: boolean;
tracer: Tracer;
meter?: Meter;
logger?: Logger;
Expand Down
Loading