@@ -76,7 +76,7 @@ class Speedometer {
76
76
set_interval ( delay_ms ) {
77
77
delay_ms ||= this . is_primary ( ) ? 1000 : 300 ;
78
78
this . clear_interval ( ) ;
79
- this . interval = setInterval ( ( ) => this . on_interval ( ) , delay_ms ) ;
79
+ this . interval = setInterval ( ( ) => this . _on_interval ( ) , delay_ms ) ;
80
80
this . interval . unref ( ) ;
81
81
}
82
82
@@ -110,7 +110,7 @@ class Speedometer {
110
110
/**
111
111
* @param {Bulk } bulk
112
112
*/
113
- update_bulk ( { bytes, ops, sum_latency, min_latency, max_latency, latency_sketch } ) {
113
+ _update_bulk ( { bytes, ops, sum_latency, min_latency, max_latency, latency_sketch } ) {
114
114
this . num_bytes += bytes ;
115
115
this . num_ops += ops ;
116
116
this . sum_latency += sum_latency ;
@@ -123,7 +123,7 @@ class Speedometer {
123
123
/**
124
124
* @returns {Bulk }
125
125
*/
126
- get_bulk ( ) {
126
+ _get_bulk ( ) {
127
127
const bytes = this . num_bytes ;
128
128
const ops = this . num_ops ;
129
129
const sum_latency = this . sum_latency ;
@@ -133,9 +133,9 @@ class Speedometer {
133
133
return { bytes, ops, sum_latency, min_latency, max_latency, latency_sketch } ;
134
134
}
135
135
136
- on_interval ( min_delay_ms ) {
136
+ _on_interval ( min_delay_ms ) {
137
137
if ( cluster . isWorker ) {
138
- process . send ( { op : 'update' , bulk : this . get_bulk ( ) } ) ;
138
+ process . send ( { op : 'update' , bulk : this . _get_bulk ( ) } ) ;
139
139
this . reset ( ) ;
140
140
} else {
141
141
this . report ( ) ;
@@ -144,11 +144,9 @@ class Speedometer {
144
144
145
145
async start ( ) {
146
146
process . on ( 'SIGINT' , signal => this . _on_signal ( signal ) ) ;
147
+ await this . _init_primary ( ) ,
147
148
await this . _start_workers ( ) ;
148
- await Promise . all ( [
149
- this . _init_primary ( ) ,
150
- this . _workers_ready ( ) ,
151
- ] ) ;
149
+ await this . _workers_ready ( ) ,
152
150
await this . _init_workers ( ) ;
153
151
await this . _run_workers ( ) ;
154
152
if ( cluster . isPrimary && this . argv ) {
@@ -163,9 +161,9 @@ class Speedometer {
163
161
164
162
async _start_workers ( ) {
165
163
if ( cluster . isWorker ) {
166
- process . on ( 'message' , msg => this . on_message_to_worker ( /** @type {Message } */ ( msg ) ) ) ;
164
+ process . on ( 'message' , msg => this . _on_message_to_worker ( /** @type {Message } */ ( msg ) ) ) ;
167
165
} else if ( cluster . isPrimary && this . num_workers > 1 ) {
168
- cluster . on ( 'message' , ( worker , msg ) => this . on_message_from_worker ( worker , msg ) ) ;
166
+ cluster . on ( 'message' , ( worker , msg ) => this . _on_message_from_worker ( worker , msg ) ) ;
169
167
cluster . on ( 'exit' , ( worker , code , signal ) => this . _on_worker_exit ( worker , code , signal ) ) ;
170
168
this . workers = { } ;
171
169
for ( let i = 0 ; i < this . num_workers ; ++ i ) {
@@ -266,7 +264,7 @@ class Speedometer {
266
264
* @param {Worker } worker
267
265
* @param {Message } msg
268
266
*/
269
- on_message_from_worker ( worker , msg ) {
267
+ _on_message_from_worker ( worker , msg ) {
270
268
if ( ! msg ) return ;
271
269
// console.log(`SPEEDOMETER: on_message_from_worker ${worker.id} pid ${worker.process.pid} msg`, msg);
272
270
if ( msg . op === 'ready' ) {
@@ -276,7 +274,7 @@ class Speedometer {
276
274
worker [ STATE ] . inited = true ;
277
275
this . _waitqueue . wakeup ( ) ;
278
276
} else if ( msg . op === 'update' ) {
279
- this . update_bulk ( msg . bulk ) ;
277
+ this . _update_bulk ( msg . bulk ) ;
280
278
} else if ( msg . op === 'done' ) {
281
279
worker [ STATE ] . done = true ;
282
280
this . _waitqueue . wakeup ( ) ;
@@ -288,7 +286,7 @@ class Speedometer {
288
286
/**
289
287
* @param {Message } msg
290
288
*/
291
- on_message_to_worker ( msg ) {
289
+ _on_message_to_worker ( msg ) {
292
290
if ( ! msg ) return ;
293
291
// console.log('SPEEDOMETER: on_message_to_worker', msg);
294
292
if ( msg . op === 'init' ) {
0 commit comments