@naturalcycles/nodejs-lib 15.72.0 → 15.72.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exec2/exec2.js +2 -2
- package/dist/infra/process.util.js +9 -4
- package/dist/stream/transform/worker/transformMultiThreaded.model.d.ts +1 -0
- package/package.json +2 -2
- package/src/exec2/exec2.ts +9 -2
- package/src/infra/process.util.ts +10 -5
- package/src/stream/transform/worker/transformMultiThreaded.model.ts +2 -0
- package/src/stream/transform/worker/workerClassProxy.js +9 -4
package/dist/exec2/exec2.js
CHANGED
|
@@ -129,7 +129,7 @@ class Exec2 {
|
|
|
129
129
|
* log: true
|
|
130
130
|
*/
|
|
131
131
|
async spawnAsync(cmd, opt = {}) {
|
|
132
|
-
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt;
|
|
132
|
+
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors, stdio = 'inherit', } = opt;
|
|
133
133
|
opt.log ??= true; // by default log should be true, as we are printing the output
|
|
134
134
|
opt.logStart ??= opt.log;
|
|
135
135
|
opt.logFinish ??= opt.log;
|
|
@@ -139,7 +139,7 @@ class Exec2 {
|
|
|
139
139
|
const p = spawn(cmd, opt.args || [], {
|
|
140
140
|
shell,
|
|
141
141
|
cwd,
|
|
142
|
-
stdio
|
|
142
|
+
stdio,
|
|
143
143
|
env: {
|
|
144
144
|
...(passProcessEnv ? process.env : {}),
|
|
145
145
|
...(forceColor ? { FORCE_COLOR: '1' } : {}),
|
|
@@ -43,11 +43,12 @@ class ProcessUtil {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
cpuInfo() {
|
|
46
|
-
const
|
|
46
|
+
const cpus = os.cpus();
|
|
47
|
+
const c = cpus[0];
|
|
47
48
|
return {
|
|
48
|
-
count:
|
|
49
|
-
model: c
|
|
50
|
-
speed: c
|
|
49
|
+
count: cpus.length,
|
|
50
|
+
model: c?.model || '',
|
|
51
|
+
speed: c?.speed || 0,
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
async cpuPercent(ms) {
|
|
@@ -61,6 +62,10 @@ class ProcessUtil {
|
|
|
61
62
|
const endTotal = stats2.total;
|
|
62
63
|
const idle = endIdle - startIdle;
|
|
63
64
|
const total = endTotal - startTotal;
|
|
65
|
+
if (!total) {
|
|
66
|
+
resolve(0);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
64
69
|
const perc = idle / total;
|
|
65
70
|
resolve(Math.round((1 - perc) * 100));
|
|
66
71
|
}, ms);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.72.
|
|
4
|
+
"version": "15.72.1",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@types/js-yaml": "^4",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"yargs": "^18"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@naturalcycles/dev-lib": "
|
|
22
|
+
"@naturalcycles/dev-lib": "20.20.0"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./dist/index.js",
|
package/src/exec2/exec2.ts
CHANGED
|
@@ -148,7 +148,14 @@ class Exec2 {
|
|
|
148
148
|
* log: true
|
|
149
149
|
*/
|
|
150
150
|
async spawnAsync(cmd: string, opt: SpawnOptions = {}): Promise<void> {
|
|
151
|
-
const {
|
|
151
|
+
const {
|
|
152
|
+
shell = true,
|
|
153
|
+
cwd,
|
|
154
|
+
env,
|
|
155
|
+
passProcessEnv = true,
|
|
156
|
+
forceColor = hasColors,
|
|
157
|
+
stdio = 'inherit',
|
|
158
|
+
} = opt
|
|
152
159
|
opt.log ??= true // by default log should be true, as we are printing the output
|
|
153
160
|
opt.logStart ??= opt.log
|
|
154
161
|
opt.logFinish ??= opt.log
|
|
@@ -159,7 +166,7 @@ class Exec2 {
|
|
|
159
166
|
const p = spawn(cmd, opt.args || [], {
|
|
160
167
|
shell,
|
|
161
168
|
cwd,
|
|
162
|
-
stdio
|
|
169
|
+
stdio,
|
|
163
170
|
env: {
|
|
164
171
|
...(passProcessEnv ? process.env : {}),
|
|
165
172
|
...(forceColor ? { FORCE_COLOR: '1' } : {}),
|
|
@@ -64,11 +64,12 @@ class ProcessUtil {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
cpuInfo(): { count: number; model: string; speed: number } {
|
|
67
|
-
const
|
|
67
|
+
const cpus = os.cpus()
|
|
68
|
+
const c = cpus[0]
|
|
68
69
|
return {
|
|
69
|
-
count:
|
|
70
|
-
model: c
|
|
71
|
-
speed: c
|
|
70
|
+
count: cpus.length,
|
|
71
|
+
model: c?.model || '',
|
|
72
|
+
speed: c?.speed || 0,
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -85,8 +86,12 @@ class ProcessUtil {
|
|
|
85
86
|
|
|
86
87
|
const idle = endIdle - startIdle
|
|
87
88
|
const total = endTotal - startTotal
|
|
88
|
-
|
|
89
|
+
if (!total) {
|
|
90
|
+
resolve(0)
|
|
91
|
+
return
|
|
92
|
+
}
|
|
89
93
|
|
|
94
|
+
const perc = idle / total
|
|
90
95
|
resolve(Math.round((1 - perc) * 100))
|
|
91
96
|
}, ms)
|
|
92
97
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const started = Date.now()
|
|
2
2
|
import { workerData, parentPort } from 'node:worker_threads'
|
|
3
3
|
import { inspect } from 'node:util'
|
|
4
|
-
const { workerFile, workerIndex, logEvery = 1000, metric = 'worker' } = workerData || {}
|
|
4
|
+
const { workerFile, workerIndex, logEvery = 1000, metric = 'worker', silent } = workerData || {}
|
|
5
5
|
|
|
6
6
|
if (!workerFile) {
|
|
7
7
|
throw new Error('workerData.workerFile is required!')
|
|
@@ -17,7 +17,7 @@ try {
|
|
|
17
17
|
const { WorkerClass } = await import(workerFile)
|
|
18
18
|
const worker = new WorkerClass(workerData)
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
log(`${metric}#${workerIndex} loaded in ${Date.now() - started} ms`)
|
|
21
21
|
|
|
22
22
|
let errors = 0
|
|
23
23
|
let processed = 0
|
|
@@ -52,7 +52,7 @@ parentPort.on('message', async msg => {
|
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
errors++
|
|
55
|
-
|
|
55
|
+
log(`${metric}#${workerIndex} errors: ${errors}`)
|
|
56
56
|
}
|
|
57
57
|
})
|
|
58
58
|
|
|
@@ -64,7 +64,7 @@ const inspectOpt = {
|
|
|
64
64
|
function logStats(final) {
|
|
65
65
|
const { rss, heapUsed, heapTotal, external } = process.memoryUsage()
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
log(
|
|
68
68
|
inspect(
|
|
69
69
|
{
|
|
70
70
|
[`${metric}${workerIndex}`]: processed,
|
|
@@ -83,3 +83,8 @@ function logStats(final) {
|
|
|
83
83
|
function mb(b) {
|
|
84
84
|
return Math.round(b / (1024 * 1024))
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
function log(...args) {
|
|
88
|
+
if (silent) return
|
|
89
|
+
console.log(...args)
|
|
90
|
+
}
|