Skip to content

Commit

Permalink
performance increase; txcount setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Williams committed Sep 26, 2014
1 parent 11594db commit b3e2213
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 82 deletions.
97 changes: 16 additions & 81 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,70 +75,6 @@ function find_richlist(coin, cb) {
});
}

/*function update_richlist(coin, hash, received, sent, cb){
find_richlist(coin, function(richlist){
f_richlist(richlist.balance, hash, received - sent, function(rl_balance){
f_richlist(richlist.received, hash, received, function(rl_received){
Richlist.update({coin: settings.coin}, {
received : sort_richlist(rl_received),
balance: sort_richlist(rl_balance),
}, function() {
return cb();
});
});
});
});
}*/

/*function f_richlist(list, address, total, cb) {
//console.log(address);
is_unique(list, address, function(unique, index){
if (unique == false) {
list.splice(index, 1);
process_richlist(list, address, total, function(list) {
return cb(list);
});
} else {
process_richlist(list, address, total, function(list) {
return cb(list);
});
}
});
}*/

/*function process_richlist(list, address, total, cb) {
if (list.length > 0) {
if (total >= list[list.length-1].total) {
list.push({addresses: address, total: total});
return cb(list);
} else if (list.length < 100){
list.push({addresses: address, total: total});
return cb(list);
} else {
return cb(list);
}
} else {
list.push({addresses: address, total: total});
return cb(list);
}
}*/

/*function sort_richlist(list){
list.sort(function(a, b) {
return b.total - a.total;
});
if (list.length > 100) {
return list.slice(0,100);
} else {
return list;
}
}*/





function update_address(hash, txid, amount, type, cb) {
find_address(hash, function(address) {
//console.log(address);
Expand Down Expand Up @@ -171,25 +107,24 @@ function update_address(hash, txid, amount, type, cb) {
is_unique(tx_array, txid, function(unique, index) {
if (unique == true) {
tx_array.push(txid);
if (type == 'vin') {
sent = sent + amount;
} else {
received = received + amount;
}
//update_richlist(settings.coin, hash, received, sent, function() {
Address.update({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
balance: received - sent,
}, function() {
//console.log('address updated: %s', hash);
return cb();
});
//});
if ( tx_array.length > settings.txcount ) {
tx_array.shift();
}
}
if (type == 'vin') {
sent = sent + amount;
} else {
received = received + amount;
}
Address.update({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
balance: received - sent,
}, function() {
//console.log('address updated: %s', hash);
return cb();
}
});
});
} else {
var received = amount;
Expand Down
1 change: 1 addition & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ exports.genesis_tx = "65f705d2f385dc85763a317b3ec000063003d6b039546af5d8195a5ec2
exports.genesis_block = "b2926a56ca64e0cd2430347e383f63ad7092f406088b9b86d6d68c2a34baef51",

exports.heavy = false,
exports.txcount = 100,
exports.reloadSettings = function reloadSettings() {
// Discover where the settings file lives
var settingsFilename = "settings.json";
Expand Down
49 changes: 49 additions & 0 deletions scripts/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require('nodetime').profile({
accountKey: '823170bf6bf4c8e481c99238999316eec066dce9',
appName: 'IQUIDUS-BENCHMARK'
});

var mongoose = require('mongoose')
, db = require('../lib/database')
, Tx = require('../models/tx')
, Address = require('../models/address')
, settings = require('../lib/settings');


var COUNT = 5000; //number of blocks to index

function exit() {
mongoose.disconnect();
process.exit(0);
}

var dbString = "mongodb://" + settings.dbsettings.address;
dbString = dbString + ":" + settings.dbsettings.port;
dbString = dbString + "/IQUIDUS-BENCHMARK";

mongoose.connect(dbString, function(err) {
if (err) {
console.log('Unable to connect to database: %s', dbString);
console.log('Aborting');
exit();
}
Tx.remove({}, function(err) {
Address.remove({}, function(err2) {
var s_timer = new Date().getTime();
db.update_tx_db(settings.coin, 1, COUNT, settings.update_timeout, function(){
var e_timer = new Date().getTime();
Tx.count({}, function(txerr, txcount){
Address.count({}, function(aerr, acount){
var stats = {
tx_count: txcount,
address_count: acount,
seconds: (e_timer - s_timer)/1000,
};
console.log(stats);
exit();
});
});
});
});
});
});
5 changes: 5 additions & 0 deletions scripts/sync.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
require('nodetime').profile({
accountKey: '823170bf6bf4c8e481c99238999316eec066dce9',
appName: 'Iquidus Explorer'
});

var mongoose = require('mongoose')
, db = require('../lib/database')
, Tx = require('../models/tx')
Expand Down
4 changes: 3 additions & 1 deletion settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
"genesis_block": "b2926a56ca64e0cd2430347e383f63ad7092f406088b9b86d6d68c2a34baef51"

//heavy (enable/disable additional heavy features)
"heavy": false
"heavy": false,

//amount of txs to index per address (stores latest n txs)
"txcount": 100

}

0 comments on commit b3e2213

Please sign in to comment.