From 0a2b8b3045adbe3dcd4b2ddaa996fcf924fdc4ee Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 11 Mar 2026 09:25:17 +0800 Subject: [PATCH] serialize batch image processing requests --- app/api/scene-fusion/route.ts | 9 +++++++-- components/scene-fusion-view.tsx | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/api/scene-fusion/route.ts b/app/api/scene-fusion/route.ts index 32ef5ce7f..c8014c08f 100644 --- a/app/api/scene-fusion/route.ts +++ b/app/api/scene-fusion/route.ts @@ -56,7 +56,8 @@ const SCENE_FUSION_MODEL_COOLDOWN_MS = 2 * 60 * 1000; const SCENE_FUSION_MAX_ITEMS = 10; const SCENE_FUSION_REQUEST_STAGGER_MS = 350; const SCENE_FUSION_AGENT_TIMEOUT_MS = 20000; -const SCENE_FUSION_AGENT_MAX_WORKERS = 2; +const SCENE_FUSION_AGENT_MAX_WORKERS = 1; +const SCENE_FUSION_PROCESS_MAX_WORKERS = 1; const SCENE_FUSION_PRE_RMBG_TIMEOUT_MS = 60_000; const SCENE_FUSION_ECHO_HASH_TIMEOUT_MS = 20_000; const SCENE_FUSION_ECHO_HASH_THRESHOLD = 8; @@ -1895,7 +1896,11 @@ export async function POST(request: Request) { let nextSceneIndex = 0; const workerCount = Math.max( 1, - Math.min(4, candidateModels.length, processedScenes.length) + Math.min( + SCENE_FUSION_PROCESS_MAX_WORKERS, + candidateModels.length, + processedScenes.length + ) ); const workers = Array.from({ length: workerCount }, async () => { diff --git a/components/scene-fusion-view.tsx b/components/scene-fusion-view.tsx index b5388c5c3..d7443ecb1 100644 --- a/components/scene-fusion-view.tsx +++ b/components/scene-fusion-view.tsx @@ -39,6 +39,7 @@ import { cn } from "@/lib/utils"; const fetcher = (url: string) => fetch(url).then((res) => res.json()); const MAX_BATCH_ITEMS = 10; const BATCH_REQUEST_STAGGER_MS = 700; +const BATCH_SERIAL_WORKER_COUNT = 1; const MULTI_PRODUCT_FAILOVER_MAX_ROUNDS = 5; const MULTI_PRODUCT_FAILOVER_RETRY_DELAY_MS = 1500; @@ -977,7 +978,10 @@ export function SceneFusionView({ ); const queue = [...itemsToProcess]; - const workerCount = Math.max(1, Math.min(2, queue.length)); + const workerCount = Math.max( + 1, + Math.min(BATCH_SERIAL_WORKER_COUNT, queue.length) + ); let successCount = 0; let failedCount = 0; @@ -1148,7 +1152,10 @@ export function SceneFusionView({ ); const queue = [...itemsToProcess]; - const workerCount = Math.max(1, Math.min(3, queue.length)); + const workerCount = Math.max( + 1, + Math.min(BATCH_SERIAL_WORKER_COUNT, queue.length) + ); let successCount = 0; let failedCount = 0;