carlos / platform Public

console: each remote read once per request

A request memo (reqmemo.go), installed by registerRoute on GET and HEAD
requests only, so one page view reads each box report set (platform and
each fleet), the live edges snapshot and the app's instances.json at
most once. It lives in the request context and dies with the request;
write doors get none and keep their own direct reads. Box completeness
and errors are memoized as loaded: a partial listing stays partial.

The Logs host picker takes record hosts from pageRecords (held in the
box-report cache) instead of listing and reading every record again.

Warm S3 calls: Running 17 -> 9, instance page 24 -> 10, Logs 8 -> 4.
Scripted session 586 -> 562.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev be24f8a4593276e2716007c57b41261d5d6daed5 parent 91ecbc6
9 files changed, +425 −24
  • internal/console/apiinstances.go +16 −2
  • internal/console/apisystemgeoip.go +8 −4
  • internal/console/apisystemupdate.go +2 −2
  • internal/console/claim_routes.go +5 −1
  • internal/console/perfquickwins_test.go +259 −0
  • internal/console/regioncandidates.go +4 −10
  • internal/console/reqmemo.go +124 −0
  • internal/console/server.go +4 −2
  • internal/console/testdata/perf-budgets.txt +3 −3

CI failed — run details

diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index c56015417..54ac85225 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -565,6 +565,20 @@ func loadBoxJoinComplete(ctx context.Context, s release.Store, now time.Time) (b
return joinBoxes(boxes, now), complete
}
+// platformBoxJoin is loadBoxJoinComplete on the console's release store,
+// its box reports read once per request (loadBoxes).
+func (s *Server) platformBoxJoin(ctx context.Context, now time.Time) (boxJoin, bool) {
+ if s.cfg.Releases == nil {
+ return boxJoin{}, false
+ }
+ boxes, complete, err := s.loadBoxes(ctx, s.cfg.Releases, "")
+ if err != nil {
+ log.Printf("console: api instances: could not load status boxes for the list join: %v", err)
+ return boxJoin{}, false
+ }
+ return joinBoxes(boxes, now), complete
+}
+
// loadRolloutJoin is the box join the instance list, the instance page and
// the host-retry door share (Astra plan 6 R1 #6), so the three never
// disagree about a host's rollout: the platform's boxes (status/boxes/),
@@ -592,7 +606,7 @@ func loadBoxJoinComplete(ctx context.Context, s release.Store, now time.Time) (b
// still READ, whatever relevant says: completeness is scoped, the join's
// content is not.
func (s *Server) loadRolloutJoin(ctx context.Context, acct string, now time.Time, relevant map[string]bool) (boxJoin, bool) {
- j, complete := loadBoxJoinComplete(ctx, s.cfg.Releases, now)
+ j, complete := s.platformBoxJoin(ctx, now)
if s.cfg.Releases == nil || s.cfg.Registry == "" {
return j, complete
}
@@ -615,7 +629,7 @@ func (s *Server) loadRolloutJoin(ctx context.Context, acct string, now time.Time
if f.Account != acct {
continue
}
- boxes, fleetComplete, err := status.LoadBoxesComplete(ctx, release.NewPrefixStore(s.cfg.Releases, "fleets/"+f.Name+"/"))
+ boxes, fleetComplete, err := s.loadBoxes(ctx, s.cfg.Releases, "fleets/"+f.Name+"/")
if err != nil {
log.Printf("console: rollout join %s: fleet %s boxes: %v", acct, f.Name, err)
complete = complete && !counts(f.Name)
diff --git a/internal/console/apisystemgeoip.go b/internal/console/apisystemgeoip.go
index bec97a9a6..e9f675622 100644
--- a/internal/console/apisystemgeoip.go
+++ b/internal/console/apisystemgeoip.go
@@ -248,8 +248,12 @@ func (s *Server) geoipInventory(ctx context.Context) (geoipInventoryRead, error)
inv.expected[geoipBoxKey{Label: label}] = true
}
}
- add := func(store release.Store, fleet string) error {
- boxes, complete, err := status.LoadBoxesComplete(ctx, store)
+ add := func(fleet string) error {
+ prefix := ""
+ if fleet != "" {
+ prefix = "fleets/" + fleet + "/"
+ }
+ boxes, complete, err := s.loadBoxes(ctx, s.cfg.Releases, prefix)
if err != nil {
return err
}
@@ -261,7 +265,7 @@ func (s *Server) geoipInventory(ctx context.Context) (geoipInventoryRead, error)
}
return nil
}
- if err := add(s.cfg.Releases, ""); err != nil {
+ if err := add(""); err != nil {
return inv, err
}
if s.cfg.Registry == "" {
@@ -296,7 +300,7 @@ func (s *Server) geoipInventory(ctx context.Context) (geoipInventoryRead, error)
inv.expected[geoipBoxKey{f.Name, fb.Label}] = true
}
}
- if err := add(release.NewPrefixStore(s.cfg.Releases, "fleets/"+f.Name+"/"), f.Name); err != nil {
+ if err := add(f.Name); err != nil {
// That fleet's heartbeats are unknown: its expected boxes are
// missing from boxes and block as "no heartbeat".
inv.heartbeatsComplete = false
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go
index f3f3dd9b5..6c93ec80f 100644
--- a/internal/console/apisystemupdate.go
+++ b/internal/console/apisystemupdate.go
@@ -267,7 +267,7 @@ func (s *Server) systemFeed() publicrelease.Feed {
// cannot be opened, or one whose fleets cannot be listed, is a fleet set this
// console cannot see.
func (s *Server) systemBoxes(ctx context.Context, strict bool) ([]status.Box, bool, error) {
- boxes, err := status.LoadBoxes(ctx, s.cfg.Releases)
+ boxes, _, err := s.loadBoxes(ctx, s.cfg.Releases, "")
if err != nil {
return nil, false, err
}
@@ -292,7 +292,7 @@ func (s *Server) systemBoxes(ctx context.Context, strict bool) ([]status.Box, bo
}
partial := false
for _, f := range fleets {
- fb, err := status.LoadBoxes(ctx, release.NewPrefixStore(s.cfg.Releases, "fleets/"+f.Name+"/"))
+ fb, _, err := s.loadBoxes(ctx, s.cfg.Releases, "fleets/"+f.Name+"/")
if err != nil {
if strict {
return nil, false, fmt.Errorf("fleet %s: cannot read its box heartbeats, refusing to guess which platforms to mirror: %w", f.Name, err)
diff --git a/internal/console/claim_routes.go b/internal/console/claim_routes.go
index 78a0a3359..91097dcdb 100644
--- a/internal/console/claim_routes.go
+++ b/internal/console/claim_routes.go
@@ -61,10 +61,14 @@ func claimHandlerName(h any) string {
// account) its pattern names, before its first response byte and again on
// return (withFrameClear, appframe.go). The clear is the only thing it adds
// ahead of the handler's own gates, and it changes no response.
+//
+// Every GET and HEAD request gets a request memo of its own (reqmemo.go),
+// so one page view reads each box report set, the edges files and the
+// app's instances.json at most once. Other requests get none.
func (s *Server) registerRoute(pattern string, h http.HandlerFunc) {
e := claimEntry{Kind: "route", Pattern: pattern, Handler: claimHandlerName(h)}
s.claimEntries.add(e)
- h = s.withFrameClear(pattern, h)
+ h = withReqMemoOnViews(s.withFrameClear(pattern, h))
if !s.cfg.HostClaim {
s.mux.HandleFunc(pattern, h)
return
diff --git a/internal/console/perfquickwins_test.go b/internal/console/perfquickwins_test.go
index 137268f1e..752ab679b 100644
--- a/internal/console/perfquickwins_test.go
+++ b/internal/console/perfquickwins_test.go
@@ -2,11 +2,17 @@ package console
import (
"context"
+ "errors"
"net/http"
+ "net/http/httptest"
+ "slices"
"strings"
"sync"
"testing"
"time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/status"
)
// manifestRequests records the HTTP methods of the S3 requests that name one
@@ -88,3 +94,256 @@ func TestAccountManifestCheckedOncePerProcess(t *testing.T) {
}
})
}
+
+// s3Recorder records every S3 request the fake answers: an object request's
+// method and key, or a listing's prefix.
+type s3Recorder struct {
+ mu sync.Mutex
+ reqs []s3Req
+}
+
+type s3Req struct {
+ Method string
+ Key string // "" for a listing
+ Prefix string // a listing's prefix
+}
+
+// recordS3 installs the recorder as the fake's request hook; fail, when
+// non-nil, answers the requests it names with a 403 (which the SDK does
+// not retry).
+func recordS3(lat *perfLatency, fail func(s3Req) bool) *s3Recorder {
+ rec := &s3Recorder{}
+ lat.Fake().OnRequest(func(r *http.Request) (int, <-chan struct{}) {
+ _, key, _ := strings.Cut(strings.TrimPrefix(r.URL.Path, "/"), "/")
+ q := s3Req{Method: r.Method, Key: key}
+ if key == "" {
+ q.Prefix = r.URL.Query().Get("prefix")
+ }
+ rec.mu.Lock()
+ rec.reqs = append(rec.reqs, q)
+ rec.mu.Unlock()
+ if fail != nil && fail(q) {
+ return http.StatusForbidden, nil
+ }
+ return 0, nil
+ })
+ return rec
+}
+
+func (rec *s3Recorder) reset() {
+ rec.mu.Lock()
+ rec.reqs = nil
+ rec.mu.Unlock()
+}
+
+// listings counts the listings of exactly prefix.
+func (rec *s3Recorder) listings(prefix string) int {
+ rec.mu.Lock()
+ defer rec.mu.Unlock()
+ n := 0
+ for _, q := range rec.reqs {
+ if q.Key == "" && q.Prefix == prefix {
+ n++
+ }
+ }
+ return n
+}
+
+// touching counts the requests that name a key or listing under prefix.
+func (rec *s3Recorder) touching(prefix string) int {
+ rec.mu.Lock()
+ defer rec.mu.Unlock()
+ n := 0
+ for _, q := range rec.reqs {
+ if strings.HasPrefix(q.Key, prefix) || (q.Key == "" && strings.HasPrefix(q.Prefix, prefix)) {
+ n++
+ }
+ }
+ return n
+}
+
+func (rec *s3Recorder) all() []s3Req {
+ rec.mu.Lock()
+ defer rec.mu.Unlock()
+ return slices.Clone(rec.reqs)
+}
+
+// TestInstancePageLoadsBoxesOnce: the instance page's three box readers
+// (layout, rollout join, updates) share one read of the platform's box
+// reports and one of each fleet's.
+func TestInstancePageLoadsBoxesOnce(t *testing.T) {
+ fx, lat := newPerfFixture(t)
+ c := signInPaul(t, fx)
+ u := fx.u("/apps/kass/instances/kass.carlosapp.dev")
+ if status, _, body := get(t, c, u); status != http.StatusOK {
+ t.Fatalf("instance page = %d:\n%s", status, body)
+ }
+ // One load's listings of each prefix: the platform store may list
+ // twice in one load (ListMod, then List), a fleet's prefix store once.
+ rec := recordS3(lat, nil)
+ once := map[string]int{}
+ for _, prefix := range []string{"", "fleets/fleet-a/"} {
+ if _, _, err := fx.srv.loadBoxes(context.Background(), fx.srv.cfg.Releases, prefix); err != nil {
+ t.Fatal(err)
+ }
+ once[prefix+"status/boxes/"] = rec.listings(prefix + "status/boxes/")
+ }
+ rec.reset()
+ if status, _, body := get(t, c, u); status != http.StatusOK {
+ t.Fatalf("instance page = %d:\n%s", status, body)
+ }
+ for prefix, want := range once {
+ if got := rec.listings(prefix); got != want {
+ t.Errorf("%s listed %d times in one view, want %d, one load's (requests: %v)", prefix, got, want, rec.all())
+ }
+ }
+}
+
+// TestRunningTabReadsEdgesOnce: the Running tab's region note and its
+// app default share one read of the edges files.
+func TestRunningTabReadsEdgesOnce(t *testing.T) {
+ fx, lat := newPerfFixture(t)
+ c := signInPaul(t, fx)
+ u := fx.u("/apps/kass/instances")
+ if status, _, body := get(t, c, u); status != http.StatusOK {
+ t.Fatalf("running = %d:\n%s", status, body)
+ }
+ rec := recordS3(lat, nil)
+ if status, _, body := get(t, c, u); status != http.StatusOK {
+ t.Fatalf("running = %d:\n%s", status, body)
+ }
+ if got := rec.listings("control/edges/"); got != 1 {
+ t.Errorf("control/edges/ listed %d times in one view, want 1 (requests: %v)", got, rec.all())
+ }
+}
+
+// TestRequestMemoKeepsBoxCompleteness: a box report that will not read
+// leaves the listing partial, and the memo hands the second reader in the
+// request the same partial answer, without asking the bucket again.
+func TestRequestMemoKeepsBoxCompleteness(t *testing.T) {
+ fx, lat := newPerfFixture(t)
+ rec := recordS3(lat, func(q s3Req) bool { return q.Key == "status/boxes/box-a.json" })
+ ctx := withReqMemo(context.Background())
+ first, complete, err := fx.srv.loadBoxes(ctx, fx.srv.cfg.Releases, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if complete {
+ t.Error("first read: complete with box-a's report unreadable, want partial")
+ }
+ n := len(rec.all())
+ second, complete, err := fx.srv.loadBoxes(ctx, fx.srv.cfg.Releases, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if complete {
+ t.Error("second read: complete with box-a's report unreadable, want partial")
+ }
+ if got := len(rec.all()); got != n {
+ t.Errorf("second read made %d S3 requests, want none", got-n)
+ }
+ labels := func(bs []status.Box) []string {
+ var out []string
+ for _, b := range bs {
+ out = append(out, b.Label)
+ }
+ return out
+ }
+ if !slices.Equal(labels(first), labels(second)) || !slices.Contains(labels(first), "box-b") || slices.Contains(labels(first), "box-a") {
+ t.Errorf("boxes: first %v, second %v; want both [box-b]", labels(first), labels(second))
+ }
+ // Without a memo every call reads again.
+ n = len(rec.all())
+ if _, complete, _ := fx.srv.loadBoxes(context.Background(), fx.srv.cfg.Releases, ""); complete {
+ t.Error("unmemoized read: complete, want partial")
+ }
+ if len(rec.all()) == n {
+ t.Error("a read with no memo in its context made no S3 request")
+ }
+}
+
+// TestLogsHostPickerReadsNoRecords: the Logs tab's host picker takes the
+// records' hosts from the page's cached record read, not a read of its own.
+func TestLogsHostPickerReadsNoRecords(t *testing.T) {
+ fx, lat := newPerfFixture(t)
+ c := signInPaul(t, fx)
+ ctx := context.Background()
+ hosts := []string{"one.kass.carlosapp.dev", "two.kass.carlosapp.dev", "three.kass.carlosapp.dev"}
+ for _, h := range hosts {
+ rec := provision.Record{Schema: 1, Host: h, App: "kass", Account: fx.sqid, Channel: "stable", Region: "ie",
+ CreatedAt: time.Now(), CreatedBy: "paul@keymail.dev", Slug: strings.Split(h, ".")[0]}
+ if err := provision.CreateRecord(ctx, fx.rel, rec); err != nil {
+ t.Fatal(err)
+ }
+ }
+ u := fx.u("/apps/kass/logs")
+ if status, _, body := get(t, c, u); status != http.StatusOK {
+ t.Fatalf("logs = %d:\n%s", status, body)
+ }
+ rec := recordS3(lat, nil)
+ status, _, body := get(t, c, u)
+ if status != http.StatusOK {
+ t.Fatalf("logs = %d:\n%s", status, body)
+ }
+ if got := rec.touching(provision.RecordsPrefix(fx.sqid, "kass")); got != 0 {
+ t.Errorf("a warm Logs view made %d requests for instance records, want 0 (requests: %v)", got, rec.all())
+ }
+ for _, h := range hosts {
+ if !strings.Contains(body, `<option value="`+h+`"`) {
+ t.Errorf("the host picker has no %s", h)
+ }
+ }
+}
+
+// TestReqMemoOnlyOnViews: memoize with no memo in the context loads every
+// time; registerRoute installs a memo for GET and HEAD requests only.
+func TestReqMemoOnlyOnViews(t *testing.T) {
+ loads := 0
+ load := func() (int, error) { loads++; return loads, nil }
+ for range 2 {
+ if _, err := memoize(context.Background(), "k", load); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if loads != 2 {
+ t.Errorf("with no memo: %d loads for two calls, want 2", loads)
+ }
+ ctx := withReqMemo(context.Background())
+ loads = 0
+ a, _ := memoize(ctx, "k", load)
+ b, _ := memoize(ctx, "k", load)
+ if loads != 1 || a != b {
+ t.Errorf("with a memo: %d loads, values %d and %d; want 1 load and one value", loads, a, b)
+ }
+ errs := 0
+ failing := func() (int, error) { errs++; return 0, errors.New("unreadable") }
+ _, e1 := memoize(ctx, "bad", failing)
+ _, e2 := memoize(ctx, "bad", failing)
+ if errs != 1 || e1 == nil || e2 == nil {
+ t.Errorf("a failed load: %d loads, errors %v and %v; want 1 load and its error twice", errs, e1, e2)
+ }
+
+ for _, tc := range []struct {
+ pattern, method string
+ memo bool
+ }{
+ {"POST /x", http.MethodPost, false},
+ {"GET /x", http.MethodGet, true},
+ {"GET /x", http.MethodHead, true},
+ {"/x", http.MethodGet, true},
+ {"/x", http.MethodPost, false},
+ {"/x", http.MethodDelete, false},
+ } {
+ t.Run(tc.method+" "+tc.pattern, func(t *testing.T) {
+ s := &Server{mux: http.NewServeMux()}
+ seen := false
+ s.registerRoute(tc.pattern, func(w http.ResponseWriter, r *http.Request) {
+ seen = r.Context().Value(reqMemoKey{}) != nil
+ })
+ s.mux.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(tc.method, "/x", nil))
+ if seen != tc.memo {
+ t.Errorf("memo in the request context: %v, want %v", seen, tc.memo)
+ }
+ })
+ }
+}
diff --git a/internal/console/regioncandidates.go b/internal/console/regioncandidates.go
index 4eec3cad0..97804fcc4 100644
--- a/internal/console/regioncandidates.go
+++ b/internal/console/regioncandidates.go
@@ -7,7 +7,6 @@ import (
"os"
"sort"
"sync"
- "time"
"github.com/carlosframework/platform/internal/geo"
"github.com/carlosframework/platform/internal/provision"
@@ -198,12 +197,6 @@ func (s *Server) regionCands(snap edgesSnapshot) []regionCandidate {
return regionCandidates(snap, s.cfg.HomeRegion, s.expectedSecretsFP())
}
-// liveEdges is the one read every automatic-eligibility caller makes: the
-// edges files joined with box liveness as of now (F1).
-func (s *Server) liveEdges(ctx context.Context) (edgesSnapshot, error) {
- return readLiveEdgesSnapshot(ctx, s.cfg.Releases, time.Now())
-}
-
// candsOrHome is the candidates from a fresh snapshot, or the home alone
// when the listing fails (or there is no bucket): for displays and guesses
// that must not fail.
@@ -275,14 +268,15 @@ type regionPolicy struct {
}
// appPolicy reads the manifest directly (never instanceManifest, which
-// answers the caller itself) and the fleet placement. Any failure is
-// policyUnreadable: an unrestricted policy is never invented.
+// answers the caller itself; once per page view, through the request memo)
+// and the fleet placement. Any failure is policyUnreadable: an
+// unrestricted policy is never invented.
func (s *Server) appPolicy(ctx context.Context, acct *Account, app string) regionPolicy {
var p regionPolicy
if s.cfg.Releases == nil {
return regionPolicy{State: policyUnreadable} // no bucket: nothing to read, so nothing is allowed
}
- m, err := provision.GetManifest(ctx, s.cfg.Releases, acct.Sqid, app)
+ m, err := s.instancesManifest(ctx, acct.Sqid, app)
switch {
case err == nil:
p.State, p.M = policyKnown, m
diff --git a/internal/console/reqmemo.go b/internal/console/reqmemo.go
new file mode 100644
index 000000000..6cc401eb4
--- /dev/null
+++ b/internal/console/reqmemo.go
@@ -0,0 +1,124 @@
+package console
+
+import (
+ "context"
+ "errors"
+ "net/http"
+ "sync"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+// The request memo: one page view reads each of a few remote things at most
+// once, however many of its parts ask (the box reports, the edges files, the
+// app's instances.json). It lives in the request's context and dies with the
+// request: nothing is shared between requests, so nothing here can go stale.
+//
+// registerRoute installs it on GET and HEAD requests only. A write door's
+// request has none, so every read a door decides on (liveEdges for
+// placement, the strict box loads) is its own, made when it asks.
+//
+// A memoized value is shared by every reader in the request: callers treat
+// these results as read-only, as they always have. A failed load is
+// memoized too, so a second reader in the same request gets the same error
+// rather than a second attempt. The load runs under the first reader's
+// context (a part with a shorter timeout bounds it for every reader after).
+
+type reqMemoKey struct{}
+
+type reqMemo struct {
+ mu sync.Mutex
+ entries map[string]*reqMemoEntry
+}
+
+type reqMemoEntry struct {
+ done chan struct{}
+ val any
+ err error
+}
+
+// errMemoLoadPanicked is what a reader waiting on a load sees when that
+// load panicked.
+var errMemoLoadPanicked = errors.New("console: request memo: the load panicked")
+
+// withReqMemo returns ctx with a fresh, empty memo.
+func withReqMemo(ctx context.Context) context.Context {
+ return context.WithValue(ctx, reqMemoKey{}, &reqMemo{entries: map[string]*reqMemoEntry{}})
+}
+
+// memoize is load's answer for key, made at most once per memo. With no
+// memo in ctx, load runs every time. Concurrent readers of one key in one
+// request wait for the first one's load.
+func memoize[T any](ctx context.Context, key string, load func() (T, error)) (T, error) {
+ m, _ := ctx.Value(reqMemoKey{}).(*reqMemo)
+ if m == nil {
+ return load()
+ }
+ m.mu.Lock()
+ e, ok := m.entries[key]
+ if !ok {
+ e = &reqMemoEntry{done: make(chan struct{}), err: errMemoLoadPanicked}
+ m.entries[key] = e
+ }
+ m.mu.Unlock()
+ if ok {
+ <-e.done
+ v, _ := e.val.(T)
+ return v, e.err
+ }
+ defer close(e.done)
+ v, err := load()
+ e.val, e.err = v, err
+ return v, err
+}
+
+// withReqMemoOnViews gives each GET and HEAD request a memo of its own.
+func withReqMemoOnViews(h http.HandlerFunc) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ if readOnlyMethod(r.Method) {
+ r = r.WithContext(withReqMemo(r.Context()))
+ }
+ h(w, r)
+ }
+}
+
+// loadBoxes is status.LoadBoxesComplete on st under prefix ("" for the
+// platform's own boxes, "fleets/<name>/" for a customer fleet's), once per
+// request. complete and err are exactly the load's: a partial listing stays
+// partial for every reader. The memo key names only the prefix, so st is
+// always the console's release store. The slice is clipped, so a reader
+// that appends to it gets a copy rather than writing into the memo's.
+func (s *Server) loadBoxes(ctx context.Context, st release.Store, prefix string) (boxes []status.Box, complete bool, err error) {
+ type loaded struct {
+ boxes []status.Box
+ complete bool
+ }
+ l, err := memoize(ctx, "boxes:"+prefix, func() (loaded, error) {
+ store := st
+ if prefix != "" {
+ store = release.NewPrefixStore(st, prefix)
+ }
+ b, c, err := status.LoadBoxesComplete(ctx, store)
+ return loaded{b, c}, err
+ })
+ return l.boxes[:len(l.boxes):len(l.boxes)], l.complete, err
+}
+
+// liveEdges is the one read every automatic-eligibility caller makes: the
+// edges files joined with box liveness as of now (F1), once per request.
+func (s *Server) liveEdges(ctx context.Context) (edgesSnapshot, error) {
+ return memoize(ctx, "edges", func() (edgesSnapshot, error) {
+ return readLiveEdgesSnapshot(ctx, s.cfg.Releases, time.Now())
+ })
+}
+
+// instancesManifest is the app's instances.json (provision.GetManifest),
+// once per request.
+func (s *Server) instancesManifest(ctx context.Context, sqid, app string) (*provision.Manifest, error) {
+ return memoize(ctx, "instances-manifest:"+sqid+"/"+app, func() (*provision.Manifest, error) {
+ return provision.GetManifest(ctx, s.cfg.Releases, sqid, app)
+ })
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index 588599841..324a1f65f 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -4047,9 +4047,11 @@ func (s *Server) handleAppLogs(w http.ResponseWriter, r *http.Request) {
p.LogHosts = append(p.LogHosts, rt.Host)
}
}
+ // The records' hosts come from the page's own record read (pageRecords,
+ // held in the box-report cache), not a second listing of its own.
if s.cfg.Releases != nil {
ctx, cancel := context.WithTimeout(r.Context(), instanceStoreTimeout)
- recs, _, err := s.listRecords(ctx, acct.Sqid, p.AppName, instanceListMax)
+ recs, err := s.pageRecords(ctx, acct.Sqid, p.AppName)
cancel()
if err == nil {
for _, rec := range recs {
@@ -5645,7 +5647,7 @@ func (s *Server) handleNewCanary(w http.ResponseWriter, r *http.Request) {
// of a transient bucket error sends them at a door that will refuse them.
// Unreadable therefore renders the neutral form, never the enable step.
func (s *Server) instanceDomainFor(ctx context.Context, sqid, app string) (domain string, absent bool) {
- m, err := provision.GetManifest(ctx, s.cfg.Releases, sqid, app)
+ m, err := s.instancesManifest(ctx, sqid, app)
switch {
case err == nil:
return m.Domain, false
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt
index b6ad20440..6a72631f6 100644
--- a/internal/console/testdata/perf-budgets.txt
+++ b/internal/console/testdata/perf-budgets.txt
@@ -44,9 +44,9 @@ GET /a/{sqid}/apps/{app}/activity over: a warm view reads nothing (the app-tab f
GET /a/{sqid}/apps/{app}/analytics over: both telemetry settings, the analytics day listing and one day read (4 S3 calls warm, median about 105 ms); cold, also the app-tab frame and the account manifest (11 S3 calls, about 290 ms)
GET /a/{sqid}/apps/{app}/availability over: both telemetry settings and three listings and a read each for the log and error chunks (10 S3 calls warm)
GET /a/{sqid}/apps/{app}/errors over: both telemetry settings and three listings and a read each for the log and error chunks (10 S3 calls warm)
-GET /a/{sqid}/apps/{app}/instances over: instances.json, and every edges file and box report listed and read twice (17 S3 calls warm)
-GET /a/{sqid}/apps/{app}/instances/{host} over: the instance record, and the box reports and the fleet box reports listed and read three times (24 S3 calls warm)
-GET /a/{sqid}/apps/{app}/logs over: a listing and a read of every instance record, three listings for the log chunks and a chunk read (8 S3 calls warm)
+GET /a/{sqid}/apps/{app}/instances over: instances.json, and every edges file and box report listed and read once per view (9 S3 calls warm, median about 290 ms); cold, also the app-tab frame and the account manifest (16 S3 calls and 1 host call, about 510 ms)
+GET /a/{sqid}/apps/{app}/instances/{host} over: the instance record, instances.json, the edges listing, and the box reports and the fleet box reports listed and read once per view (10 S3 calls warm, median about 315 ms); cold, also the app-tab frame and the account manifest (17 S3 calls, about 495 ms)
+GET /a/{sqid}/apps/{app}/logs over: three listings for the log chunks and a chunk read; the host picker uses the records the page already holds (4 S3 calls warm, median about 105 ms); cold, also the app-tab frame and the account manifest (11 S3 calls, about 285 ms)
GET /a/{sqid}/apps/{app}/releases over: the release and tag listings, at most 20 manifests, retention and instances.json (6 S3 calls warm, median about 160 ms; 4 on the fixture's empty page 2)
GET /a/{sqid}/apps/{app}/settings over: General builds the whole settings record: each environment and its store read twice, every instance record, the domain claims, cert-warm records, every box report and a listing of every key under the app, plus the swap policy (25 S3 calls warm)
GET /a/{sqid}/apps/{app}/settings/{section} over: Domains, Environments, Storage, Email and Feature flags build the whole settings record, as General does (24 S3 calls warm; General 25); Errors and analytics 2 (both telemetry settings); the pipeline section, Placement, Delete and the advanced redirect none