Skip to main content Início Criadores jeremylongshore tons-of-skills-marketplace langfuse-performance-tuning
langfuse-performance-tuning Optimize Langfuse tracing performance for high-throughput applications.
Use when experiencing latency issues, optimizing trace overhead,
or scaling Langfuse for production workloads.
Trigger with phrases like "langfuse performance", "optimize langfuse",
"langfuse latency", "langfuse overhead", "langfuse slow".
Ir para a instalação Skills Marketplace Descubra e explore skills de IA criadas pela comunidade.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Copiar promptMostrar detalhes do prompt Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
npx skills add https://github.com/jeremylongshore/tons-of-skills-marketplace --skill langfuse-performance-tuningO comando permanece em uma só linha. Role horizontalmente para revisá-lo antes de copiar.
Prefere uma cópia local? Baixe os arquivos disponíveis atualmente no SkillsMP.
Baixar Zip Baixando... Mais deste repositório langchain-deploy-integration Deploy a LangChain 1.0 / LangGraph 1.0 app to Cloud Run, Vercel, or LangServe correctly — with timeouts sized for chain length, cold-start mitigation, SSE anti-buffering headers, and Secret Manager over .env. Use when prepping a first production deploy, debugging a stream that hangs behind a proxy, or diagnosing p99 latency spikes. Trigger with "langchain deploy", "langchain cloud run", "langchain vercel python", "langchain langserve", or "langchain docker".
langchain-langgraph-agents Build a correct LangGraph 1.0 ReAct agent with create_react_agent — typed tools, error propagation, recursion caps, and stop conditions that actually stop. Use when writing a first tool-calling agent, migrating from AgentExecutor or initialize_agent, or diagnosing an agent that loops on vague prompts. Trigger with "langgraph agent", "create_react_agent", "langgraph tool calling", "AgentExecutor migration", or "agent loop cost".
langchain-langgraph-human-in-loop Build LangGraph 1.0 human-in-the-loop approval flows with interrupt_before /
interrupt_after and Command(resume=...) — JSON-serializable state, clean
resume semantics, and UI wiring for approval decisions. Use when adding an
approval gate before an expensive tool call, wiring a Slack/web UI for agent
approvals, or debugging a graph that crashes on interrupt.
Trigger with "langgraph human in loop", "langgraph interrupt_before",
"langgraph approval flow", "Command resume", "langgraph HITL".
name langfuse-performance-tuning description Optimize Langfuse tracing performance for high-throughput applications.
Use when experiencing latency issues, optimizing trace overhead,
or scaling Langfuse for production workloads.
Trigger with phrases like "langfuse performance", "optimize langfuse",
"langfuse latency", "langfuse overhead", "langfuse slow".
allowed-tools Read, Write, Edit version 1.12.0 license MIT author Jeremy Longshore <jeremy@intentsolutions.io> tags ["saas","langfuse","performance","scaling","tracing"] compatibility Designed for Claude Code
Langfuse Performance Tuning
Overview
Optimize Langfuse tracing for minimal overhead and maximum throughput: benchmark measurement, batch tuning, non-blocking patterns, payload optimization, sampling, and memory management.
Prerequisites
Existing Langfuse integration
Performance baseline to compare against
Understanding of async patterns
Performance Targets
Metric Target Critical Trace creation overhead < 1ms < 5ms Flush latency (batch) < 100ms < 500ms Memory per active trace < 1KB < 5KB CPU overhead < 1% < 5%
Instructions
Step 1: Benchmark Current Performance
import { performance } from "perf_hooks" ;
import { startActiveObservation, updateActiveObservation } from "@langfuse/tracing" ;
import { LangfuseSpanProcessor } from "@langfuse/otel" ;
import { NodeSDK } from "@opentelemetry/sdk-node" ;
async function benchmark ( ) {
const sdk = new NodeSDK ({
spanProcessors : [new LangfuseSpanProcessor ()],
});
sdk.start ();
const iterations = 1000 ;
const : [] = [];
( i = ; i < iterations; i++) {
start = performance. ();
( , () => {
({ : { i }, : { : } });
});
timings. (performance. () - start);
}
sorted = timings. ( a - b);
. ( );
. ( );
. ( );
. ( );
. ( );
. ( );
flushStart = performance. ();
sdk. ();
. ( );
}
();
timings
number
for
let
0
const
now
await
startActiveObservation
`bench-${i} `
async
updateActiveObservation
input
output
done
true
push
now
const
sort
(a, b ) =>
console
log
"=== Langfuse Performance Benchmark ==="
console
log
`Iterations: ${iterations} `
console
log
`Mean: ${(sorted.reduce((a, b) => a + b) / sorted.length).toFixed(3 )} ms`
console
log
`P50: ${sorted[Math .floor(sorted.length * 0.5 )].toFixed(3 )} ms`
console
log
`P95: ${sorted[Math .floor(sorted.length * 0.95 )].toFixed(3 )} ms`
console
log
`P99: ${sorted[Math .floor(sorted.length * 0.99 )].toFixed(3 )} ms`
const
now
await
shutdown
console
log
`Flush: ${(performance.now() - flushStart).toFixed(1 )} ms`
benchmark
Step 2: Optimize Batch Configuration
import { LangfuseSpanProcessor } from "@langfuse/otel" ;
import { NodeSDK } from "@opentelemetry/sdk-node" ;
const processor = new LangfuseSpanProcessor ({
exportIntervalMillis : 10000 ,
maxExportBatchSize : 100 ,
maxQueueSize : 4096 ,
});
const sdk = new NodeSDK ({ spanProcessors : [processor] });
sdk.start ();
const langfuse = new Langfuse ({
flushAt : 100 ,
flushInterval : 10000 ,
requestTimeout : 30000 ,
});
Setting Low Volume High Volume Ultra-High Batch size 15 50-100 200 Flush interval 5s 10s 30s Queue size 1024 4096 8192
Step 3: Non-Blocking Trace Wrapper Ensure tracing never blocks your application's critical path:
import { observe, updateActiveObservation } from "@langfuse/tracing" ;
function safeObserve<T extends (...args : any []) => Promise <any >>(
name : string ,
fn : T
): T {
return (async (...args : Parameters <T>) => {
try {
return await observe ({ name }, async () => {
updateActiveObservation ({ input : args });
const result = await fn (...args);
updateActiveObservation ({ output : result });
return result;
})();
} catch (error) {
console .warn (`Tracing failed for ${name} :` , error);
return fn (...args);
}
}) as T;
}
Step 4: Payload Size Optimization Large trace payloads slow down flush and increase costs:
function truncateForTrace (input : any , maxStringLen = 5000 , maxArrayLen = 50 ): any {
if (typeof input === "string" ) {
return input.length > maxStringLen
? input.slice (0 , maxStringLen) + `...[truncated ${input.length - maxStringLen} chars]`
: input;
}
if (Array .isArray (input)) {
return input.slice (0 , maxArrayLen).map ((item ) => truncateForTrace (item));
}
if (input instanceof Buffer || input instanceof Uint8Array ) {
return `[Binary: ${input.length} bytes]` ;
}
if (typeof input === "object" && input !== null ) {
const result : Record <string , any > = {};
for (const [key, value] of Object .entries (input)) {
result[key] = truncateForTrace (value);
}
return result;
}
return input;
}
await startActiveObservation ("process" , async () => {
updateActiveObservation ({
input : truncateForTrace (largeInput),
});
const result = await process (largeInput);
updateActiveObservation ({ output : truncateForTrace (result) });
});
Step 5: Sampling for Ultra-High Volume When you cannot afford to trace every request:
class TraceSampler {
private rate : number ;
private windowMs = 60000 ;
private maxPerWindow : number ;
private timestamps : number [] = [];
constructor (rate : number , maxPerMinute : number ) {
this .rate = rate;
this .maxPerWindow = maxPerMinute;
}
shouldSample (isError = false ): boolean {
if (isError) return true ;
const now = Date .now ();
this .timestamps = this .timestamps .filter ((t ) => t > now - this .windowMs );
if (this .timestamps .length >= this .maxPerWindow ) return false ;
if (Math .random () > this .rate ) return false ;
this .timestamps .push (now);
return true ;
}
}
const sampler = new TraceSampler (0.1 , 1000 );
async function maybeTrace<T>(name : string , fn : () => Promise <T>, isError = false ): Promise <T> {
if (!sampler.shouldSample (isError)) {
return fn ();
}
return startActiveObservation (name, async () => {
updateActiveObservation ({ metadata : { sampled : true } });
return fn ();
});
}
Step 6: Memory Management
function logMemoryStats ( ) {
const mem = process.memoryUsage ();
console .log ({
heapUsedMB : (mem.heapUsed / 1024 / 1024 ).toFixed (1 ),
rssMB : (mem.rss / 1024 / 1024 ).toFixed (1 ),
externalMB : (mem.external / 1024 / 1024 ).toFixed (1 ),
});
}
setInterval (logMemoryStats, 60000 );
Optimization Impact Matrix Optimization Latency Impact Throughput Impact Effort Increase batch size High High Low Non-blocking wrapper High Medium Low Payload truncation Medium Medium Low Sampling High Very High Medium Memory monitoring Low Low Low
Error Handling Issue Cause Solution High P99 latency Sync flush in hot path Use non-blocking wrapper Memory growth No payload limits Truncate inputs/outputs Request timeouts Batch too large Reduce batch size or increase timeout Dropped spans Queue full Increase maxQueueSize
Resources