Track which replicas are actually being used, and summarise the fleet
Two things a cluster with many nodes and many GPUs needs that were missing, and they are the same thing seen from two distances. Idle tracking. The control plane knew what was placed and whether it was healthy, never whether anyone wanted it — so on a fleet with more models than cards there was no way to answer the first question anyone asks, which is what can I stop. The router is the only thing that knows, so it now reports it: a timestamp written in Acquire, where a request already meets an endpoint under a lock already held, and collected once a tick as a map. That shape is the point. Per-request notification would be a firehose carrying one bit — the newest timestamp wins — and this costs the same on four replicas as on four hundred. It travels through an interface in the direction opposite EndpointSink, for the same reason that one exists: the control plane decides what should run, the router knows whether anyone wants it, and neither should need to be in the other's process to say so. Unknown is kept distinct from idle throughout. A router that has just restarted knows nothing, and a zero timestamp would be the oldest idle replica in every comparison — so one restart would nominate an entire fleet for eviction. Absent from the map, "-" in the table, negative in the JSON, and IdleFor returns a second value rather than a duration anything could act on by mistake. ctl status. A per-node listing is right for four nodes and wrong for two hundred: how full am I, what is broken, what is holding cards nobody is using are aggregates, and reading them off a long table is a chore, which means it gets skipped. Capacity per GPU class with usage bars, free whole nodes per fabric — the number that decides whether a multi-node replica can land, since free cards on the wrong fabric are not capacity for a model that spans nodes — replica and model counts, models that cannot be placed, and what has gone unasked-for. Derived from the same state the tables show, so it cannot disagree with them. Unhealthy GPUs count as neither used nor free, because counting them free is how a cluster looks like it has room it does not. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1431426db0
commit
9d8cd5e284
15 files changed
+928
-20
No files matched your search
@@ -27,6 +27,7 @@ func New(ctl *control.Controller) *API { return &API{ctl: ctl} }
|
||||
|
||||
// Register mounts the endpoints on a mux under /api/v1.
|
||||
func (a *API) Register(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/v1/summary", a.summary)
|
||||
mux.HandleFunc("GET /api/v1/nodes", a.listNodes)
|
||||
mux.HandleFunc("GET /api/v1/models", a.listModels)
|
||||
mux.HandleFunc("GET /api/v1/replicas", a.listReplicas)
|
||||
@@ -77,16 +78,21 @@ type ModelView struct {
|
||||
|
||||
// ReplicaView is a replica as `ctl replicas` shows it.
|
||||
type ReplicaView struct {
|
||||
ID string `json:"id"`
|
||||
Model string `json:"model"`
|
||||
Profile string `json:"profile"`
|
||||
State string `json:"state"`
|
||||
Pool string `json:"pool,omitempty"`
|
||||
Fabric string `json:"fabric,omitempty"`
|
||||
Endpoint string `json:"endpoint,omitempty"`
|
||||
AgeSec int64 `json:"age_seconds"`
|
||||
Err string `json:"error,omitempty"`
|
||||
Shards []ShardView `json:"shards"`
|
||||
ID string `json:"id"`
|
||||
Model string `json:"model"`
|
||||
Profile string `json:"profile"`
|
||||
State string `json:"state"`
|
||||
Pool string `json:"pool,omitempty"`
|
||||
Fabric string `json:"fabric,omitempty"`
|
||||
Endpoint string `json:"endpoint,omitempty"`
|
||||
AgeSec int64 `json:"age_seconds"`
|
||||
// IdleSec is how long since a request was routed here. Negative means the
|
||||
// router has not reported any use of this replica, which is not the same
|
||||
// as idle — it is what a replica looks like before anything has asked for
|
||||
// it, and after a router restart.
|
||||
IdleSec int64 `json:"idle_seconds"`
|
||||
Err string `json:"error,omitempty"`
|
||||
Shards []ShardView `json:"shards"`
|
||||
}
|
||||
|
||||
// ShardView is one shard of a replica.
|
||||
@@ -212,7 +218,13 @@ func (a *API) Replicas(model string) []ReplicaView {
|
||||
ID: rep.ID, Model: rep.Model, Profile: rep.Profile,
|
||||
State: rep.State.String(), Pool: rep.Pool, Fabric: rep.Fabric,
|
||||
Endpoint: rep.Endpoint, Err: rep.Err,
|
||||
AgeSec: int64(time.Since(rep.CreatedAt).Seconds()),
|
||||
AgeSec: int64(time.Since(rep.CreatedAt).Seconds()),
|
||||
IdleSec: -1,
|
||||
}
|
||||
if rep.LastUsedAt.IsZero() {
|
||||
v.IdleSec = -1
|
||||
} else {
|
||||
v.IdleSec = int64(time.Since(rep.LastUsedAt).Seconds())
|
||||
}
|
||||
for _, s := range rep.Shards {
|
||||
v.Shards = append(v.Shards, ShardView{
|
||||
@@ -225,6 +237,10 @@ func (a *API) Replicas(model string) []ReplicaView {
|
||||
return out
|
||||
}
|
||||
|
||||
func (a *API) summary(w http.ResponseWriter, _ *http.Request) {
|
||||
writeJSON(w, http.StatusOK, a.Summary())
|
||||
}
|
||||
|
||||
func (a *API) explainPlacement(w http.ResponseWriter, r *http.Request) {
|
||||
model := r.URL.Query().Get("model")
|
||||
if model == "" {
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
package adminapi
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Summary is the whole fleet in one answer.
|
||||
//
|
||||
// A per-node listing is the right tool for four nodes and the wrong one for two
|
||||
// hundred: the questions that matter at that size — how full am I, what is
|
||||
// broken, what is holding cards it is not using — are aggregates, and reading
|
||||
// them off a long table is a chore that gets skipped. Everything here is
|
||||
// derived from the same state the tables show, so it can never disagree with
|
||||
// them; it is a different question asked of the same facts.
|
||||
type Summary struct {
|
||||
Nodes NodeTotals `json:"nodes"`
|
||||
GPUs []ClassUse `json:"gpus"`
|
||||
// Fabrics matter because a multi-node replica may never span two of them,
|
||||
// so free capacity in the wrong fabric is not capacity for the model that
|
||||
// needs it.
|
||||
Fabrics []FabricUse `json:"fabrics,omitempty"`
|
||||
Replicas ReplicaTotal `json:"replicas"`
|
||||
Models ModelTotals `json:"models"`
|
||||
// Unplaceable names models the scheduler currently cannot satisfy. This is
|
||||
// the line that turns "something is wrong" into a place to look.
|
||||
Unplaceable []string `json:"unplaceable,omitempty"`
|
||||
// IdleReplicas are serving replicas nothing has asked for in a while, which
|
||||
// on a fleet with more models than GPUs is the first place to find room.
|
||||
IdleReplicas []IdleReplica `json:"idle_replicas,omitempty"`
|
||||
}
|
||||
|
||||
// NodeTotals counts nodes by the states that need different responses.
|
||||
type NodeTotals struct {
|
||||
Total int `json:"total"`
|
||||
Ready int `json:"ready"`
|
||||
Cordoned int `json:"cordoned"`
|
||||
Draining int `json:"draining"`
|
||||
Unreachable int `json:"unreachable"`
|
||||
}
|
||||
|
||||
// ClassUse is how much of one kind of card is in use.
|
||||
type ClassUse struct {
|
||||
Class string `json:"class"`
|
||||
Total int `json:"total"`
|
||||
Used int `json:"used"`
|
||||
// Unhealthy GPUs are neither used nor available, and counting them as free
|
||||
// is how a cluster looks like it has room it does not have.
|
||||
Unhealthy int `json:"unhealthy"`
|
||||
}
|
||||
|
||||
// Free is what can still be allocated.
|
||||
func (c ClassUse) Free() int { return c.Total - c.Used - c.Unhealthy }
|
||||
|
||||
// FabricUse is capacity within one fabric.
|
||||
type FabricUse struct {
|
||||
Fabric string `json:"fabric"`
|
||||
Nodes int `json:"nodes"`
|
||||
// LargestFreeBlock is the most nodes on this fabric that are entirely free,
|
||||
// which is the number that decides whether a multi-node replica can land.
|
||||
LargestFreeBlock int `json:"largest_free_block"`
|
||||
}
|
||||
|
||||
// ReplicaTotal counts replicas by state.
|
||||
type ReplicaTotal struct {
|
||||
Ready int `json:"ready"`
|
||||
Starting int `json:"starting"`
|
||||
Draining int `json:"draining"`
|
||||
Failed int `json:"failed"`
|
||||
}
|
||||
|
||||
// ModelTotals counts models by whether they have what they asked for.
|
||||
type ModelTotals struct {
|
||||
Total int `json:"total"`
|
||||
Satisfied int `json:"satisfied"`
|
||||
Short int `json:"short"`
|
||||
}
|
||||
|
||||
// IdleReplica is a replica holding hardware nothing is asking for.
|
||||
type IdleReplica struct {
|
||||
ID string `json:"id"`
|
||||
Model string `json:"model"`
|
||||
IdleSec int64 `json:"idle_seconds"`
|
||||
GPUs int `json:"gpus"`
|
||||
}
|
||||
|
||||
// idleThreshold is how long a replica must go unasked-for to be worth naming.
|
||||
//
|
||||
// Minutes rather than seconds, because a replica that flaps in and out of this
|
||||
// list is noise, and because unloading one throws away its KV cache — the thing
|
||||
// prefix routing spent its effort filling.
|
||||
const idleThreshold = 10 * time.Minute
|
||||
|
||||
// Summary builds the fleet summary.
|
||||
func (a *API) Summary() Summary {
|
||||
var s Summary
|
||||
|
||||
nodes := a.Nodes()
|
||||
byClass := map[string]*ClassUse{}
|
||||
s.Nodes.Total = len(nodes)
|
||||
for _, n := range nodes {
|
||||
switch n.State {
|
||||
case "ready":
|
||||
s.Nodes.Ready++
|
||||
case "cordoned":
|
||||
s.Nodes.Cordoned++
|
||||
case "draining":
|
||||
s.Nodes.Draining++
|
||||
default:
|
||||
s.Nodes.Unreachable++
|
||||
}
|
||||
for _, c := range n.Classes {
|
||||
if byClass[c] == nil {
|
||||
byClass[c] = &ClassUse{Class: c}
|
||||
}
|
||||
}
|
||||
// A node reports one class in practice; attribute its cards to it.
|
||||
if len(n.Classes) == 1 {
|
||||
u := byClass[n.Classes[0]]
|
||||
u.Total += n.GPUTotal
|
||||
u.Unhealthy += len(n.Unhealthy)
|
||||
u.Used += n.GPUTotal - n.GPUFree - len(n.Unhealthy)
|
||||
}
|
||||
}
|
||||
for _, u := range byClass {
|
||||
s.GPUs = append(s.GPUs, *u)
|
||||
}
|
||||
sort.Slice(s.GPUs, func(i, j int) bool { return s.GPUs[i].Class < s.GPUs[j].Class })
|
||||
|
||||
byFabric := map[string]*FabricUse{}
|
||||
for _, n := range nodes {
|
||||
for _, f := range n.Fabrics {
|
||||
if byFabric[f] == nil {
|
||||
byFabric[f] = &FabricUse{Fabric: f}
|
||||
}
|
||||
byFabric[f].Nodes++
|
||||
// Entirely free, which is what a multi-node replica needs: a node
|
||||
// with one card in use cannot contribute a full-width shard.
|
||||
if n.State == "ready" && n.GPUFree == n.GPUTotal && n.GPUTotal > 0 {
|
||||
byFabric[f].LargestFreeBlock++
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range byFabric {
|
||||
s.Fabrics = append(s.Fabrics, *f)
|
||||
}
|
||||
sort.Slice(s.Fabrics, func(i, j int) bool { return s.Fabrics[i].Fabric < s.Fabrics[j].Fabric })
|
||||
|
||||
for _, r := range a.Replicas("") {
|
||||
switch r.State {
|
||||
case "ready":
|
||||
s.Replicas.Ready++
|
||||
case "draining":
|
||||
s.Replicas.Draining++
|
||||
case "failed":
|
||||
s.Replicas.Failed++
|
||||
default:
|
||||
s.Replicas.Starting++
|
||||
}
|
||||
if r.State == "ready" && r.IdleSec >= int64(idleThreshold.Seconds()) {
|
||||
gpus := 0
|
||||
for _, sh := range r.Shards {
|
||||
gpus += len(sh.GPUs)
|
||||
}
|
||||
s.IdleReplicas = append(s.IdleReplicas, IdleReplica{
|
||||
ID: r.ID, Model: r.Model, IdleSec: r.IdleSec, GPUs: gpus,
|
||||
})
|
||||
}
|
||||
}
|
||||
sort.Slice(s.IdleReplicas, func(i, j int) bool {
|
||||
return s.IdleReplicas[i].IdleSec > s.IdleReplicas[j].IdleSec
|
||||
})
|
||||
|
||||
for _, m := range a.Models() {
|
||||
s.Models.Total++
|
||||
if m.Ready >= m.Min {
|
||||
s.Models.Satisfied++
|
||||
continue
|
||||
}
|
||||
s.Models.Short++
|
||||
// Short of replicas and unable to place more is the actionable case;
|
||||
// short and still starting is just a cluster doing its job.
|
||||
if m.Total <= m.Ready {
|
||||
s.Unplaceable = append(s.Unplaceable, m.Name)
|
||||
}
|
||||
}
|
||||
sort.Strings(s.Unplaceable)
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package adminapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/inventory"
|
||||
)
|
||||
|
||||
func TestSummaryCountsCapacityByClass(t *testing.T) {
|
||||
// The question a per-node table answers badly at two hundred nodes: how
|
||||
// full am I.
|
||||
a, _ := setup(t, testModels(), gpuNode("n1", 8), gpuNode("n2", 8))
|
||||
s := a.Summary()
|
||||
|
||||
if s.Nodes.Total != 2 || s.Nodes.Ready != 2 {
|
||||
t.Errorf("nodes = %+v", s.Nodes)
|
||||
}
|
||||
if len(s.GPUs) != 1 {
|
||||
t.Fatalf("expected one GPU class, got %+v", s.GPUs)
|
||||
}
|
||||
if g := s.GPUs[0]; g.Total != 16 || g.Free() != 16 {
|
||||
t.Errorf("class totals wrong: %+v", g)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnhealthyGPUsAreNotCountedAsFree(t *testing.T) {
|
||||
// Counting them free is how a cluster looks like it has room it does not,
|
||||
// which is worse than showing less capacity than exists.
|
||||
n := gpuNode("n1", 4)
|
||||
n.GPUs[0].Health.Problems = []string{"3 uncorrected ECC errors"}
|
||||
a, _ := setup(t, testModels(), n)
|
||||
|
||||
g := a.Summary().GPUs[0]
|
||||
if g.Unhealthy != 1 {
|
||||
t.Errorf("unhealthy = %d", g.Unhealthy)
|
||||
}
|
||||
if g.Free() != 3 {
|
||||
t.Errorf("free = %d; a faulty card was counted as available", g.Free())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFabricFreeBlocksCountWholeNodesOnly(t *testing.T) {
|
||||
// A multi-node replica may never span fabrics, and a node with one card in
|
||||
// use cannot contribute a full-width shard. Free cards scattered across
|
||||
// partly-used nodes are not capacity for the model that needs them.
|
||||
free := gpuNode("free", 8, "ib-a")
|
||||
partial := gpuNode("partial", 8, "ib-a")
|
||||
a, ctl := setup(t, testModels(), free, partial)
|
||||
// Take one GPU on the second node.
|
||||
ctl.Inventory().Allocate("partial", inventory.Allocation{
|
||||
ShardID: "s", ReplicaID: "r", GPUIndices: []int{0},
|
||||
})
|
||||
|
||||
s := a.Summary()
|
||||
if len(s.Fabrics) != 1 {
|
||||
t.Fatalf("fabrics = %+v", s.Fabrics)
|
||||
}
|
||||
if got := s.Fabrics[0].LargestFreeBlock; got != 1 {
|
||||
t.Errorf("fully free nodes = %d, want 1: a partly used node is not one", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestANodeWithNoGPUsDoesNotInventAClass(t *testing.T) {
|
||||
// The CPU-only node this fleet acquired. It has no class, and a summary
|
||||
// that invents one for it would report capacity nobody has.
|
||||
a, _ := setup(t, testModels(), inventory.Node{ID: "cpu1", State: inventory.Ready})
|
||||
s := a.Summary()
|
||||
for _, g := range s.GPUs {
|
||||
if g.Class == "" {
|
||||
t.Errorf("an empty class was reported: %+v", g)
|
||||
}
|
||||
}
|
||||
if s.Nodes.Total != 1 {
|
||||
t.Errorf("the node was not counted: %+v", s.Nodes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIdleReplicasNeedRealIdleness(t *testing.T) {
|
||||
// A replica the router has said nothing about carries -1, and must not be
|
||||
// read as idle since the epoch — otherwise a router restart nominates the
|
||||
// whole fleet for eviction at once.
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
idle int64
|
||||
want bool
|
||||
}{
|
||||
{"never reported", -1, false},
|
||||
{"just used", 5, false},
|
||||
{"idle for an hour", int64(time.Hour.Seconds()), true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := tc.idle >= int64(idleThreshold.Seconds())
|
||||
if got != tc.want {
|
||||
t.Errorf("idle=%d counted as idle=%v, want %v", tc.idle, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummaryNamesModelsThatCannotBePlaced(t *testing.T) {
|
||||
// The line that turns "something is wrong" into a place to look.
|
||||
a, _ := setup(t, testModels()) // no nodes at all
|
||||
s := a.Summary()
|
||||
if len(s.Unplaceable) == 0 {
|
||||
t.Fatal("a model with no hardware to run on was not named")
|
||||
}
|
||||
if s.Models.Short == 0 {
|
||||
t.Error("no model was counted short")
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,21 @@ type EndpointSink interface {
|
||||
SetEndpoints(ctx context.Context, infos []endpoint.Info)
|
||||
}
|
||||
|
||||
// UsageSource reports when each endpoint was last sent a request.
|
||||
//
|
||||
// The return path of EndpointSink, and an interface for the same reason: the
|
||||
// control plane decides what should run, the router is the only thing that
|
||||
// knows whether anyone wants it, and neither should have to be in the same
|
||||
// process as the other to say so.
|
||||
//
|
||||
// Deliberately a snapshot rather than an event stream. On a fleet with hundreds
|
||||
// of replicas, per-request notification is a firehose carrying one bit of
|
||||
// information — the newest timestamp wins — and a map read once a tick carries
|
||||
// exactly the same answer for a fixed cost.
|
||||
type UsageSource interface {
|
||||
LastUsed() map[string]time.Time
|
||||
}
|
||||
|
||||
// Config tunes the control plane.
|
||||
type Config struct {
|
||||
Reconciler reconciler.Config
|
||||
@@ -44,12 +59,13 @@ func DefaultConfig() Config {
|
||||
|
||||
// Controller owns the control plane's state.
|
||||
type Controller struct {
|
||||
cfg Config
|
||||
log *slog.Logger
|
||||
inv *inventory.Store
|
||||
cat *catalog.Catalog
|
||||
rec *reconciler.Reconciler
|
||||
sink EndpointSink
|
||||
cfg Config
|
||||
log *slog.Logger
|
||||
inv *inventory.Store
|
||||
cat *catalog.Catalog
|
||||
rec *reconciler.Reconciler
|
||||
sink EndpointSink
|
||||
usage UsageSource
|
||||
|
||||
mu sync.Mutex
|
||||
last string // fingerprint of the last published list
|
||||
@@ -83,6 +99,25 @@ func New(cfg Config, cat *catalog.Catalog, disp reconciler.Dispatcher, sink Endp
|
||||
// Inventory exposes the node inventory, which the agent service feeds.
|
||||
func (c *Controller) Inventory() *inventory.Store { return c.inv }
|
||||
|
||||
// SetUsageSource supplies where request activity is read from.
|
||||
//
|
||||
// A setter rather than a constructor argument because a control plane without
|
||||
// one is fully functional — it simply cannot say whether a replica is idle,
|
||||
// which is how it behaved until now.
|
||||
func (c *Controller) SetUsageSource(u UsageSource) { c.usage = u }
|
||||
|
||||
// collectUsage stamps replicas with when they were last asked for anything.
|
||||
//
|
||||
// Once a tick, over the replicas rather than the requests. On a fleet of
|
||||
// hundreds this is a map lookup each; there is no version of it that grows with
|
||||
// traffic.
|
||||
func (c *Controller) collectUsage() {
|
||||
if c.usage == nil {
|
||||
return
|
||||
}
|
||||
c.rec.RecordUsage(c.usage.LastUsed())
|
||||
}
|
||||
|
||||
// Reconciler exposes the reconciliation loop, for status reports and ctl.
|
||||
func (c *Controller) Reconciler() *reconciler.Reconciler { return c.rec }
|
||||
|
||||
@@ -106,6 +141,9 @@ func (c *Controller) Start(ctx context.Context) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
// Before publishing, so a replica's idleness is as fresh as
|
||||
// the endpoint list it travels beside.
|
||||
c.collectUsage()
|
||||
c.Publish(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,6 +299,47 @@ func (r *Reconciler) fleetHasSettled() bool {
|
||||
return settled
|
||||
}
|
||||
|
||||
// RecordUsage stamps replicas with when each was last sent a request.
|
||||
//
|
||||
// Replicas absent from the map are left alone rather than zeroed: a router that
|
||||
// has just restarted knows nothing about what happened before it, and treating
|
||||
// that as "never used" would make every replica look abandoned at once —
|
||||
// exactly when a fleet is least able to afford acting on that.
|
||||
func (r *Reconciler) RecordUsage(lastUsed map[string]time.Time) {
|
||||
if len(lastUsed) == 0 {
|
||||
return
|
||||
}
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
for id, at := range lastUsed {
|
||||
rep, ok := r.replicas[id]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
// Only forwards. Two routers reporting, or a stale snapshot arriving
|
||||
// late, must not move a replica's last use backwards.
|
||||
if at.After(rep.LastUsedAt) {
|
||||
rep.LastUsedAt = at
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IdleFor reports how long a replica has gone without a request, and whether
|
||||
// that is known at all.
|
||||
//
|
||||
// The second return is not a detail. "Idle for an hour" and "nobody has told me
|
||||
// yet" are different states, and anything that acts on idleness — eviction,
|
||||
// most obviously — has to refuse to act on the second.
|
||||
func (r *Reconciler) IdleFor(id string) (time.Duration, bool) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
rep, ok := r.replicas[id]
|
||||
if !ok || rep.LastUsedAt.IsZero() {
|
||||
return 0, false
|
||||
}
|
||||
return r.now().Sub(rep.LastUsedAt), true
|
||||
}
|
||||
|
||||
// expireStuckReplicas fails replicas that never finished coming up.
|
||||
//
|
||||
// Every other path out of Starting depends on the agent reporting something. A
|
||||
|
||||
@@ -1153,3 +1153,79 @@ func TestSettlingOutlastsAnAgentReconnectBackoff(t *testing.T) {
|
||||
t.Fatal("placement never resumed")
|
||||
}
|
||||
}
|
||||
|
||||
// --- idle tracking ---
|
||||
|
||||
func TestUsageIsRecordedAgainstReplicas(t *testing.T) {
|
||||
h := newHarness(t, testModel(1), gpuNode("1", 8))
|
||||
h.r.Reconcile(t.Context())
|
||||
reps := h.r.Replicas()
|
||||
if len(reps) != 1 {
|
||||
t.Fatalf("expected a replica, got %d", len(reps))
|
||||
}
|
||||
id := reps[0].ID
|
||||
|
||||
if _, known := h.r.IdleFor(id); known {
|
||||
t.Error("a replica nothing has used reported a known idleness")
|
||||
}
|
||||
|
||||
used := h.clock.now()
|
||||
h.r.RecordUsage(map[string]time.Time{id: used})
|
||||
h.advance(5 * time.Minute)
|
||||
|
||||
idle, known := h.r.IdleFor(id)
|
||||
if !known {
|
||||
t.Fatal("usage was recorded but idleness is still unknown")
|
||||
}
|
||||
if idle != 5*time.Minute {
|
||||
t.Errorf("idle = %s, want 5m", idle)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUsageNeverMovesBackwards(t *testing.T) {
|
||||
// Two routers reporting, or a snapshot arriving late, must not make a busy
|
||||
// replica look abandoned.
|
||||
h := newHarness(t, testModel(1), gpuNode("1", 8))
|
||||
h.r.Reconcile(t.Context())
|
||||
id := h.r.Replicas()[0].ID
|
||||
|
||||
recent := h.clock.now()
|
||||
h.r.RecordUsage(map[string]time.Time{id: recent})
|
||||
h.r.RecordUsage(map[string]time.Time{id: recent.Add(-time.Hour)})
|
||||
|
||||
h.advance(time.Minute)
|
||||
if idle, _ := h.r.IdleFor(id); idle != time.Minute {
|
||||
t.Errorf("idle = %s; a stale report moved last-use backwards", idle)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUsageForReplicasWeDoNotHaveIsIgnored(t *testing.T) {
|
||||
// The router's list and the reconciler's drift constantly on a live fleet:
|
||||
// a replica stops between the snapshot and the read. That is ordinary, not
|
||||
// an error, and must not panic or create phantom state.
|
||||
h := newHarness(t, testModel(1), gpuNode("1", 8))
|
||||
h.r.Reconcile(t.Context())
|
||||
before := len(h.r.Replicas())
|
||||
|
||||
h.r.RecordUsage(map[string]time.Time{"a-replica-that-left": h.clock.now()})
|
||||
if got := len(h.r.Replicas()); got != before {
|
||||
t.Errorf("replica count changed from %d to %d", before, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnEmptyUsageReportLeavesEverythingAlone(t *testing.T) {
|
||||
// A router that has just started knows nothing, and treating that as "never
|
||||
// used" would make every replica look abandoned at once — exactly when a
|
||||
// fleet is least able to afford acting on it.
|
||||
h := newHarness(t, testModel(1), gpuNode("1", 8))
|
||||
h.r.Reconcile(t.Context())
|
||||
id := h.r.Replicas()[0].ID
|
||||
|
||||
h.r.RecordUsage(map[string]time.Time{id: h.clock.now()})
|
||||
h.advance(time.Minute)
|
||||
h.r.RecordUsage(nil)
|
||||
|
||||
if idle, known := h.r.IdleFor(id); !known || idle != time.Minute {
|
||||
t.Errorf("idle=%s known=%v; an empty report erased what was known", idle, known)
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,14 @@ type Replica struct {
|
||||
|
||||
CreatedAt time.Time
|
||||
ReadyAt time.Time
|
||||
// LastUsedAt is when a request was last routed to this replica, zero if
|
||||
// none has been since the router started.
|
||||
//
|
||||
// The difference between a replica that is holding eight cards for work and
|
||||
// one that is holding them out of habit. Nothing recorded it, so on a fleet
|
||||
// with more models than GPUs there was no way to answer the first question
|
||||
// anyone asks: what can I stop?
|
||||
LastUsedAt time.Time
|
||||
// DrainingAt is when the replica stopped taking new work, so the wait for a
|
||||
// replacement can be bounded.
|
||||
DrainingAt time.Time
|
||||
|
||||
Reference in new issue
Block a user