























@@ -112,6 +112,7 @@ let diagnosticLivenessMonitor: EventLoopDelayMonitor | null = null;
112112let lastDiagnosticLivenessWallAt = 0;
113113let lastDiagnosticLivenessCpuUsage: CpuUsage | null = null;
114114let lastDiagnosticLivenessEventLoopUtilization: EventLoopUtilization | null = null;
115+let lastDiagnosticLivenessEventAt = 0;
115116let lastDiagnosticLivenessWarnAt = 0;
116117117118function loadCommandPollBackoffRuntime() {
@@ -179,6 +180,7 @@ function startDiagnosticLivenessSampler(): void {
179180lastDiagnosticLivenessWallAt = Date.now();
180181lastDiagnosticLivenessCpuUsage = process.cpuUsage();
181182lastDiagnosticLivenessEventLoopUtilization = performance.eventLoopUtilization();
183+lastDiagnosticLivenessEventAt = 0;
182184lastDiagnosticLivenessWarnAt = 0;
183185184186if (diagnosticLivenessMonitor) {
@@ -202,6 +204,7 @@ function stopDiagnosticLivenessSampler(): void {
202204lastDiagnosticLivenessWallAt = 0;
203205lastDiagnosticLivenessCpuUsage = null;
204206lastDiagnosticLivenessEventLoopUtilization = null;
207+lastDiagnosticLivenessEventAt = 0;
205208lastDiagnosticLivenessWarnAt = 0;
206209}
207210@@ -266,7 +269,21 @@ function sampleDiagnosticLiveness(now: number): DiagnosticLivenessSample | null
266269};
267270}
268271269-function shouldEmitDiagnosticLivenessWarning(now: number): boolean {
272+function shouldEmitDiagnosticLivenessEvent(now: number): boolean {
273+if (
274+lastDiagnosticLivenessEventAt > 0 &&
275+now - lastDiagnosticLivenessEventAt < DEFAULT_LIVENESS_WARN_COOLDOWN_MS
276+) {
277+return false;
278+}
279+lastDiagnosticLivenessEventAt = now;
280+return true;
281+}
282+283+function shouldEmitDiagnosticLivenessWarning(now: number, work: DiagnosticWorkSnapshot): boolean {
284+if (!hasOpenDiagnosticWork(work)) {
285+return false;
286+}
270287if (
271288lastDiagnosticLivenessWarnAt > 0 &&
272289now - lastDiagnosticLivenessWarnAt < DEFAULT_LIVENESS_WARN_COOLDOWN_MS
@@ -281,19 +298,22 @@ function emitDiagnosticLivenessWarning(
281298sample: DiagnosticLivenessSample,
282299work: DiagnosticWorkSnapshot,
283300): void {
284-diag.warn(
285-`liveness warning: reasons=${sample.reasons.join(",")} interval=${Math.round(
286- sample.intervalMs / 1000,
287- )}s eventLoopDelayP99Ms=${formatOptionalDiagnosticMetric(
288- sample.eventLoopDelayP99Ms,
289- )} eventLoopDelayMaxMs=${formatOptionalDiagnosticMetric(
290- sample.eventLoopDelayMaxMs,
291- )} eventLoopUtilization=${formatOptionalDiagnosticMetric(
292- sample.eventLoopUtilization,
293- )} cpuCoreRatio=${formatOptionalDiagnosticMetric(sample.cpuCoreRatio)} active=${
294- work.activeCount
295- } waiting=${work.waitingCount} queued=${work.queuedCount}`,
296-);
301+const message = `liveness warning: reasons=${sample.reasons.join(",")} interval=${Math.round(
302+ sample.intervalMs / 1000,
303+ )}s eventLoopDelayP99Ms=${formatOptionalDiagnosticMetric(
304+ sample.eventLoopDelayP99Ms,
305+ )} eventLoopDelayMaxMs=${formatOptionalDiagnosticMetric(
306+ sample.eventLoopDelayMaxMs,
307+ )} eventLoopUtilization=${formatOptionalDiagnosticMetric(
308+ sample.eventLoopUtilization,
309+ )} cpuCoreRatio=${formatOptionalDiagnosticMetric(sample.cpuCoreRatio)} active=${
310+ work.activeCount
311+ } waiting=${work.waitingCount} queued=${work.queuedCount}`;
312+if (hasOpenDiagnosticWork(work)) {
313+diag.warn(message);
314+} else {
315+diag.debug(message);
316+}
297317emitDiagnosticEvent({
298318type: "diagnostic.liveness.warning",
299319reasons: sample.reasons,
@@ -735,10 +755,13 @@ export function startDiagnosticHeartbeat(
735755pruneDiagnosticSessionStates(now, true);
736756const work = getDiagnosticWorkSnapshot();
737757const livenessSample = (opts?.sampleLiveness ?? sampleDiagnosticLiveness)(now, work);
758+const shouldEmitLivenessEvent =
759+livenessSample !== null && shouldEmitDiagnosticLivenessEvent(now);
738760const shouldEmitLivenessWarning =
739-livenessSample !== null && shouldEmitDiagnosticLivenessWarning(now);
761+livenessSample !== null && shouldEmitDiagnosticLivenessWarning(now, work);
762+const shouldEmitLivenessReport = shouldEmitLivenessEvent || shouldEmitLivenessWarning;
740763const shouldRecordMemorySample =
741-shouldEmitLivenessWarning || hasRecentDiagnosticActivity(now) || hasOpenDiagnosticWork(work);
764+shouldEmitLivenessReport || hasRecentDiagnosticActivity(now) || hasOpenDiagnosticWork(work);
742765(opts?.emitMemorySample ?? emitDiagnosticMemorySample)({
743766emitSample: shouldRecordMemorySample,
744767});
@@ -747,7 +770,7 @@ export function startDiagnosticHeartbeat(
747770return;
748771}
749772750-if (shouldEmitLivenessWarning && livenessSample) {
773+if (shouldEmitLivenessReport && livenessSample) {
751774emitDiagnosticLivenessWarning(livenessSample, work);
752775}
753776此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。