Skip to content

Commit d8978e1

Browse files
committed
refactor: wip
1 parent 9ed836c commit d8978e1

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

packages/utils/mocks/multiprocess-profiling/utils.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function getProfilerConfig(
4444
export async function createBufferedEvents(): Promise<void> {
4545
const bM1 = `buffered-mark-${process.pid}`;
4646
performance.mark(bM1, asOptions(markerPayload({ color: 'tertiary' })));
47-
const intervalDelay = Math.floor(Math.random() * 150) + 50;
47+
const intervalDelay = Math.floor(Math.random() * 50) + 25;
4848
await new Promise(resolve => setTimeout(resolve, intervalDelay));
4949
performance.measure(`buffered-${process.pid}`, {
5050
start: bM1,
@@ -67,20 +67,20 @@ export async function performDummyWork(
6767
tooltipText: `Process ${process.pid} started`,
6868
});
6969

70-
// Random number of intervals (2-5)
71-
const numIntervals = Math.floor(Math.random() * 4) + 2;
70+
// Random number of intervals (1-3) - reduced from 2-5
71+
const numIntervals = Math.floor(Math.random() * 3) + 1;
7272

7373
for (let interval = 0; interval < numIntervals; interval++) {
74-
// Random interval delay (50-200ms)
75-
const intervalDelay = Math.floor(Math.random() * 150) + 50;
74+
// Random interval delay (25-100ms)
75+
const intervalDelay = Math.floor(Math.random() * 75) + 25;
7676
await new Promise(resolve => setTimeout(resolve, intervalDelay));
7777

78-
// Random number of work packages per interval (1-5)
79-
const numWorkPackages = Math.floor(Math.random() * 5) + 1;
78+
// Random number of work packages per interval (1-3)
79+
const numWorkPackages = Math.floor(Math.random() * 3) + 1;
8080

8181
for (let pkg = 0; pkg < numWorkPackages; pkg++) {
82-
// Random work size (100-5000 elements)
83-
const workSize = Math.floor(Math.random() * 5_000_000);
82+
// Random work size (100-2,500,000 elements)
83+
const workSize = Math.floor(Math.random() * 2_500_000);
8484

8585
profiler.measure(
8686
`process-${process.pid}:interval-${interval}:work-${pkg}`,

packages/utils/src/lib/profiler/profiler-node.int.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,15 @@ describe('NodeJS Profiler Integration', () => {
391391

392392
it('should handle sharding across multiple processes', async () => {
393393
const numProcesses = 3;
394+
const startTime = performance.now();
394395

395396
const {
396397
[PROFILER_SHARDER_ID_ENV_VAR]: _coordinatorId,
397398
[PROFILER_MEASURE_NAME_ENV_VAR]: _measureName,
398399
...cleanEnv
399400
} = process.env;
400401

402+
const processStartTime = performance.now();
401403
const { stdout, stderr } = await executeProcess({
402404
command: 'npx',
403405
args: [
@@ -415,6 +417,7 @@ describe('NodeJS Profiler Integration', () => {
415417
[PROFILER_OUT_DIR_ENV_VAR]: testSuitDir,
416418
},
417419
});
420+
const processDuration = performance.now() - processStartTime;
418421

419422
if (!stdout.trim()) {
420423
throw new Error(
@@ -432,6 +435,7 @@ describe('NodeJS Profiler Integration', () => {
432435
);
433436
}
434437

438+
const validationStartTime = performance.now();
435439
expect(coordinatorStats).toStrictEqual(
436440
expect.objectContaining({
437441
isCoordinator: true,
@@ -459,5 +463,12 @@ describe('NodeJS Profiler Integration', () => {
459463
});
460464

461465
expect(processIds.size).toStrictEqual(numProcesses);
466+
const validationDuration = performance.now() - validationStartTime;
467+
const totalDuration = performance.now() - startTime;
468+
469+
// Log timing information for debugging
470+
console.log(
471+
`[Timing] Process execution: ${processDuration.toFixed(2)}ms, Validation: ${validationDuration.toFixed(2)}ms, Total: ${totalDuration.toFixed(2)}ms`,
472+
);
462473
}, 10_000); // Timeout: 10 seconds for multi-process coordination
463474
});

0 commit comments

Comments
 (0)