Container-aware GOMAXPROCS

컨테이너 CPU 인식 병렬도

Match Go’s default runtime parallelism to the container CPU limit.

···
html
<div class="v"><header><b>CONTAINER CPU LIMIT</b><span id="state"></span></header><main><div class="cores" id="cores"></div><div class="limit" id="limit"></div></main><footer>default follows container limit</footer></div>
css
.v{width:min(92vw,660px);height:min(86vh,310px);box-sizing:border-box;padding:clamp(9px,2.5vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);display:flex;flex-direction:column;gap:7px;color:var(--fg);font:500 clamp(15px,3.2vmin,17px)/1.25 var(--font-sans, sans-serif)}.v header,.v footer{display:flex;justify-content:space-between;align-items:center;gap:8px;white-space:nowrap}.v header b{color:var(--accent);font-size:.9em}.v header span,.v footer{color:var(--muted);font-size:.82em}.v main{flex:1;min-height:0;position:relative;overflow:hidden}.v .mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.v .active{background:var(--accent)!important;color:var(--bg)!important;border-color:var(--accent)!important}.v .muted{opacity:.28} .cores{height:62%;display:grid;grid-template-columns:repeat(4,1fr);grid-template-rows:repeat(2,minmax(0,1fr));gap:5px}.core{min-height:0;border:1px solid var(--line);border-radius:5px;display:grid;place-items:center;font:600 .8em ui-monospace,monospace}.limit{margin-top:8px;text-align:center;color:var(--accent);font:600 .85em ui-monospace,monospace}
js
let n=0;function draw(){const cap=n?2:4;document.getElementById("cores").innerHTML=Array.from({length:8},(_,i)=>"<div class=\"core "+(i<cap?"active":"muted")+"\">P"+(i+1)+"</div>").join("");document.getElementById("limit").textContent="GOMAXPROCS "+cap+" · host 8";document.getElementById("state").textContent="quota "+cap;n=1-n}draw();setInterval(draw,1400)

Since Go 1.25, the default GOMAXPROCS considers a container CPU limit when it is lower than the host core count. The runtime can periodically adapt when that limit changes.

GOMAXPROCS limits parallel Go execution while a CPU quota limits usage over time, so the two are not identical. Explicit environment or API settings override the default behavior.

When to use

Use it when diagnosing container CPU quotas and goroutine parallelism.

Open as page ↗