-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8239 from Agoric/swingset-perf-tool
SwingSet benchmarking tool, phase 1
- Loading branch information
Showing
16 changed files
with
613 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/boot/test/bootstrapTests/bench-vaults-stripped.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// This is a version of bench-vaults-performance.js that has had all intrinsic | ||
// performance measurement code stripped out of it, purely implementing the | ||
// vault benchmark test code in expectation of extrinsic measurement. | ||
|
||
import { test as unknownTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js'; | ||
|
||
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; | ||
import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; | ||
import { makeSwingsetTestKit } from './supports.js'; | ||
import { makeWalletFactoryDriver } from './drivers.js'; | ||
|
||
// presently all these tests use one collateral manager | ||
const collateralBrandKey = 'ATOM'; | ||
|
||
const makeDefaultTestContext = async t => { | ||
const swingsetTestKit = await makeSwingsetTestKit(t); | ||
|
||
const { runUtils, storage: chainStorage } = swingsetTestKit; | ||
const { EV } = runUtils; | ||
|
||
// Wait for ATOM to make it into agoricNames | ||
// E(bootstrap).consumeItem('vaultFactoryKit'); | ||
await EV.vat('bootstrap').consumeItem('vaultFactoryKit'); | ||
|
||
// has to be late enough for agoricNames data to have been published | ||
const agoricNamesRemotes = | ||
makeAgoricNamesRemotesFromFakeStorage(chainStorage); | ||
|
||
const walletFactoryDriver = await makeWalletFactoryDriver( | ||
runUtils, | ||
chainStorage, | ||
agoricNamesRemotes, | ||
); | ||
|
||
return { ...swingsetTestKit, walletFactoryDriver }; | ||
}; | ||
|
||
/** @type {import('ava').TestFn<Awaited<ReturnType<makeDefaultTestContext>>>} */ | ||
const test = unknownTest; | ||
|
||
test.before(async t => { | ||
t.context = await makeDefaultTestContext(t); | ||
}); | ||
test.after.always(t => t.context.shutdown()); | ||
|
||
test.serial('stress vaults', async t => { | ||
const { walletFactoryDriver } = t.context; | ||
await walletFactoryDriver.provideSmartWallet( | ||
'agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce', | ||
); | ||
await walletFactoryDriver.provideSmartWallet( | ||
'agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang', | ||
); | ||
await walletFactoryDriver.provideSmartWallet( | ||
'agoric1w8wktaur4zf8qmmtn3n7x3r0jhsjkjntcm3u6h', | ||
); | ||
|
||
const wd = await walletFactoryDriver.provideSmartWallet('agoric1open'); | ||
|
||
const openVault = async (i, n) => { | ||
const offerId = `open-vault-${i}-of-${n}`; | ||
await wd.executeOfferMaker(Offers.vaults.OpenVault, { | ||
offerId, | ||
collateralBrandKey, | ||
wantMinted: 5, | ||
giveCollateral: 1.0, | ||
}); | ||
|
||
t.like(wd.getLatestUpdateRecord(), { | ||
updated: 'offerStatus', | ||
status: { id: offerId, numWantsSatisfied: 1 }, | ||
}); | ||
}; | ||
|
||
const openN = async n => { | ||
const range = [...Array(n)].map((_, i) => i + 1); | ||
await Promise.all(range.map(i => openVault(i, n))); | ||
}; | ||
|
||
await openN(1); | ||
await eventLoopIteration(); | ||
t.pass(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
packages/swingset-runner/demo/vaultPerfTest/vat-benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// In-swingset implementation of the vault performance benchmark from | ||
// packages/boot/test/bootstrapTests/bench-vaults-performance.js | ||
// | ||
// Run with: | ||
// | ||
// runner --usebundlecache --chain --sbench demo/vaultPerfTest/vat-benchmark.js --benchmark ${ROUNDS} --config ../vm-config/decentral-itest-vaults-config.json run | ||
// | ||
// NOTE: The above incantation assumes running from the root directory of the | ||
// swingset-runner package. If running from elsewhere, adjust the paths to | ||
// vat-benchmark.js driver and the JSON config file (and possibly the runner | ||
// itself, if it's not on your $PATH) accordingly. | ||
|
||
import { E } from '@endo/eventual-send'; | ||
import { Far } from '@endo/marshal'; | ||
import { assert } from '@agoric/assert'; | ||
|
||
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js'; | ||
|
||
const log = console.log; | ||
|
||
const collateralBrandKey = 'ATOM'; | ||
|
||
export function buildRootObject() { | ||
let benchmarkRounds = 0; | ||
let wallet; | ||
let walletOffersFacet; | ||
let brand; | ||
let subscriber; | ||
|
||
return Far('root', { | ||
async setup(vats, devices) { | ||
// XXX TODO: Some of this setup logic will be common to perhaps many | ||
// benchmarks. The common portions should be factored out into a | ||
// benchmark support library as we learn from experience which are the | ||
// common parts and which are the benchmark-specific parts | ||
|
||
log( | ||
`benchmark setup(${JSON.stringify(vats)}, ${JSON.stringify(devices)})`, | ||
); | ||
await E(vats.bootstrap).consumeItem('vaultFactoryKit'); | ||
|
||
const walletFactoryStartResult = await E(vats.bootstrap).consumeItem( | ||
'walletFactoryStartResult', | ||
); | ||
const agoricNames = await E(vats.bootstrap).consumeItem('agoricNames'); | ||
const atomBrand = await E(agoricNames).lookup('brand', 'ATOM'); | ||
const istBrand = await E(agoricNames).lookup('brand', 'IST'); | ||
brand = { | ||
ATOM: atomBrand, | ||
IST: istBrand, | ||
}; | ||
|
||
const bankManager = await E(vats.bootstrap).consumeItem('bankManager'); | ||
const namesByAddressAdmin = await E(vats.bootstrap).consumeItem( | ||
'namesByAddressAdmin', | ||
); | ||
|
||
async function provideSmartWallet(walletAddress) { | ||
const bank = await E(bankManager).getBankForAddress(walletAddress); | ||
return E(walletFactoryStartResult.creatorFacet) | ||
.provideSmartWallet(walletAddress, bank, namesByAddressAdmin) | ||
.then(([walletPresence]) => walletPresence); | ||
} | ||
|
||
await provideSmartWallet('agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce'); | ||
await provideSmartWallet('agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang'); | ||
await provideSmartWallet('agoric1w8wktaur4zf8qmmtn3n7x3r0jhsjkjntcm3u6h'); | ||
wallet = await provideSmartWallet('agoric1open'); | ||
walletOffersFacet = await E(wallet).getOffersFacet(); | ||
|
||
const topics = await E(wallet).getPublicTopics(); | ||
subscriber = topics.updates.subscriber; | ||
}, | ||
async runBenchmarkRound() { | ||
benchmarkRounds += 1; | ||
log(`runBenchmarkRound #${benchmarkRounds}`); | ||
|
||
const openVault = async (i, n) => { | ||
const offerId = `open-vault-${i}-of-${n}-round-${benchmarkRounds}`; | ||
const offer = Offers.vaults.OpenVault( | ||
{ brand }, | ||
{ | ||
offerId, | ||
collateralBrandKey, | ||
wantMinted: 5, | ||
giveCollateral: 1.0, | ||
}, | ||
); | ||
|
||
await E(walletOffersFacet).executeOffer(offer); | ||
|
||
const upd = await E(subscriber).getUpdateSince(); | ||
assert( | ||
upd.value.updated === 'offerStatus' && | ||
upd.value.status.id === offerId && | ||
upd.value.status.numWantsSatisfied === 1, | ||
); | ||
}; | ||
|
||
const openN = async n => { | ||
const range = [...Array(n)].map((_, i) => i + 1); | ||
await Promise.all(range.map(i => openVault(i, n))); | ||
}; | ||
|
||
await openN(1); | ||
}, | ||
}); | ||
} |
Oops, something went wrong.