Skip to content

Commit

Permalink
feat: Log (and graph) database disk usage
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Mar 19, 2020
1 parent 5c187f3 commit 9f9f5af
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
8 changes: 7 additions & 1 deletion packages/swing-store-lmdb/lmdbSwingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ function makeSwingStore(dirPath, forceReset = false) {
}
}

function diskUsage() {
const dataFilePath = `${dirPath}/data.mdb`;
const stat = fs.statSync(dataFilePath);
return stat.size;
}

/**
* Obtain the value stored for a given key.
*
Expand Down Expand Up @@ -180,7 +186,7 @@ function makeSwingStore(dirPath, forceReset = false) {
lmdbEnv = null;
}

return { storage, commit, close };
return { storage, commit, close, diskUsage };
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/swingset-runner/bin/graphDisk
16 changes: 16 additions & 0 deletions packages/swingset-runner/src/graphDisk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env -S node -r esm

import { dataGraphApp } from './dataGraphApp';

export async function main() {
// prettier-ignore
await dataGraphApp(
'block',
'Block #',
'disk',
'Database size (bytes)',
['disk'],
);
}

main();
39 changes: 26 additions & 13 deletions packages/swingset-runner/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ Command line:
runner [FLAGS...] CMD [{BASEDIR|--} [ARGS...]]
FLAGS may be:
--no-ses - directs vats not to be run in SES.
--init - discard any existing saved state at startup.
--lmdb - runs using LMDB as the data store
--filedb - runs using the simple file-based data store (default)
--lmdb - runs using LMDB as the data store (default)
--filedb - runs using the simple file-based data store
--memdb - runs using the non-persistent in-memory data store
--blockmode - run in block mode (checkpoint every BLOCKSIZE blocks)
--blocksize N - set BLOCKSIZE to N (default 200)
--logtimes - log block execution time stats while running
--logmem - log memory usage stats after each block
--logdisk - log disk space usage stats after each block
--logall - log block times, memory use, and disk space
--forcegc - run garbage collector after each block
--batchsize N - set BATCHSIZE to N (default 200)
Expand Down Expand Up @@ -73,21 +74,18 @@ function fail(message, printUsage) {
export async function main() {
const argv = process.argv.splice(2);

let withSES = true;
let forceReset = false;
let dbMode = '--filedb';
let dbMode = '--lmdb';
let blockSize = 200;
let batchSize = 200;
let blockMode = false;
let logTimes = false;
let logMem = false;
let logDisk = false;
let forceGC = false;
while (argv[0] && argv[0].startsWith('--')) {
while (argv[0] && argv[0].startsWith('-')) {
const flag = argv.shift();
switch (flag) {
case '--no-ses':
withSES = false;
break;
case '--init':
forceReset = true;
break;
Expand All @@ -97,6 +95,14 @@ export async function main() {
case '--logmem':
logMem = true;
break;
case '--logdisk':
logDisk = true;
break;
case '--logall':
logTimes = true;
logMem = true;
logDisk = true;
break;
case '--forcegc':
forceGC = true;
break;
Expand Down Expand Up @@ -178,18 +184,21 @@ export async function main() {

let blockNumber = 0;
let statLogger = null;
if (logTimes || logMem) {
if (logTimes || logMem || logDisk) {
let headers = ['block', 'steps'];
if (logTimes) {
headers = headers.concat(['btime']);
headers.push('btime');
}
if (logMem) {
headers = headers.concat(['rss', 'heapTotal', 'heapUsed', 'external']);
}
if (logDisk) {
headers.push('disk');
}
statLogger = makeStatLogger('runner', headers);
}

const controller = await buildVatController(config, withSES, bootstrapArgv);
const controller = await buildVatController(config, true, bootstrapArgv);
switch (command) {
case 'run': {
await commandRun(0, blockMode);
Expand Down Expand Up @@ -292,7 +301,7 @@ export async function main() {
blockNumber += 1;
let data = [blockNumber, actualSteps];
if (logTimes) {
data = data.concat([blockEndTime - blockStartTime]);
data.push(blockEndTime - blockStartTime);
}
if (logMem) {
const mem = process.memoryUsage();
Expand All @@ -303,6 +312,10 @@ export async function main() {
mem.external,
]);
}
if (logDisk) {
const diskUsage = dbMode === '--lmdb' ? store.diskUsage() : 0;
data.push(diskUsage);
}
statLogger.log(data);
}
return actualSteps;
Expand Down

0 comments on commit 9f9f5af

Please sign in to comment.