🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
perf: batch read single S3 events (#5298)
Max Deichmann774efa4eaa93
diff --git a/worker/src/queues/ingestionQueue.ts b/worker/src/queues/ingestionQueue.tsindex 04b7fb41cc..db96551b3c 100644--- a/worker/src/queues/ingestionQueue.ts+++ b/worker/src/queues/ingestionQueue.ts@@ -19,6 +19,7 @@ import { prisma } from "@langfuse/shared/src/db";import { env } from "../env";import { IngestionService } from "../services/IngestionService";import { ClickhouseWriter } from "../services/ClickhouseWriter";+import { chunk } from "lodash";let s3StorageServiceClient: StorageService;@@ -118,15 +119,23 @@ export const ingestionQueueProcessorBuilder = (.map((fileRef) => fileRef.createdAt).sort().shift() ?? new Date();- const events: IngestionEventType[] = (- await Promise.all(- eventFiles.map(async (fileRef) => {- const file = await s3Client.download(fileRef.file);- const parsedFile = JSON.parse(file);- return Array.isArray(parsedFile) ? parsedFile : [parsedFile];- }),- )- ).flat();++ const S3_CONCURRENT_READS = 50;+ const events: IngestionEventType[] = [];++ // Process files in batches+ // If a user has 5k events, this will likely take 100 seconds.+ const downloadAndParseFile = async (fileRef: { file: string }) => {+ const file = await s3Client.download(fileRef.file);+ const parsedFile = JSON.parse(file);+ return Array.isArray(parsedFile) ? parsedFile : [parsedFile];+ };++ const batches = chunk(eventFiles, S3_CONCURRENT_READS);+ for (const batch of batches) {+ const batchEvents = await Promise.all(batch.map(downloadAndParseFile));+ events.push(...batchEvents.flat());+ }if (events.length === 0) {logger.warn(