@naturalcycles/nodejs-lib 12.47.3 → 12.48.2
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/stream/pipeline/pipeline.js +1 -1
- package/dist/stream/transform/transformLogProgress.d.ts +8 -0
- package/dist/stream/transform/transformLogProgress.js +8 -7
- package/package.json +1 -1
- package/src/stream/pipeline/pipeline.ts +1 -1
- package/src/stream/transform/transformLogProgress.ts +19 -6
|
@@ -9,7 +9,7 @@ const util_1 = require("util");
|
|
|
9
9
|
exports._pipeline = (0, util_1.promisify)(stream_1.pipeline);
|
|
10
10
|
// Workaround https://github.com/nodejs/node/issues/40191
|
|
11
11
|
// todo: remove it when fix is released in 16.x and in AppEngine 16.x
|
|
12
|
-
if (process.version
|
|
12
|
+
if (process.version >= 'v16.10') {
|
|
13
13
|
const { pipeline } = require('stream/promises');
|
|
14
14
|
exports._pipeline = ((streams) => pipeline(...streams));
|
|
15
15
|
}
|
|
@@ -75,6 +75,14 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
|
|
|
75
75
|
* chunk is undefined for "final" stats, otherwise is defined.
|
|
76
76
|
*/
|
|
77
77
|
extra?: (chunk: IN | undefined, index: number) => AnyObject;
|
|
78
|
+
/**
|
|
79
|
+
* If specified - will multiply the counter by this number.
|
|
80
|
+
* Useful e.g when using `transformBuffer({ batchSize: 500 })`, so
|
|
81
|
+
* it'll accurately represent the number of processed entries (not batches).
|
|
82
|
+
*
|
|
83
|
+
* Defaults to 1.
|
|
84
|
+
*/
|
|
85
|
+
batchSize?: number;
|
|
78
86
|
}
|
|
79
87
|
/**
|
|
80
88
|
* Pass-through transform that optionally logs progress.
|
|
@@ -15,7 +15,7 @@ const inspectOpt = {
|
|
|
15
15
|
* Pass-through transform that optionally logs progress.
|
|
16
16
|
*/
|
|
17
17
|
function transformLogProgress(opt = {}) {
|
|
18
|
-
const { metric = 'progress', heapTotal: logHeapTotal = false, heapUsed: logHeapUsed = false, rss: logRss = true, peakRSS: logPeakRSS = true, logRPS = true, logEvery = 1000, extra, } = opt;
|
|
18
|
+
const { metric = 'progress', heapTotal: logHeapTotal = false, heapUsed: logHeapUsed = false, rss: logRss = true, peakRSS: logPeakRSS = true, logRPS = true, logEvery = 1000, batchSize = 1, extra, } = opt;
|
|
19
19
|
const logProgress = opt.logProgress !== false && logEvery !== 0; // true by default
|
|
20
20
|
const logEvery10 = logEvery * 10;
|
|
21
21
|
const started = Date.now();
|
|
@@ -46,15 +46,16 @@ function transformLogProgress(opt = {}) {
|
|
|
46
46
|
return;
|
|
47
47
|
const mem = process.memoryUsage();
|
|
48
48
|
const now = Date.now();
|
|
49
|
-
const lastRPS = processedLastSecond / ((now - lastSecondStarted) / 1000) || 0;
|
|
50
|
-
const rpsTotal = Math.round(progress / ((now - started) / 1000)) || 0;
|
|
49
|
+
const lastRPS = (processedLastSecond * batchSize) / ((now - lastSecondStarted) / 1000) || 0;
|
|
50
|
+
const rpsTotal = Math.round((progress * batchSize) / ((now - started) / 1000)) || 0;
|
|
51
51
|
lastSecondStarted = now;
|
|
52
52
|
processedLastSecond = 0;
|
|
53
53
|
const rps10 = Math.round(sma.push(lastRPS));
|
|
54
54
|
if (mem.rss > peakRSS)
|
|
55
55
|
peakRSS = mem.rss;
|
|
56
|
+
const batchedProgress = progress * batchSize;
|
|
56
57
|
console.log((0, util_1.inspect)({
|
|
57
|
-
[final ? `${metric}_final` : metric]:
|
|
58
|
+
[final ? `${metric}_final` : metric]: batchedProgress,
|
|
58
59
|
...(extra ? extra(chunk, progress) : {}),
|
|
59
60
|
...(logHeapUsed ? { heapUsed: (0, js_lib_1._mb)(mem.heapUsed) } : {}),
|
|
60
61
|
...(logHeapTotal ? { heapTotal: (0, js_lib_1._mb)(mem.heapTotal) } : {}),
|
|
@@ -71,14 +72,14 @@ function transformLogProgress(opt = {}) {
|
|
|
71
72
|
: {}),
|
|
72
73
|
}, inspectOpt));
|
|
73
74
|
if (tenx) {
|
|
74
|
-
let perHour = Math.round((
|
|
75
|
+
let perHour = Math.round((batchedProgress * 1000 * 60 * 60) / (now - started)) || 0;
|
|
75
76
|
if (perHour > 900) {
|
|
76
77
|
perHour = Math.round(perHour / 1000) + 'K';
|
|
77
78
|
}
|
|
78
|
-
console.log(`${(0, colors_1.dimGrey)((0, time_lib_1.dayjs)().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} so far to process ${(0, colors_1.yellow)(
|
|
79
|
+
console.log(`${(0, colors_1.dimGrey)((0, time_lib_1.dayjs)().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} so far to process ${(0, colors_1.yellow)(batchedProgress)} rows, ~${(0, colors_1.yellow)(perHour)}/hour`);
|
|
79
80
|
}
|
|
80
81
|
else if (final) {
|
|
81
|
-
console.log(`${(0, colors_1.boldWhite)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} to process ${(0, colors_1.yellow)(
|
|
82
|
+
console.log(`${(0, colors_1.boldWhite)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} to process ${(0, colors_1.yellow)(batchedProgress)} rows with total RPS of ${(0, colors_1.yellow)(rpsTotal)}`);
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ export let _pipeline = promisify(pipeline)
|
|
|
10
10
|
|
|
11
11
|
// Workaround https://github.com/nodejs/node/issues/40191
|
|
12
12
|
// todo: remove it when fix is released in 16.x and in AppEngine 16.x
|
|
13
|
-
if (process.version
|
|
13
|
+
if (process.version >= 'v16.10') {
|
|
14
14
|
const { pipeline } = require('stream/promises')
|
|
15
15
|
_pipeline = ((streams: AnyStream[]) => pipeline(...streams)) as any
|
|
16
16
|
}
|
|
@@ -92,6 +92,15 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
|
|
|
92
92
|
* chunk is undefined for "final" stats, otherwise is defined.
|
|
93
93
|
*/
|
|
94
94
|
extra?: (chunk: IN | undefined, index: number) => AnyObject
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* If specified - will multiply the counter by this number.
|
|
98
|
+
* Useful e.g when using `transformBuffer({ batchSize: 500 })`, so
|
|
99
|
+
* it'll accurately represent the number of processed entries (not batches).
|
|
100
|
+
*
|
|
101
|
+
* Defaults to 1.
|
|
102
|
+
*/
|
|
103
|
+
batchSize?: number
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
const inspectOpt: InspectOptions = {
|
|
@@ -113,6 +122,7 @@ export function transformLogProgress<IN = any>(
|
|
|
113
122
|
peakRSS: logPeakRSS = true,
|
|
114
123
|
logRPS = true,
|
|
115
124
|
logEvery = 1000,
|
|
125
|
+
batchSize = 1,
|
|
116
126
|
extra,
|
|
117
127
|
} = opt
|
|
118
128
|
const logProgress = opt.logProgress !== false && logEvery !== 0 // true by default
|
|
@@ -153,18 +163,20 @@ export function transformLogProgress<IN = any>(
|
|
|
153
163
|
const mem = process.memoryUsage()
|
|
154
164
|
|
|
155
165
|
const now = Date.now()
|
|
156
|
-
const lastRPS = processedLastSecond / ((now - lastSecondStarted) / 1000) || 0
|
|
157
|
-
const rpsTotal = Math.round(progress / ((now - started) / 1000)) || 0
|
|
166
|
+
const lastRPS = (processedLastSecond * batchSize) / ((now - lastSecondStarted) / 1000) || 0
|
|
167
|
+
const rpsTotal = Math.round((progress * batchSize) / ((now - started) / 1000)) || 0
|
|
158
168
|
lastSecondStarted = now
|
|
159
169
|
processedLastSecond = 0
|
|
160
170
|
|
|
161
171
|
const rps10 = Math.round(sma.push(lastRPS))
|
|
162
172
|
if (mem.rss > peakRSS) peakRSS = mem.rss
|
|
163
173
|
|
|
174
|
+
const batchedProgress = progress * batchSize
|
|
175
|
+
|
|
164
176
|
console.log(
|
|
165
177
|
inspect(
|
|
166
178
|
{
|
|
167
|
-
[final ? `${metric}_final` : metric]:
|
|
179
|
+
[final ? `${metric}_final` : metric]: batchedProgress,
|
|
168
180
|
...(extra ? extra(chunk, progress) : {}),
|
|
169
181
|
...(logHeapUsed ? { heapUsed: _mb(mem.heapUsed) } : {}),
|
|
170
182
|
...(logHeapTotal ? { heapTotal: _mb(mem.heapTotal) } : {}),
|
|
@@ -185,7 +197,8 @@ export function transformLogProgress<IN = any>(
|
|
|
185
197
|
)
|
|
186
198
|
|
|
187
199
|
if (tenx) {
|
|
188
|
-
let perHour: number | string =
|
|
200
|
+
let perHour: number | string =
|
|
201
|
+
Math.round((batchedProgress * 1000 * 60 * 60) / (now - started)) || 0
|
|
189
202
|
if (perHour > 900) {
|
|
190
203
|
perHour = Math.round(perHour / 1000) + 'K'
|
|
191
204
|
}
|
|
@@ -193,12 +206,12 @@ export function transformLogProgress<IN = any>(
|
|
|
193
206
|
console.log(
|
|
194
207
|
`${dimGrey(dayjs().toPretty())} ${white(metric)} took ${yellow(
|
|
195
208
|
_since(started),
|
|
196
|
-
)} so far to process ${yellow(
|
|
209
|
+
)} so far to process ${yellow(batchedProgress)} rows, ~${yellow(perHour)}/hour`,
|
|
197
210
|
)
|
|
198
211
|
} else if (final) {
|
|
199
212
|
console.log(
|
|
200
213
|
`${boldWhite(metric)} took ${yellow(_since(started))} to process ${yellow(
|
|
201
|
-
|
|
214
|
+
batchedProgress,
|
|
202
215
|
)} rows with total RPS of ${yellow(rpsTotal)}`,
|
|
203
216
|
)
|
|
204
217
|
}
|