fixes for perf.

This commit is contained in:
Christopher Jeffrey 2016-05-25 18:20:55 -07:00
parent e2817436de
commit 1ef834ca3e
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 35 additions and 15 deletions

View File

@ -365,6 +365,12 @@ Peer.prototype.sendInv = function sendInv(items) {
inv.push(item);
}
if (inv.length === 0)
return;
bcoin.debug('Serving %d inv items to %s.',
inv.length, this.hostname);
for (i = 0; i < inv.length; i += 50000) {
chunk = inv.slice(i, i + 50000);
this.write(this.framer.inv(chunk));
@ -392,6 +398,12 @@ Peer.prototype.sendHeaders = function sendHeaders(items) {
headers.push(item);
}
if (headers.length === 0)
return;
bcoin.debug('Serving %d headers to %s.',
headers.length, this.hostname);
for (i = 0; i < headers.length; i += 2000) {
chunk = headers.slice(i, i + 2000);
this.write(this.framer.headers(chunk));
@ -850,6 +862,9 @@ Peer.prototype._handleGetUTXOs = function _handleGetUTXOs(payload) {
unlock();
}
if (!this.pool.synced)
return done();
if (this.pool.options.selfish)
return done();
@ -950,6 +965,9 @@ Peer.prototype._handleGetHeaders = function _handleGetHeaders(payload) {
unlock();
}
if (!this.pool.synced)
return done();
if (this.pool.options.selfish)
return done();
@ -1024,6 +1042,9 @@ Peer.prototype._handleGetBlocks = function _handleGetBlocks(payload) {
unlock();
}
if (!this.pool.synced)
return done();
if (this.pool.options.selfish)
return done();
@ -1150,6 +1171,9 @@ Peer.prototype._handleMempool = function _handleMempool() {
if (!this.mempool)
return done();
if (!this.pool.synced)
return done();
if (this.pool.options.selfish)
return done();
@ -1368,8 +1392,7 @@ Peer.prototype._handleGetData = function _handleGetData(items) {
Peer.prototype._handleAddr = function _handleAddr(addrs) {
var hosts = [];
var now = utils.now();
var i, addr, ts;
var i, addr;
for (i = 0; i < addrs.length; i++) {
addr = new NetworkAddress(addrs[i]);
@ -1454,7 +1477,7 @@ Peer.prototype._handleGetAddr = function _handleGetAddr() {
items.length,
this.hostname);
return this.write(this.framer.addr(items));
this.write(this.framer.addr(items));
};
Peer.prototype._handleInv = function _handleInv(items) {
@ -1462,8 +1485,6 @@ Peer.prototype._handleInv = function _handleInv(items) {
var txs = [];
var i, item, unknown;
this.fire('inv', items);
for (i = 0; i < items.length; i++) {
item = items[i];
if (item.type === constants.inv.TX) {
@ -1477,6 +1498,8 @@ Peer.prototype._handleInv = function _handleInv(items) {
this.invFilter.add(item.hash, 'hex');
}
this.fire('inv', items);
if (blocks.length > 0)
this.emit('blocks', blocks);
@ -1539,7 +1562,7 @@ Peer.prototype.getHeaders = function getHeaders(locator, stop) {
'Requesting headers packet from peer with getheaders (%s).',
this.hostname);
bcoin.debug('Height: %s, Hash: %s, Stop: %s',
bcoin.debug('Height: %d, Hash: %s, Stop: %s',
locator && locator.length ? this.chain._getCachedHeight(locator[0]) : -1,
locator && locator.length ? utils.revHex(locator[0]) : 0,
stop ? utils.revHex(stop) : 0);
@ -1558,8 +1581,8 @@ Peer.prototype.getBlocks = function getBlocks(locator, stop) {
'Requesting inv packet from peer with getblocks (%s).',
this.hostname);
bcoin.debug('Height: %s, Hash: %s, Stop: %s',
locator && locator.length ? this.chain._getCachedHeight(locator[0]) : null,
bcoin.debug('Height: %d, Hash: %s, Stop: %s',
locator && locator.length ? this.chain._getCachedHeight(locator[0]) : -1,
locator && locator.length ? utils.revHex(locator[0]) : 0,
stop ? utils.revHex(stop) : 0);

View File

@ -52,9 +52,7 @@ Profile.prototype.stopProfiling = function stopProfiling() {
if (!v8profiler)
return;
assert(this.profile);
return this.profile.stopProfiling();
this.profile = v8profiler.stopProfiling(this.name);
};
/**
@ -65,9 +63,7 @@ Profile.prototype.del = function del() {
if (!v8profiler)
return;
assert(this.profile);
return this.profile['delete']();
this.profile['delete']();
};
/**
@ -83,7 +79,8 @@ Profile.prototype.save = function save(callback) {
if (!v8profiler)
return callback();
assert(this.profile);
if (!this.profile)
this.stopProfiling();
bcoin.debug('Saving CPU profile: %s', this.name);