Skip to content

fix(task): size with one region-wide price table, not a Price List call per candidate - #1236

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1181-sizing-pricing-calls
Oct 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1181-sizing-pricing-calls

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1181

What was slow

truffleFinder.FindCandidates (cmd/task.go) called truffleaws.Client.OnDemandPrice once for every match, serially. Each call is one Price List GetProducts request filtered by instanceType. A cpu: 2 spec matches 1325 types in us-east-1, so that was 1325 requests, each retried up to 8 times when throttled (truffle#175). E1 measured 149-256 s before RunInstances; the instance search itself is a few paginated DescribeInstanceTypes calls (the pinned case took 4-5 s in total).

Fix

  • New pkg/pricelist: RegionOnDemandPrices runs one paginated GetProducts query per region. It uses truffle's onDemandFilters minus instanceType, with MaxResults=100, a 40-page cap, and the same 8-attempt retryer and us-east-1 endpoint as truffle. That costs ceil(types in region / 100) requests, which does not depend on what the spec matched. It lives in pkg/ because TestNoNewAWSSDKImportsInCmd forbids new SDK imports in cmd/.
  • The finder fetches that table once, then prices each candidate from it. A type the table lacks falls back to libs/pricing's static table by exact match, the same order truffle's fallbackPricer uses. If the live fetch fails, there is no per-candidate retry storm: one failed request, then static prices.
  • New output: when any candidate was ranked on a static price, stderr says how many, why, and the table's PricesAsOf date. Before, this was silent.
  • -v prints sizing: instance search Xs (N candidates), pricing Ys (K Price List request(s)).
  • truffle#182 throttling: each process now makes ~14 requests instead of 1325, so concurrent launches put about 100x less load on the Price List API.

The real home for this is truffle. I filed spore-host/truffle#262 with the measurements; once it lands, spawn should drop pkg/pricelist.

Gate

TestSizingMakesAConstantNumberOfPricingCalls runs renderTaskDryRun on a cpu: 2 spec, with 1325 synthetic candidates and a recording GetProducts fake that counts every request and honours the regionCode/instanceType filters. It asserts:

  • no request filters by instanceType;
  • the request count is exactly the pages of one region table (14);
  • the count is the same for 10 candidates and for 1325;
  • the cheapest type wins.

TestSizingFallsBackToTheStaticTableAndSaysSo asserts one call when the Price List fails, exact static prices, and a labelled note.

I watched both fail against two reverts that compile:

  1. A per-candidate GetProducts with an instanceType filter (the old design): 1325 per-type requests, 106 calls on the failure path.
  2. Fetching the table inside the candidate loop (the break dropped): 18,550 requests, with 140 vs 18,550 for the two candidate counts.

Checks

  • make check: all tests pass. check-build-tags fails on /private/tmp paths, and it fails the same way on unmodified main.
  • make lint: 0 issues.
  • semgrep --config=auto --error: 0 findings.
  • make check-docs: clean.

Not verified

No AWS calls were made. I have not measured the real page count or latency of a region-only GetProducts query against the live Price List, nor checked that its rates equal the per-type rates. The filters are identical apart from instanceType, so they should, but a single live dry run would confirm it.

@scttfrdmn scttfrdmn added this to the v0.138.0 milestone Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.81356% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/pricelist/pricelist.go 79.45% 12 Missing and 3 partials ⚠️
cmd/task.go 60.00% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

…ll per candidate (#1181)

Sizing priced each of the ~1325 matching types with its own GetProducts
request (149-256 s before RunInstances in E1). Fetch the region's
On-Demand table once via a new pkg/pricelist (ceil(types/100) pages,
independent of the spec), fall back to the static table by exact match
with a labelled note, and report the timing breakdown under -v.

Fixes #1181
@scttfrdmn
scttfrdmn force-pushed the fix/1181-sizing-pricing-calls branch from 8205c55 to 9510471 Compare October 20, 2026 18:40
@scttfrdmn
scttfrdmn merged commit a8dd3e8 into main Oct 20, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1181-sizing-pricing-calls branch October 20, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task run: instance-type sizing takes 2.5–7 minutes before anything launches

1 participant