liveBook · Manning

Marginal cost

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

Marginal cost is the increase in a machine's aggregate resource cost that would result from assigning an additional task to it.

Marginal cost measures how much a machine’s aggregate resource cost increases when a scheduler adds one task. CPU and memory usage become one comparable cost, allowing assignment to the machine with the lowest increase. section 10.8.1

Apply the concept through a small scheduling pipeline:

  • Filter nodes that have enough available disk for the task. section 10.8.2
  • Measure CPU usage from node statistics and convert usage into load. section 10.8.2

A practical scoring loop

A Go-style scheduler keeps a score map and evaluates each node using current CPU usage, CPU load, allocated memory, projected memory percentage, and task count. The implementation uses maxJobs = 4.0 as an initial task-capacity estimate; production deployments should tune that value from observed metrics. section 10.8.2

Listing 10.17 Pseudocode describing the algorithm used in the E-PVM scheduling method
max_jobs = 1;
 
while () {
    machine_pick = 1; cost = MAX_COST
    repeat {} until (new job j arrives)
    for (each machine m) {
        marginal_cost = power(n, percentage memory utilization on
         m if j was added) +
        power(n, (jobs on m + 1/max_jobs) - power(n, memory use on m)
         - power(n, jobs on m/max_jobs));
 
        if (marginal_cost < cost) { machine_pick = m; }
    }
 
    assign job to machine_pick;
    if (jobs on machine_pick > max_jobs) max_jobs = max_jobs * 2;
}

Inspect the E-PVM pseudocode for the complete decision shape: initialize the cost limit, calculate each machine’s marginal cost, retain the lowest-cost machine, assign the job, and update maxJobs. section 10.8.1

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

How deep it goes
Explains the cost model and implements scoring, metric collection, candidate filtering, and minimum-score selection.
Examples
Demonstrates E-PVM pseudocode and Go scheduler methods for scoring, disk filtering, statistics retrieval, CPU calculation, and node selection.
What it assumes
Assumes task, node, CPU, memory, disk, and scheduler interfaces, while deriving CPU usage from fetched node statistics.
What you can do after
Build it from scratch by filtering feasible nodes, calculating resource scores, and picking the node with the lowest marginal cost.
How it connects
Connects marginal cost with job scheduling, CPU usage, memory utilization, node statistics, and load.

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.