Technologies/Express/express.eventloop.lag
ExpressExpressMetric

express.eventloop.lag

Event loop lag
Dimensions:None
Available on:PrometheusPrometheus (1)
Interface Metrics (1)
PrometheusPrometheus
Lag of event loop in seconds, indicating how long tasks are waiting in the event queue
Dimensions:None

Technical Annotations (105)

Configuration Parameters (11)
prisma.transaction.timeoutrecommended: 5000
Default Prisma transaction timeout in milliseconds
trace.logs.limitrecommended: 25000
Maximum number of logs to display in trace view
THRESHOLD_NSrecommended: 100000000
100ms threshold in nanoseconds for event loop monitoring
alert.eventloop.lag.thresholdrecommended: 1000
Alert threshold in milliseconds for event loop lag
chunkSizerecommended: 10000
Process 10,000 iterations at a time when chunking heavy calculations
package-lock.jsonrecommended: properly locked versions
prevents version drift and ensures consistent dependency performance
UV_THREADPOOL_SIZErecommended: 8
Increase from default 4 for heavy I/O on multi-core systems
wsEnginerecommended: uWebSockets
Use C++-based uWebSockets engine instead of default Socket.IO engine
perMessageDeflaterecommended: true
Enable per-message compression to reduce bandwidth
--max-semi-space-sizerecommended: larger than 4MB default
Increase to reduce GC frequency and use available RAM
tcp_nodelayrecommended: true
Disable Nagle's algorithm to prevent packet batching in real-time apps
Error Signatures (3)
Transaction already closed: A query cannot be executed on an expired transactionexception
Invalid `prisma.taskAttempt.create()` invocation: Transaction API errorexception
fs.readFileSynclog pattern
CLI Commands (24)
ssh -L 9221:localhost:9229 user@hostdiagnostic
node --trace-sync-io app.jsdiagnostic
npx clinic doctor -- node app.jsdiagnostic
npm install -g 0xdiagnostic
0x app.jsdiagnostic
node --inspect your_app.jsdiagnostic
clinic doctor -- node your_app.jsdiagnostic
npm install event-loop-lagmonitoring
function processInChunks(data, chunkSize = 1000) { let index = 0; function nextChunk() { const end = Math.min(index + chunkSize, data.length); for (; index < end; index++) { processData(data[index]); } if (index < data.length) { setImmediate(nextChunk); } } nextChunk(); }remediation
const { Worker } = require('worker_threads'); function runWorker() { return new Promise((resolve, reject) => { const worker = new Worker('./heavy-task.js'); worker.on('message', resolve); worker.on('error', reject); worker.on('exit', code => { if (code !== 0) reject(new Error(`Worker stopped with exit code ${code}`)); }); }); }remediation
const fs = require('fs'); const readStream = fs.createReadStream('large-file.txt'); readStream.on('data', chunk => { console.log(`Received ${chunk.length} bytes`); });remediation
npm lsdiagnostic
npm auditdiagnostic
npm deduperemediation
clinic doctor -- node your-app.jsdiagnostic
const { monitorEventLoopDelay } = require('perf_hooks'); const h = monitorEventLoopDelay(); h.enable(); setInterval(() => { console.log(`Event Loop Lag: ${Math.round(h.mean / 1e6)} ms`); }, 1000);monitoring
node --inspect your-app.jsdiagnostic
clinic.jsdiagnostic
0xdiagnostic
clinic doctor - node main.jsdiagnostic
clinic flame — node main.jsdiagnostic
node --trace-event-categories v8,node,node.async_hooks,node.perfdiagnostic
clinic doctordiagnostic
--trace-gcmonitoring
Technical References (67)
PinocomponentWinstoncomponentPM2componentfs.readFileSynccomponentevent loopconceptcrypto.pbkdf2SynccomponentPrismacomponentO(n^2) complexityconceptBig O notationconceptZodcomponentBuffer.byteLengthcomponentstream-jsoncomponentContent-Lengthprotocolnode:async_hookscomponentOpenTelemetrycomponentprocess.hrtimecomponentV8 profilercomponentprocess.hrtime.bigint()componentWorker ThreadscomponentsetImmediateconceptworker_threadscomponentfs.readFilecomponentasync/awaitconceptN+1 queriesconceptconnection poolingconceptcluster modulecomponentsetTimeoutcomponentWorkercomponentstreamcomponentfs.createReadStreamcomponentbackpressureconceptdebounceconceptthrottleconceptWebSocketsprotocolmoment.jscomponentdate-fnscomponentdayjscomponentfast-json-stringifycomponentclinic.jscomponentclinic doctorcomponentperf_hookscomponentmonitorEventLoopDelaycomponent--inspectcomponentChrome DevToolscomponentheap snapshotsconceptcallback queuecomponentJavaScript threadcomponentCPU profilercomponentreplicacomponentsingle-threadedconceptdistributed tracingcomponentSSRconceptChild Processescomponentfs.readFileSync()componentgarbage collectionconceptfs.promisescomponentPromise.allcomponentp-limitcomponentprom-clientcomponentClinic.jscomponentsetImmediate()componentSocket.IO cluster adaptercomponentWebRTC data channelsprotocolPeerJScomponentSocket.IOcomponentuWebSocketscomponentNagle's algorithmprotocol
Related Insights (48)
Synchronous logging blocks event loop in productionwarning
Live debugging with Inspector pauses event loop and halts trafficcritical
Event loop lag exceeds 10-20ms thresholdwarning
Synchronous file system calls block event loopwarning
Synchronous operations block event loop and tank throughputcritical
Legacy Node.js versions reduce event loop efficiencywarning
Prisma transaction timeouts due to event loop blockingcritical
Nested loop over large datasets blocks event loopcritical
Large unpaginated datasets cause resource exhaustioncritical
Synchronous JSON parsing causes event loop lagwarning
Monitor event loop blocking with async_hooksinfo
High event loop lag degrades API responsivenesswarning
Synchronous CPU-bound operations block event loopcritical
Synchronous file I/O blocks event loop in productioncritical
Poorly optimized database queries delay callback executionwarning
100% CPU utilization prevents event loop processingcritical
Synchronous loops block event loop causing application unresponsivenesscritical
CPU-intensive tasks starve event loop requiring worker threadswarning
Large file processing causes memory exhaustion and event loop lagwarning
Request floods from APIs or WebSockets overload serverwarning
Heavy third-party dependencies bloat application and degrade performancewarning
Event loop lag detection requires monitoring toolinginfo
Memory leaks indirectly cause event loop lagwarning
Event loop blocking causes request latency spikes under concurrent loadcritical
Event loop 100% utilization causes request latency spikes and timeoutscritical
Synchronous CPU-intensive operations block event loop and cause latencycritical
Horizontal scaling mitigates event loop starvation when under-provisionedwarning
Event loop blocking misdiagnosed as downstream service latencywarning
Response timer includes event loop wait time in observed latencyinfo
Callback queue flooding from high request volume causes event loop starvationwarning
Synchronous middleware operations block event loop causing throughput degradationwarning
CPU-intensive tasks block event loop causing request delayscritical
Synchronous file system calls stall event loopcritical
Memory leaks cause garbage collection pauses and event loop latencywarning
Event loop lag indicates delayed task executionwarning
Poorly written dependencies introduce blocking operationswarning
Event loop congestion causes severe response time degradation at scalecritical
Synchronous file I/O blocks event loopwarning
Unbatched concurrent promises cause event loop delayswarning
CPU-intensive operations block event loop for secondscritical
Event loop blocking causes health check failures and pod restartscritical
Event loop lag over 300ms causes API response time degradationcritical
Single-threaded Node.js process saturates one core despite multi-core availabilitycritical
High-frequency real-time broadcasts flood event loop with micro-taskswarning
Socket.IO abstraction overhead reduces throughput under high loadwarning
Small default semi-space heap size causes frequent GC pauseswarning
Nagle's algorithm batches TCP packets causing latency spikeswarning
Node.js struggles to use more than 50% of single CPU before event loop laginfo