Skip to content

Commit a11c792

Browse files
committed
stats优化
1 parent 624e485 commit a11c792

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/hub.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const cluster = require('cluster');
12
const redis = require('./broker/redis');
23
const { getProtoBuf } = require("./utils/protoBuf");
34
const { randomNum, timeout} = require("./utils/tool");
@@ -293,23 +294,25 @@ class Hub {
293294

294295
async _handlePeerNotFound(client, toPeerId, peerId) {
295296
// this.logger.info(`_handlePeerNotFound ${client} ${toPeerId} ${peerId}`);
296-
this.stats.notFoundCount ++;
297297
const msg = {
298298
action: 'signal',
299299
from_peer_id: toPeerId,
300300
}
301301
if (client) {
302302
if (toPeerId === client.notFoundIdCache) return
303303
client.notFoundIdCache = toPeerId;
304+
this.stats.notFoundCount ++;
304305
return this.sendJsonToClient(client, msg);
305306
}
306307
// polling to another worker
307-
if (redis.getIsAlive()) {
308+
if (!cluster.isPrimary && redis.getIsAlive()) {
308309
const { node } = await this._getRemotePeerInfo(peerId);
309310
if (node) {
310311
// this.logger.info(`polling to another worker, send peer not found`);
311312
if (!node.sendMsgSignal(msg, peerId)) {
312313
// this.logger.warn(`sendMsgSignal to remote ${addr} failed`);
314+
} else {
315+
this.stats.notFoundCount ++;
313316
}
314317
}
315318
}

0 commit comments

Comments
 (0)