Skip to content

Commit d716a9c

Browse files
committed
asd
1 parent 8001bf4 commit d716a9c

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/util/speedometer.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Speedometer {
7676
set_interval(delay_ms) {
7777
delay_ms ||= this.is_primary() ? 1000 : 300;
7878
this.clear_interval();
79-
this.interval = setInterval(() => this.on_interval(), delay_ms);
79+
this.interval = setInterval(() => this._on_interval(), delay_ms);
8080
this.interval.unref();
8181
}
8282

@@ -110,7 +110,7 @@ class Speedometer {
110110
/**
111111
* @param {Bulk} bulk
112112
*/
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 }) {
114114
this.num_bytes += bytes;
115115
this.num_ops += ops;
116116
this.sum_latency += sum_latency;
@@ -123,7 +123,7 @@ class Speedometer {
123123
/**
124124
* @returns {Bulk}
125125
*/
126-
get_bulk() {
126+
_get_bulk() {
127127
const bytes = this.num_bytes;
128128
const ops = this.num_ops;
129129
const sum_latency = this.sum_latency;
@@ -133,9 +133,9 @@ class Speedometer {
133133
return { bytes, ops, sum_latency, min_latency, max_latency, latency_sketch };
134134
}
135135

136-
on_interval(min_delay_ms) {
136+
_on_interval(min_delay_ms) {
137137
if (cluster.isWorker) {
138-
process.send({ op: 'update', bulk: this.get_bulk() });
138+
process.send({ op: 'update', bulk: this._get_bulk() });
139139
this.reset();
140140
} else {
141141
this.report();
@@ -144,11 +144,9 @@ class Speedometer {
144144

145145
async start() {
146146
process.on('SIGINT', signal => this._on_signal(signal));
147+
await this._init_primary(),
147148
await this._start_workers();
148-
await Promise.all([
149-
this._init_primary(),
150-
this._workers_ready(),
151-
]);
149+
await this._workers_ready(),
152150
await this._init_workers();
153151
await this._run_workers();
154152
if (cluster.isPrimary && this.argv) {
@@ -163,9 +161,9 @@ class Speedometer {
163161

164162
async _start_workers() {
165163
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)));
167165
} 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));
169167
cluster.on('exit', (worker, code, signal) => this._on_worker_exit(worker, code, signal));
170168
this.workers = {};
171169
for (let i = 0; i < this.num_workers; ++i) {
@@ -266,7 +264,7 @@ class Speedometer {
266264
* @param {Worker} worker
267265
* @param {Message} msg
268266
*/
269-
on_message_from_worker(worker, msg) {
267+
_on_message_from_worker(worker, msg) {
270268
if (!msg) return;
271269
// console.log(`SPEEDOMETER: on_message_from_worker ${worker.id} pid ${worker.process.pid} msg`, msg);
272270
if (msg.op === 'ready') {
@@ -276,7 +274,7 @@ class Speedometer {
276274
worker[STATE].inited = true;
277275
this._waitqueue.wakeup();
278276
} else if (msg.op === 'update') {
279-
this.update_bulk(msg.bulk);
277+
this._update_bulk(msg.bulk);
280278
} else if (msg.op === 'done') {
281279
worker[STATE].done = true;
282280
this._waitqueue.wakeup();
@@ -288,7 +286,7 @@ class Speedometer {
288286
/**
289287
* @param {Message} msg
290288
*/
291-
on_message_to_worker(msg) {
289+
_on_message_to_worker(msg) {
292290
if (!msg) return;
293291
// console.log('SPEEDOMETER: on_message_to_worker', msg);
294292
if (msg.op === 'init') {

0 commit comments

Comments
 (0)