Spend a contention budget against a fixed capacity and turn the granted and denied counts into a spend, drain, or throttle remediation action.

budget capacity The contention capacity and budget are scalars, so the granted and denied counts that drive the remediation action stay deterministic and free of atomic identity.

Atomic Budget Remediation Report

requests
atomic_budget_remediation_report.cpp
Replay: real traced execution (multi-file project)
#include <iostream>
#include <string>

int main() {
    int requests = 1;
    const int capacity = 2;
    int granted = 0;
    int denied = 0;

    for (int i = 0; i < requests; ++i) {
        if (granted < capacity) {
            granted += 1;
        } else {
            denied += 1;
        }
    }
    int spare = capacity - granted;

    std::string action;
    if (denied > 0) {
        action = "throttle";
    } else if (spare == 0) {
        action = "drain";
    } else {
        action = "spend";
    }

    std::cout << "requests=" << requests
              << " granted=" << granted
              << " denied=" << denied
              << " " << action << std::endl;
    return 0;
}
#include <iostream>
#include <string>

int main() {
    int requests = 2;
    const int capacity = 2;
    int granted = 0;
    int denied = 0;

    for (int i = 0; i < requests; ++i) {
        if (granted < capacity) {
            granted += 1;
        } else {
            denied += 1;
        }
    }
    int spare = capacity - granted;

    std::string action;
    if (denied > 0) {
        action = "throttle";
    } else if (spare == 0) {
        action = "drain";
    } else {
        action = "spend";
    }

    std::cout << "requests=" << requests
              << " granted=" << granted
              << " denied=" << denied
              << " " << action << std::endl;
    return 0;
}
#include <iostream>
#include <string>

int main() {
    int requests = 4;
    const int capacity = 2;
    int granted = 0;
    int denied = 0;

    for (int i = 0; i < requests; ++i) {
        if (granted < capacity) {
            granted += 1;
        } else {
            denied += 1;
        }
    }
    int spare = capacity - granted;

    std::string action;
    if (denied > 0) {
        action = "throttle";
    } else if (spare == 0) {
        action = "drain";
    } else {
        action = "spend";
    }

    std::cout << "requests=" << requests
              << " granted=" << granted
              << " denied=" << denied
              << " " << action << std::endl;
    return 0;
}
  1. requests ← 1, capacity ← 2, granted ← 0, denied ← 0

    4int main() {5    int requests→ 1 = 1; //@requests=2, 46    const int capacity→ 2 = 2;7    int granted→ 0 = 0;8    int denied→ 0 = 0;
  2. for (int i = 0; i < requests; ++i)

    10for (int i0 = 0; i < requests1; ++i) {11    if (granted < capacity) {
  3. granted ← 1

    10for (int i = 0; i < requests; ++i) {11    if (granted0 < capacity2) {12        granted→ 1 += 1;13    } else {
  4. spare ← 1, action ← (empty)

    16}17int spare→ 1 = capacity2 - granted1;1819std::string action→ (empty);20if (denied > 0) {
  5. action ← spend

    23    action = "drain";24} else {25    action→ spend = "spend";26}
  6. std::cout << "requests=" << requests

    28    std::cout << "requests=" << requests129              << " granted=" << granted130              << " denied=" << denied031              << " " << actionspend << std::endl;32    return 0;33}
    outputrequests=1 granted=1 denied=0 spend
  1. requests ← 2, capacity ← 2, granted ← 0, denied ← 0

    4int main() {5    int requests→ 2 = 2;6    const int capacity→ 2 = 2;7    int granted→ 0 = 0;8    int denied→ 0 = 0;
  2. for (int i = 0; i < requests; ++i)

    pass 1 of 2
    10for (int i0 = 0; i < requests2; ++i) {11    if (granted < capacity) {
  3. granted ← 1

    pass 1 of 2
    10for (int i = 0; i < requests; ++i) {11    if (granted0 < capacity2) {12        granted→ 1 += 1;13    } else {
  4. for (int i = 0; i < requests; ++i)

    pass 2 of 2
    10for (int i1 = 0; i < requests2; ++i) {11    if (granted < capacity) {
  5. granted ← 2

    pass 2 of 2
    10for (int i = 0; i < requests; ++i) {11    if (granted1 < capacity2) {12        granted→ 2 += 1;13    } else {
  6. spare ← 0, action ← (empty)

    16}17int spare→ 0 = capacity2 - granted2;1819std::string action→ (empty);20if (denied > 0) {
  7. action ← drain

    21    action = "throttle";22} else if (spare0 == 0) {23    action→ drain = "drain";24} else {
  8. std::cout << "requests=" << requests

    28    std::cout << "requests=" << requests229              << " granted=" << granted230              << " denied=" << denied031              << " " << actiondrain << std::endl;32    return 0;33}
    outputrequests=2 granted=2 denied=0 drain
  1. requests ← 4, capacity ← 2, granted ← 0, denied ← 0

    4int main() {5    int requests→ 4 = 4;6    const int capacity→ 2 = 2;7    int granted→ 0 = 0;8    int denied→ 0 = 0;
  2. for (int i = 0; i < requests; ++i)

    pass 1 of 4
    10for (int i0 = 0; i < requests4; ++i) {11    if (granted < capacity) {
    All 4 passes — pass 1 is the card above
    passicapacitygranteddenied
    1020 1
    2121 2
    320 1
    431 2
  3. granted ← 1

    pass 1 of 2
    10for (int i = 0; i < requests; ++i) {11    if (granted0 < capacity2) {12        granted→ 1 += 1;13    } else {
  4. granted ← 2

    pass 2 of 2
    10for (int i = 0; i < requests; ++i) {11    if (granted1 < capacity2) {12        granted→ 2 += 1;13    } else {
  5. denied ← 1

    pass 1 of 2
    12    granted += 1;13} else {14    denied→ 1 += 1;15}
  6. denied ← 2

    pass 2 of 2
    12    granted += 1;13} else {14    denied→ 2 += 1;15}
  7. spare ← 0, action ← (empty)

    16}17int spare→ 0 = capacity2 - granted2;1819std::string action→ (empty);20if (denied > 0) {
  8. action ← throttle

    19std::string action;20if (denied2 > 0) {21    action→ throttle = "throttle";22} else if (spare == 0) {
  9. std::cout << "requests=" << requests

    28    std::cout << "requests=" << requests429              << " granted=" << granted230              << " denied=" << denied231              << " " << actionthrottle << std::endl;32    return 0;33}
    outputrequests=4 granted=2 denied=2 throttle