Browse Source

cleanup / reorganize

fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
d5f97699bc
  1. 25
      app.js
  2. 11
      app/utils.js

25
app.js

@ -85,27 +85,6 @@ function refreshExchangeRate() {
}
}
var firstCall = true;
function trackMemoryUsage() {
var mbUsed = process.memoryUsage().heapUsed / 1024 / 1024;
mbUsed = Math.round(mbUsed * 100) / 100;
var mbTotal = process.memoryUsage().heapTotal / 1024 / 1024;
mbTotal = Math.round(mbTotal * 100) / 100;
var stream = fs.createWriteStream("memoryUsage.csv", {flags:'a'});
if (firstCall) {
stream.write("App starting up.\n");
}
stream.write(mbUsed + "\n");
stream.end();
firstCall = false;
}
app.runOnStartup = function() {
@ -198,8 +177,8 @@ app.runOnStartup = function() {
// refresh exchange rate periodically
setInterval(refreshExchangeRate, 1800000);
trackMemoryUsage();
setInterval(trackMemoryUsage, 5000);
utils.logMemoryUsage();
setInterval(utils.logMemoryUsage, 5000);
};
app.use(function(req, res, next) {

11
app/utils.js

@ -150,6 +150,16 @@ function seededRandomIntBetween(seed, min, max) {
return (min + (max - min) * rand);
}
function logMemoryUsage() {
var mbUsed = process.memoryUsage().heapUsed / 1024 / 1024;
mbUsed = Math.round(mbUsed * 100) / 100;
var mbTotal = process.memoryUsage().heapTotal / 1024 / 1024;
mbTotal = Math.round(mbTotal * 100) / 100;
console.log("memoryUsage: heapUsed=" + mbUsed + ", heapTotal=" + mbTotal + ", ratio=" + parseInt(mbUsed / mbTotal * 100));
}
function getMinerFromCoinbaseTx(tx) {
if (tx == null || tx.vin == null || tx.vin.length == 0) {
return null;
@ -208,6 +218,7 @@ module.exports = {
formatCurrencyAmountInSmallestUnits: formatCurrencyAmountInSmallestUnits,
seededRandom: seededRandom,
seededRandomIntBetween: seededRandomIntBetween,
logMemoryUsage: logMemoryUsage,
getMinerFromCoinbaseTx: getMinerFromCoinbaseTx,
getBlockTotalFeesFromCoinbaseTxAndBlockHeight: getBlockTotalFeesFromCoinbaseTxAndBlockHeight
};

Loading…
Cancel
Save