-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: let makeRunUtils caller provide run policy #10348
Conversation
Deploying agoric-sdk with Cloudflare Pages
|
hang on... I should integrate this into an existing bootstrap test... |
darn... I'm having trouble getting I should have tested that it works before I put so much work into doing a computron measurement. unsettled value for kp3542
|
ah. I had a bug in turning off the policy, so when I started contracts, I tripped the 65Mc limit. |
It's now integrated into a couple of existing bootstrap tests, though only when $ cd agoric-sdk/packages/boot
$ SWINGSET_WORKER_TYPE=xsnap yarn test test/bootstrapTests/price-feed-replace.test.ts
...
✔ setupVaults; run updatePriceFeeds proposals (1m 27.6s)
ℹ setPrice computrons 65536531n
...
$ SWINGSET_WORKER_TYPE=xsnap yarn test test/bootstrapTests/orchestration.test.ts
...
✔ stakeAtom - smart wallet (13.8s)
ℹ makeAccount computrons 15231491n
... |
re docs: how does benchmarkerator relate? |
@gibson042 merge conflicts crept in. I presume you don't mind that I rebased to address them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Nearly every comment I have is a naming suggestion, and none of them are blockers.
* @param {boolean} [ignoreBlockLimit] | ||
* @returns {import('./launch-chain.js').ChainRunPolicy} | ||
*/ | ||
export function computronCounter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thrilled to see this pulled out of launch-chain.js, but we actually already have packages/SwingSet/src/lib/runPolicies.js. I think merging it in would be out-of-scope for this PR because it's a cosmic-swingset ChainRunPolicy rather than merely a SwingSet RunPolicy, although in the fullness of time that's probably exactly what should happen because the extra methods of the former aren't really blockchain-specific.
At any rate, focusing on the present, I'd like to see this function renamed for accuracy, e.g.:
export function computronCounter( | |
export function makeExclusiveCleanupRunPolicy( |
(or similar).
and its containing file renamed to something like chain-run-polic{y,ies}.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the feedback, but due to how much stuff I'm juggling, I'm inclined to leave the swingset refactoring to folks like yourself that spend more time in the swingset code.
{ beansPerUnit, vatCleanupBudget }, | ||
ignoreBlockLimit = false, | ||
) { | ||
const { | ||
[BeansPerBlockComputeLimit]: blockComputeLimit, | ||
[BeansPerVatCreation]: vatCreation, | ||
[BeansPerXsnapComputron]: xsnapComputron, | ||
} = beansPerUnit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: for better comprehensibility, especially at call sites, consider splitting the overly-generic beansPerUnit
parameter to be less directly coupled to cosmic-swingset chain parameters:
{ beansPerUnit, vatCleanupBudget }, | |
ignoreBlockLimit = false, | |
) { | |
const { | |
[BeansPerBlockComputeLimit]: blockComputeLimit, | |
[BeansPerVatCreation]: vatCreation, | |
[BeansPerXsnapComputron]: xsnapComputron, | |
} = beansPerUnit; | |
{ computronScale, computeLimit, vatCreationCost, vatCleanupBudget }, | |
) { | |
// Prefer just the new names, but to clarify their mapping: | |
// const blockComputeLimit = computeLimit; | |
// const vatCreation = vatCreationCost; | |
// const xsnapComputron = computronScale; | |
const ignoreBlockLimit = computeLimit === Infinity; |
and then call sites look something like:
async function bootstrapBlock(blockHeight, blockTime, params) {
…
// This is before the initial block, we need to finish processing the
// entire bootstrap before opening for business.
const runPolicyConfig = makeRunPolicyConfig(params, true);
const runPolicy = makeExclusiveCleanupRunPolicy(runPolicyConfig);
…
}
async function endBlock(blockHeight, blockTime, params) {
…
// If we have work to complete this block, it needs to run to completion.
// It will also run to completion any work that swingset still had pending.
const neverStop = runThisBlock.size() > 0;
// Process the work for this block using a dedicated Cranker with a stateful
// run policy.
const runPolicyConfig = makeRunPolicyConfig(params, neverStop);
const runPolicy = makeExclusiveCleanupRunPolicy(runPolicyConfig);
…
}
with
/**
* Derive SwingSet run policy configuration from cosmic-swingset parameters
* (maximum computation per block, computron scale factor, etc.).
*
* @param {object} params
* @param {BeansPerUnit} params.beansPerUnit
* @param {import('@agoric/swingset-vat').CleanupBudget} [params.vatCleanupBudget]
* @param {boolean} [ignoreComputeLimit]
*/
function makeRunPolicyConfig(params, ignoreComputeLimit = false) {
const { beansPerUnit, vatCleanupBudget } = params;
const {
[BeansPerBlockComputeLimit]: requestedComputeLimit,
[BeansPerVatCreation]: vatCreationCost,
[BeansPerXsnapComputron]: computronScale,
} = beansPerUnit;
const computeLimit = ignoreComputeLimit ? Infinity : requestedComputeLimit;
return { computronScale, computeLimit, vatCreationCost, vatCleanupBudget };
}
/** @typedef {{ provideRunPolicy: () => RunPolicy | undefined }} RunPolicyMaker */ | ||
|
||
/** | ||
* @param {import('../src/controller/controller.js').SwingsetController} controller | ||
* @param {RunPolicyMaker} [perfTool] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempted future-proofing: perfTool: RunPolicyMaker
→ harness: RunHarness
(and likewise in packages/boot/tools/supports.ts and the other files)
/** @typedef {{ provideRunPolicy: () => RunPolicy | undefined }} RunPolicyMaker */ | |
/** | |
* @param {import('../src/controller/controller.js').SwingsetController} controller | |
* @param {RunPolicyMaker} [perfTool] | |
/** @typedef {{ provideRunPolicy: () => RunPolicy | undefined }} RunHarness */ | |
/** | |
* @param {import('../src/controller/controller.js').SwingsetController} controller | |
* @param {RunHarness} [harness] provides run policies for the controller |
/** @param {boolean} x */ | ||
usePolicy: x => { | ||
counting = x; | ||
if (!counting) { | ||
policy = undefined; | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @param {boolean} x */ | |
usePolicy: x => { | |
counting = x; | |
if (!counting) { | |
policy = undefined; | |
} | |
}, | |
/** @param {boolean} enabled */ | |
usePolicy: enabled => { | |
counting = enabled; | |
if (!counting) { | |
policy = undefined; | |
} | |
}, |
policy = undefined; | ||
} | ||
}, | ||
totalCount: () => (policy?.totalBeans() || 0n) / c2b, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
totalCount: () => (policy?.totalBeans() || 0n) / c2b, | |
totalComputronCount: () => (policy?.totalBeans() || 0n) / c2b, |
packages/boot/tools/supports.ts
Outdated
@@ -660,3 +669,45 @@ export const makeSwingsetTestKit = async ( | |||
}; | |||
}; | |||
export type SwingsetTestKit = Awaited<ReturnType<typeof makeSwingsetTestKit>>; | |||
|
|||
export const makePolicyProvider = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const makePolicyProvider = () => { | |
export const makeRunPolicyProvider = () => { |
const cleanupPossible = | ||
Object.values(remainingCleanups).length > 0 | ||
? Object.values(remainingCleanups).some(n => n > 0) | ||
: defaultCleanupBudget > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please feel free to clean up this function a bit.
const cleanupPossible = | |
Object.values(remainingCleanups).length > 0 | |
? Object.values(remainingCleanups).some(n => n > 0) | |
: defaultCleanupBudget > 0; | |
const cleanupPossible = Object.values(remainingCleanups).some(n => n > 0); |
in a couple tests: $ cd agoric-sdk/packages/boot $ SWINGSET_WORKER_TYPE=xsnap yarn test test/bootstrapTests/price-feed-replace.test.ts ... ✔ setupVaults; run updatePriceFeeds proposals (1m 27.6s) ℹ setPrice computrons 65536531n $ SWINGSET_WORKER_TYPE=xsnap yarn test test/bootstrapTests/orchestration.test.ts ... ✔ stakeAtom - smart wallet (13.8s) ℹ makeAccount computrons 15231491n
Rename types/functions/parameters as suggested at: * #10348 (comment) * #10348 (comment)
Description
Support computron measurements in boostrap tests for performance testing by letting
makeRunUtils
caller provide a way to make a run policy.Security Considerations
A swingset controller relies on the run policy to be well-behaved. But the caller of
makeRunUtils
can only shoot themselves in the foot.Scaling Considerations
helps measure scaling issues
Documentation Considerations
JSDocs with static types provide adequate docs for an internal tool such as this.
Testing Considerations
Integration with a couple bootstrap tests is included.
See also #10254 .
Upgrade Considerations
n/a