mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +00:00
perf(analysis): measure tpm over trailing 5s window (#948)
* perf(analysis): measure tpm over trailing 5s instead of full minute Mirror the cover cpm change: a 60s rolling average added too much inertia and flattened real bursts/stalls. Count completions in the trailing 5s window and extrapolate to per-minute, so analysis tpm reacts promptly and decays to 0 within the window when idle. Retention stays at 60s. * docs(changelog): note trailing-window throughput rate (PR #948)
This commit is contained in:
@@ -14,31 +14,36 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe('analysisPerfStore', () => {
|
||||
it('records last track timings and rolling tpm', () => {
|
||||
const record = (trackId: string): void =>
|
||||
recordAnalysisTrackPerf({ trackId, fetchMs: 1, seedMs: 1, bpmMs: 1, totalMs: 3 });
|
||||
|
||||
it('records last track timings and trailing-window tpm', () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(1_000_000);
|
||||
recordAnalysisTrackPerf({
|
||||
trackId: 't1',
|
||||
fetchMs: 1000,
|
||||
seedMs: 2000,
|
||||
bpmMs: 500,
|
||||
totalMs: 3500,
|
||||
});
|
||||
record('t1');
|
||||
vi.advanceTimersByTime(100);
|
||||
expect(getAnalysisTracksPerMinute()).toBeGreaterThan(0);
|
||||
// 1 completion in the trailing 5s → 1 / 5s × 60 = 12 tpm.
|
||||
expect(getAnalysisTracksPerMinute()).toBeCloseTo(12, 0);
|
||||
});
|
||||
|
||||
it('prunes completions older than one minute from tpm window', () => {
|
||||
it('extrapolates a burst over the trailing 5s window', () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(2_000_000);
|
||||
recordAnalysisTrackPerf({
|
||||
trackId: 'old',
|
||||
fetchMs: 1,
|
||||
seedMs: 1,
|
||||
bpmMs: 1,
|
||||
totalMs: 3,
|
||||
});
|
||||
vi.advanceTimersByTime(61_000);
|
||||
record('a');
|
||||
vi.advanceTimersByTime(1_000);
|
||||
record('b');
|
||||
vi.advanceTimersByTime(1_000);
|
||||
record('c');
|
||||
// 3 completions within the last 5s → 3 / 5s × 60 = 36 tpm.
|
||||
expect(getAnalysisTracksPerMinute()).toBeCloseTo(36, 0);
|
||||
});
|
||||
|
||||
it('decays to 0 once completions fall outside the trailing window', () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(3_000_000);
|
||||
record('old');
|
||||
expect(getAnalysisTracksPerMinute()).toBeGreaterThan(0);
|
||||
vi.advanceTimersByTime(6_000);
|
||||
expect(getAnalysisTracksPerMinute()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user