{
  "id": "enwiki-001368753991",
  "slug": "load-computing",
  "title": "Load (computing)",
  "qid": "",
  "lead": "displaying a significant computing load (top right: Load average:) In UNIX computing, the system load is a measure of the amount of computational work that a computer system performs. The load average represents the average system load over a period of time. It conventionally appears in the form of three numbers which represent the system load during the last one-, five-, and fifteen-minute periods.",
  "body": "displaying a significant computing load (top right: Load average:) In UNIX computing, the system load is a measure of the amount of computational work that a computer system performs. The load average represents the average system load over a period of time. It conventionally appears in the form of three numbers which represent the system load during the last one-, five-, and fifteen-minute periods. $ uptime 14:34:03 up 10:43, 4 users, load average: 0.06, 0.11, 0.09 The w and top commands show the same three load average numbers, as do a range of graphical user interface utilities. The underlying interface is , a C function present on most UNIX systems since 4.3BSD-Reno of 1990 (but is not part of POSIX). On Linux specifically, one can also read /proc/loadavg for this information. This file also provides instantaneous information on the number of processes in \"R\" state, the total number of processes, and the process ID of the most-recently-created process. Systems calculate the load average as the exponentially damped/weighted moving average of the load number. The three values of load average refer to the past one, five, and fifteen minutes of system operation. Mathematically speaking, all three values always average all the system load since the system started up. They all decay exponentially, but they decay at different speeds: they decay exponentially by e after 1, 5, and 15 minutes respectively. Hence, the 1-minute load average consists of 63% (more precisely: 1 − 1/e) of the load from the last minute and 37% (1/e) of the average load since start up, excluding the last minute. For the 5- and 15-minute load averages, the same 63%/37% ratio is computed over 5 minutes and 15 minutes, respectively. Therefore, it is not technically accurate that the 1-minute load average only includes the last 60 seconds of activity, as it includes 37% of the activity from the past, but it is correct to state that it includes mostly the last minute. extern unsigned long avenrun[]; /* Load averages */ extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift); define FSHIFT 11 /* nr of bits of precision */ define FIXED_1 (1 = load) newload += FIXED_1-1; return newload / FIXED_1; } extern unsigned long calc_load_n(unsigned long load, unsigned long exp, unsigned long active, unsigned int n); define LOAD_INT(x) ((x) >> FSHIFT) define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) The avenrun array contains 1-minute, 5-minute and 15-minute average. The function provides the correct update of the load-average for the default update rate of . It is used like such in loadavg.c (formerly sched.c): void calc_global_load(void) { unsigned long sample_window; long active, delta; sample_window = READ_ONCE(calc_load_update); if (time_before(jiffies, sample_window + 10)) return; /* * Fold the 'old' NO_HZ-delta to include all NO_HZ CPUs. */ delta = calc_load_nohz_read(); if (delta) atomic_long_add(delta, &calc_load_tasks); active = atomic_long_read(&calc_load_tasks); active = active > 0 ? active * FIXED_1 : 0; avenrun[0] = calc_load(avenrun[0], EXP_1, active); avenrun[1] = calc_load(avenrun[1], EXP_5, active); avenrun[2] = calc_load(avenrun[2], EXP_15, active); WRITE_ONCE(calc_load_update, sample_window + LOAD_FREQ); /* * In case we went to NO_HZ for multiple LOAD_FREQ intervals * catch up in bulk. */ calc_global_nohz(); } Note this handling of NO_HZ CPUs. NO_HZ is a mode meant to reduce the number of scheduling-clock interrupts on idle processors, which improves power efficiency and reduces clock jitter. This would cause processors to miss their update ticks, however. As a result, the counting of tasks is done using atomic operations. The function handles the calculation in case of needing to catch up to multiple ticks, making use of this function: /* [1] application of the geometric series: * n 1 - x^(n+1) * S_n := \\Sum x^i = ------------- * i=0 1 - x */ unsigned long calc_load_n(unsigned long load, unsigned long exp, unsigned long active, unsigned int n) { return calc_load(load, fixed_power_int(exp, FSHIFT, n), active); } Here (not included in article) raises exp to its nth power in fixed-point arithmetic. define LOAD_FREQ (60*HZ/13) /* 60/13 ~ 4.61 sec intervals */ define EXP_1 1896 /* 1/exp(4.61sec/1min) = 1/exp(1/13) as fixed-point */ define EXP_5 2017 /* 1/exp(4.61sec/5min) = 1/exp(1/13/5) */ define EXP_15 2038 /* 1/exp(4.61sec/15min) = 1/exp(1/13/15) */ !/usr/bin/env python3 import time import os from datetime import datetime from math import exp, log from dataclasses import dataclass LOGSYSPERIODS = [log(x) for x in [60, 300, 900 REFRESH_RATE = ((5**0.5) + 1) / 2 # Ripke's golden ratio PERIODS = [10, 30, 60, 120, 300, 900, 1800, 3600] COUNT_DISKWAIT = True # Whether to include disk wait in load calculation @dataclass class LoadEntry: avg: float exp: float def initialize_loads(now: int | float, lavgs: dict[int, LoadEntry]): \"\"\"Initialize load averages based on linear interpolation of system load averages and instant load count.\"\"\" sys = getloadavg() slopes = ((sys[0] - now) / 60, (sys[1] - sys[0]) / 240, (sys[2] - sys[1]) / 600) for period in [10, 30, 60, 120, 300, 900, 1800, 3600]: exp_factor = exp(-REFRESH_RATE / period) if period None: for _, entry in lavgs.items(): entry.avg = entry.avg * entry.exp + current_load * (1 - entry.exp) if os.name == \"posix\": uname = os.uname()[0].lower() getloadavg = os.getloadavg if uname == \"linux\": def get_current_load() -> int: load = 0 with open(\"/proc/stat\", \"r\") as f: for line in f: if line.startswith(\"procs_running \"): load += int(line.split()[1]) # Read procs_running load -= 1 # Subtract one for ourself elif line.startswith(\"procs_blocked \") and COUNT_DISKWAIT: load += int(line.split()[1]) # Read procs_blocked return load else: PS_THREAD_OPTION = \"-H\" if os.uname()[0].lower().endswith(\"bsd\") else \"-M\" PS_DISK_WAIT = \"U\" if os.uname()[0] == \"Darwin\" else \"D\" PS_STATES = (\"R\" + PS_DISK_WAIT) if COUNT_DISKWAIT else \"R\" def get_current_load() -> int: with os.popen(f\"ps {PS_THREAD_OPTION}ax -o stat\", \"r\") as f: states = map(f, lambda line: line.split()[-1]) # Get the last column. Required on macOS! return sum(1 if state[0] in PS_STATES else 0 for state in states) - 1 elif os.name == \"nt\": # It is possible to use Windows performance counters to get a queue length. # In fact, Microsoft recommends it as an additional metric for load in addition to CPU usage: # https://learn.microsoft.com/en-us/biztalk/technical-guides/using-the-performance-analysis-of-logs-pal-tool#processor-queue-length-analysis # Using it we can also obtain a load similar to Unix systems. from pyperfmon import pyperfmon pm = pyperfmon.pyperfmon() ncores = os.cpu_count() get_counter = lambda x: pm.getCounter(x) def get_current_load() -> float: return ( # Threads waiting for CPU, not running ones get_counter(r\"System\\Processor Queue Length\") # Approximate number of threads using CPU + get_counter(r\"Processor\\_Total\\% Processor Time\") * ncores # Threads waiting for disk I/O + get_counter(r\"PhysicalDisk\\_Total\\Current Disk Queue Length\") if COUNT_DISKWAIT else 0 ) def getloadavg() -> tuple[float, float, float]: # Dummy implementation for Windows load = get_current_load() return (load, load, load) def main(): lavgs: dict[int, LoadEntry] = {} current_load = get_current_load() initialize_loads(current_load, lavgs) heading = [\"SYSTIME\", \" CURR\"] + [str(x) for x in PERIODS] print(\"\\t\".join(heading)) while True: # Always print before recalculating entries = [f\"{datetime.now().strftime('%H:%M:%S')} {current_load:.4f}\"] entries += [f\"{entry.avg:.4f}\" for entry in lavgs.values()] print(\"\\t\".join(entries), flush=True) # Sleep and wait. This assumes that the time used to update a new line is # minuscule compared to the time slept. If this is not the case, a # sleepuntil()-type reckoning should be used. time.sleep(REFRESH_RATE) # Print current_load = get_current_load() update_loads(lavgs, current_load) if __name__ == \"__main__\": main() ==Notes==",
  "categories": [
    "22918986",
    "23000992",
    "23118434",
    "23603337",
    "23837581",
    "24043274",
    "26868916"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1368753991",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1786394574.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001368753991",
    "type": "webpage",
    "title": "Load (computing)",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/load-computing",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          18
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          18
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001368753991",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1368753991",
    "note": "Immutable snapshot enwiki-001368753991"
  }
}