|
1 | 1 | #!/usr/bin/env node
|
| 2 | + |
| 3 | +// Note: getting replicable results from this script requires: |
| 4 | +// (1) Running with the `--expose-gc` flag, |
| 5 | +// (2) adding `global.gc()` within the `index.js` file |
| 6 | +// to force garbage collection within each worker after each iteration. |
| 7 | + |
2 | 8 | const path = require('path');
|
3 | 9 | const { createWorker, createScheduler } = require('../../src');
|
4 | 10 |
|
@@ -43,19 +49,25 @@ const workerGen = async () => {
|
43 | 49 | const time1 = Date.now();
|
44 | 50 | const promises = [];
|
45 | 51 | for (let j = 0; j < 10; j++) {
|
46 |
| - promises.push(scheduler.addJob('recognize', file)); |
| 52 | + // Results are purposefully not saved as this would increase memory usage over time. |
| 53 | + promises.push(scheduler.addJob('recognize', file).then(() => (true))); |
47 | 54 | }
|
48 | 55 | // eslint-disable-next-line no-await-in-loop
|
49 | 56 | await Promise.all(promises);
|
50 | 57 |
|
51 |
| - if (global.gc) global.gc(); |
52 |
| - |
53 | 58 | const time2 = Date.now();
|
54 | 59 | const timeDif = (time2 - time1) / 1e3;
|
55 | 60 | iterationTime += timeDif;
|
56 | 61 | }
|
| 62 | + |
| 63 | + if (global.gc) global.gc(); |
| 64 | + |
57 | 65 | // Print memory stats and time after each iteration
|
58 | 66 | console.log(getMemoryRow(i + 1, process.memoryUsage(), iterationTime));
|
59 | 67 | }
|
| 68 | + |
| 69 | + if (global.gc) global.gc(); |
| 70 | + // require('v8').writeHeapSnapshot(); |
| 71 | + |
60 | 72 | scheduler.terminate();
|
61 | 73 | })();
|
0 commit comments