컨테이너 CPU 인식 병렬도

Container-aware GOMAXPROCS

Go 런타임의 기본 병렬도를 컨테이너 CPU 한도에 맞춥니다.

···
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)

Go 1.25부터 GOMAXPROCS의 기본값은 컨테이너 CPU 한도가 머신 코어 수보다 작으면 그 한도를 고려합니다. CPU 한도가 바뀌면 기본값을 주기적으로 조정할 수도 있습니다.

GOMAXPROCS는 동시에 실행할 Go 코드의 병렬도이고 CPU 한도는 일정 기간의 사용량 한도라 개념이 같지는 않습니다. 환경변수나 API로 명시 설정한 경우에는 기본 자동 조정이 적용되지 않습니다.

언제 쓰나

컨테이너에서 CPU 제한과 고루틴 실행 병렬도의 차이를 진단할 때 씁니다.

페이지로 열기 ↗