Skip to content

Commit

Permalink
fix: metrics handle missing values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Jan 8, 2024
1 parent a11d9c4 commit b6dd746
Show file tree
Hide file tree
Showing 7 changed files with 14,829 additions and 4 deletions.
67 changes: 67 additions & 0 deletions yarn-project/bench.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { randomBytes } from 'crypto';

const lmdb = await import('lmdb');
const { AztecLmdbStore } = await import('@aztec/kv-store');
const root = lmdb.open('/home/ubuntu/aztec-data/random');
const store = new AztecLmdbStore(root);
const rawDB = root.openDB('raw', {});
const { createHistogram, performance } = await import('perf_hooks');

const array = store.createArray('array');
const map = store.createMap('map');
const collection = store.createCollection('collection', {});

const [arrayHistogram, mapHistogram, collectionHistogram, rawHistogram] = await Promise.all([
benchmark('array', 1000, x => array.push(x)),
benchmark('map', 1000, x => map.set(x, x)),
benchmark('collection', 1000, x => collection.insert(x)),
benchmark('raw', 1000, x => rawDB.put(x, x)),
]);

console.log('Benchmark: array');
console.group();
printHistogram(arrayHistogram);
console.groupEnd();

console.log('Benchmark: map');
console.group();
printHistogram(mapHistogram);
console.groupEnd();

console.log('Benchmark: collection');
console.group();
printHistogram(collectionHistogram);
console.groupEnd();

console.log('Benchmark: raw');
console.group();
printHistogram(rawHistogram);
console.groupEnd();

async function benchmark(name, runs, fn) {
const histogram = createHistogram();
const instrumented = performance.timerify(fn, { histogram });

for (let i = 0; i < runs; i++) {
const x = randomBytes(32);
await instrumented(x);
}

return histogram;
}

function nsToMs(ns) {
return ns / 1e6;
}

function printHistogram(histogram) {
console.log(`\
${nsToMs(histogram.min)}ms min
${nsToMs(histogram.max)}ms max
${nsToMs(histogram.percentile(0.5))}ms median
${nsToMs(histogram.percentile(0.75))}ms 75th percentile
${nsToMs(histogram.percentile(0.9))}ms 90th percentile
${nsToMs(histogram.percentile(0.99))}ms 99th percentile
${nsToMs(histogram.percentile(0.9999))}ms 99.99th percentile\
`);
}
13,386 changes: 13,386 additions & 0 deletions yarn-project/e2e_log.txt

Large diffs are not rendered by default.

1,300 changes: 1,300 additions & 0 deletions yarn-project/out.txt

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions yarn-project/sandbox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export DEBUG=aztec:*
export DATA_DIRECTORY="$HOME/aztec-data"

export ROLLUP_CONTRACT_ADDRESS=0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9
export REGISTRY_CONTRACT_ADDRESS=0x5fbdb2315678afecb367f032d93f642f64180aa3
export INBOX_CONTRACT_ADDRESS=0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
export CONTRACT_DEPLOYMENT_EMITTER_ADDRESS=0x5fc8d32690cc91d4c39d9d3abcbd16989f875707

export TEST_ACCOUNTS=false
export DEPLOY_AZTEC_CONTRACTS=false

export ME=0x06357cc85cb8fc561adbf741f63cd75efa26ffba1c80d431ec77d036d8edf022
export PARTIAL_ADDRESS=0x23475465106cc4ee212154ddad52658014ff02442196c340960abfdee1b5424a
export PRIVATE_KEY=0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281
export PUBLIC_KEY=0x27c20118733174347b8082f578a7d8fb84b3ad38be293715eee8119ee5cd8a6d0d6b7d8124b37359663e75bcd2756f544a93b821a06f8e33fba68cc8029794d9

export CONTRACT=EasyPrivateTokenContractArtifact
export CONTRACT_ADDRESS=0x2b3a0adc1037c457e3a5bb17d3fe2f22814c5771f593fc923941c5577bd13ddc
export CONTRACT_PARTIAL_ADDRESS=0x0c0a534faca34253a694f325ac98f9234dbb6173347e7d09e112754653ef5bc6

yarn workspace @aztec/aztec-sandbox start
exit 0
24 changes: 24 additions & 0 deletions yarn-project/sb.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const lmdb = await import('lmdb');
const { AztecLmdbStore } = await import('@aztec/kv-store');
const { KVPxeDatabase } = await import('./pxe/dest/database/kv_pxe_database.js');
const { AztecAddress, BlockHeader, CompleteAddress } = await import('@aztec/circuits.js');
const { Fr, Point } = await import('@aztec/foundation/fields');
const root = lmdb.open('/home/ubuntu/aztec-data/pxe_data');
const data = root.openDB('data', {});
const noteIndexes = root.openDB('data_dup_sort', {});
const store = new AztecLmdbStore(root);

const addresses = store.createMap('addresses');
const authWitnesses = store.createMap('authWitnesses');
const capsules = store.createArray('capsules');
const blockHeader = store.createSingleton('block_header');
const contracts = store.createMap('contracts');
const notes = store.createArray('notes');
const nullifiedNotes = store.createMap('nullified_notes');

const notesByContract = store.createMultiMap('notes_by_contract');
const notesByStorageSlot = store.createMultiMap('notes_by_storage_slot');
const notesByTxHash = store.createMultiMap('notes_by_tx_hash');
const notesByOwner = store.createMultiMap('notes_by_owner');

const pxeDB = new KVPxeDatabase(store);
15 changes: 11 additions & 4 deletions yarn-project/scripts/src/benchmarks/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ function getCell(
row: string,
col: string,
) {
const value = data[row][col];
const value: number | undefined = data[row][col];
const formattedValue = formatValue(value);
const baseValue = base ? (base[row] ?? {})[col] : undefined;
const percentDiff = baseValue ? Math.round(((value - baseValue) / baseValue) * 100) : undefined;
const baseValue: number | undefined = base?.[row]?.[col];
const percentDiff =
typeof baseValue === 'number' && typeof value === 'number'
? Math.round(((value - baseValue) / baseValue) * 100)
: undefined;
if (!percentDiff || Math.abs(percentDiff) < 1) {
return formattedValue;
}
Expand All @@ -118,7 +121,11 @@ function withDesc(name: string) {
}

/** Formats a numeric value for display. */
function formatValue(value: number) {
function formatValue(value: number | undefined): string {
if (typeof value === 'undefined') {
return 'N/A';
}

if (value < 100) {
return value.toPrecision(3);
}
Expand Down
19 changes: 19 additions & 0 deletions yarn-project/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const lmdb = await import('lmdb');
const root = lmdb.open({});
const map = prefix => ({
set: (k, v) => root.put([prefix, k], v),
get: (k, v) => root.get([prefix, k], v),
});

const foo = map('foo');
const bar = map('bar');

foo.set('a', 'foo: a');
foo.set('b', 'foo: b');
foo.set('e', 'foo: e');
foo.set('c', 'foo: c');

bar.set('a', 'bar: a');
bar.set('b', 'bar: b');
bar.set('e', 'bar: e');
bar.set('c', 'bar: c');

0 comments on commit b6dd746

Please sign in to comment.