liveBook · Manning

Score method

As explained in Build and Orchestrator in Go (From Scratch)

Score is a scheduler-interface method that assigns a numeric placement score to each candidate node for a task.

The Score method turns a set of viable worker nodes into a decision-ready map of numeric scores. It accepts a task and candidate nodes, then returns map[string]float64 values keyed by node name. Scoring is the middle phase of scheduling: filter nodes first, score them next, and let Pick choose the best result. section 10.3

Listing 10.1 The updated Scheduler interface
type Scheduler interface {
   SelectCandidateNodes(t task.Task, nodes []*node.Node) []*node.Node
   Score(t task.Task, nodes []*node.Node) map[string]float64
   Pick(scores map[string]float64, candidates []*node.Node) *node.Node
}

The interface makes responsibilities explicit: SelectCandidateNodes narrows the pool, Score evaluates it, and Pick converts scores into one selected node. section 10.3

A score has no universal meaning. Each scheduler defines what “best” means and how Pick interprets the values. In the round-robin implementation, lower scores win: the next worker receives 0.1 and all other workers receive 1.0. Score also updates LastWorker so successive tasks advance through the node list and wrap back to the start. section 10.4

Round-robin scoring

With node1, node2, and node3 as candidates, a scheduler whose next worker is node2 can return {"node1": 1.0, "node2": 0.1, "node3": 1.0}. Pick scans the candidates and returns node2 because 0.1 is the lowest score. section 10.4

The manager consumes Score through the Scheduler interface rather than embedding an algorithm. After candidate selection succeeds, it passes the task and candidates to Score, sends the resulting map to Pick, and receives a node to run the task. This keeps task-specific placement logic replaceable. section 10.5.2

More sophisticated scoring can estimate the marginal cost of placing a task on each candidate. The E-PVM implementation filters by available disk, gathers node statistics, calculates CPU load and memory-related values, and records a score for each node. Its maximum-jobs setting is a configurable assumption that production deployments should tune from observed metrics. section 10.8.2

How Build and Orchestrator in Go (From Scratch) covers it

How deep it goes
Builds round-robin scoring step by step, then introduces E-PVM marginal-cost scoring with CPU and memory helpers.
Examples
Uses a three-node round-robin score map and an E-PVM implementation that filters disk-constrained nodes.
What it assumes
Assumes familiarity with tasks, nodes, maps, and interfaces while defining the scheduling phases explicitly.
What you can do after
Build it from scratch as a Scheduler implementation that returns per-node scores consumed by Pick.
How it connects
Connects Scheduler, SelectCandidateNodes, Pick, round-robin scheduling, E-PVM, CPU usage, and resource requirements.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build and Orchestrator in Go (From Scratch). The section links point to the parts of the book it draws on.