fleetmap-reports 1.0.752 → 1.0.754
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/package.json +1 -1
- package/src/util/parallel.js +7 -1
- package/src/util/worker.js +1 -1
package/package.json
CHANGED
package/src/util/parallel.js
CHANGED
|
@@ -6,9 +6,11 @@ exports.parallel = (report, method, toSlice, ...args) => {
|
|
|
6
6
|
const numCPUs = require('os').cpus().length
|
|
7
7
|
return new Promise((resolve, reject) => {
|
|
8
8
|
if (cluster.isPrimary) {
|
|
9
|
-
console.log('
|
|
9
|
+
console.log('parallel with', numCPUs, 'cpus', 'toSlice len', toSlice.length)
|
|
10
10
|
cluster.setupPrimary({ exec: path.resolve(__dirname, 'worker.js') })
|
|
11
11
|
const sliced = toSlice.length > (numCPUs - 1) ? sliceArray(toSlice, toSlice.length / (numCPUs - 1)) : [toSlice]
|
|
12
|
+
console.log('sliced in', sliced.length)
|
|
13
|
+
console.log()
|
|
12
14
|
const _result = []
|
|
13
15
|
let done = 0
|
|
14
16
|
let workerCount = 0
|
|
@@ -17,6 +19,10 @@ exports.parallel = (report, method, toSlice, ...args) => {
|
|
|
17
19
|
reject(new Error('0 to process'))
|
|
18
20
|
}
|
|
19
21
|
sliced.forEach((slice) => {
|
|
22
|
+
if (!slice.length) {
|
|
23
|
+
console.error(report, method, 'got empty slice', slice)
|
|
24
|
+
reject(new Error('got empty slice'))
|
|
25
|
+
}
|
|
20
26
|
try {
|
|
21
27
|
console.log('forking worker', workerCount++, report, method, slice)
|
|
22
28
|
const worker = cluster.fork()
|
package/src/util/worker.js
CHANGED
|
@@ -2,7 +2,7 @@ const path = require('path')
|
|
|
2
2
|
console.log(`worker ${process.pid} is running`, process.cwd())
|
|
3
3
|
process.on('message', async (message) => {
|
|
4
4
|
const { report, method, args } = message
|
|
5
|
-
console.log(`worker ${process.pid} is running`, process.cwd(), report, method
|
|
5
|
+
console.log(`worker ${process.pid} is running`, process.cwd(), report, method)
|
|
6
6
|
const _report = require(path.resolve(__dirname, `../${report}`))
|
|
7
7
|
process.send({ result: await _report[method](...args) })
|
|
8
8
|
})
|