mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-09 17:36:15 -08:00
* docs(performance): plan Xtream benchmark * feat(xtream-mock-server): add deterministic 100k fixture * style(xtream-mock-server): apply repository formatting * fix(xtream-mock-server): harden performance fixture data * feat(xtream-mock-server): add performance control plane * docs(performance): correct Xtream capture plan * fix(xtream-mock-server): harden performance controls * fix(xtream-mock-server): harden control lifecycle * feat(performance): add Xtream preload markers * feat(performance): trace Xtream main phases * feat(performance): mark Xtream store publications * feat(performance): trace Xtream database phases * feat(performance): trace Xtream delete cancellation * feat(performance): capture Xtream phase attribution * feat(performance): mark Sources Xtream refresh * test(performance): define Xtream benchmark evidence contracts * test(performance): add Xtream benchmark runner * test(performance): surface failure evidence writes * test(performance): align database read clock * test(performance): preserve capture failure contracts
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import type { WorkerRequestPerformanceMetrics } from './m3u-refresh-cancellation-contract';
|
|
import { XTREAM_WORKER_REQUEST_INVALID_REASON } from './xtream-summary-contract';
|
|
|
|
export interface XtreamWorkerRequestWindowProxy {
|
|
readonly eventLoopDelayMaxMs: number;
|
|
readonly eventLoopDelayP95Ms: number;
|
|
readonly eventLoopDelayP99Ms: number;
|
|
readonly eventLoopUtilization: number;
|
|
}
|
|
|
|
export function deriveXtreamWorkerRequestWindowProxy(
|
|
evidence: readonly WorkerRequestPerformanceMetrics[]
|
|
): XtreamWorkerRequestWindowProxy | null {
|
|
const valid = evidence.filter(
|
|
({ invalidReason }) =>
|
|
invalidReason !==
|
|
XTREAM_WORKER_REQUEST_INVALID_REASON.OVERLAPPING_DATABASE_REQUESTS
|
|
);
|
|
if (
|
|
valid.length === 0 ||
|
|
valid.some(
|
|
({ eventLoopDelay, eventLoopUtilization, invalidReason }) =>
|
|
invalidReason !== null ||
|
|
!isDelay(eventLoopDelay) ||
|
|
!isUtilization(eventLoopUtilization)
|
|
)
|
|
) {
|
|
return null;
|
|
}
|
|
return {
|
|
eventLoopDelayMaxMs: Math.max(
|
|
...valid.map(({ eventLoopDelay }) => eventLoopDelay?.maxMs ?? 0)
|
|
),
|
|
eventLoopDelayP95Ms: Math.max(
|
|
...valid.map(({ eventLoopDelay }) => eventLoopDelay?.p95Ms ?? 0)
|
|
),
|
|
eventLoopDelayP99Ms: Math.max(
|
|
...valid.map(({ eventLoopDelay }) => eventLoopDelay?.p99Ms ?? 0)
|
|
),
|
|
eventLoopUtilization: Math.max(
|
|
...valid.map(
|
|
({ eventLoopUtilization }) => eventLoopUtilization ?? 0
|
|
)
|
|
),
|
|
};
|
|
}
|
|
|
|
function isDelay(
|
|
value: WorkerRequestPerformanceMetrics['eventLoopDelay']
|
|
): value is NonNullable<WorkerRequestPerformanceMetrics['eventLoopDelay']> {
|
|
return (
|
|
value !== null &&
|
|
[value.p95Ms, value.p99Ms, value.maxMs].every(
|
|
(sample) =>
|
|
typeof sample === 'number' &&
|
|
Number.isFinite(sample) &&
|
|
sample >= 0
|
|
) &&
|
|
value.p95Ms <= value.p99Ms &&
|
|
value.p99Ms <= value.maxMs
|
|
);
|
|
}
|
|
|
|
function isUtilization(value: number | null): value is number {
|
|
return (
|
|
typeof value === 'number' &&
|
|
Number.isFinite(value) &&
|
|
value >= 0 &&
|
|
value <= 1
|
|
);
|
|
}
|