[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
@@ -2,102 +2,134 @@
id: wiki-2026-0508-stop-the-world
title: Stop the world
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [P-Reinforce-AUTO-D2D9B2]
aliases: [P-Reinforce-AUTO-D2D9B2, STW, GC pause, Stop-the-world]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
tags: [auto-reinforced]
confidence_score: 0.95
verification_status: applied
tags: [gc, runtime, performance, latency, jvm, v8]
raw_sources: []
last_reinforced: 2026-04-20
github_commit: "[P-Reinforce] Continuous Worker - Stop-the-world"
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: unspecified
framework: unspecified
language: Java / JS / Go
framework: HotSpot / V8 / Go runtime
---
# [[Stop-the-world|Stop-the-world]]
# Stop the world
## 📌 한 줄 통찰 (The Karpathy Summary)
> 'Stop-the-world'(STW)는 가비지 컬렉션(GC)이 실행되는 동안 메모리를 정리하기 위해 애플리케이션의 실행이 일시적으로 완전히 중단되는 현상을 의미합니다 [1, 2]. 가비지 컬렉터가 힙(Heap) 메모리에 대한 배타적 접근 권한을 얻어야 하므로 애플리케이션 스레드가 멈추게 됩니다 [1, 3]. 이로 인해 발생하는 지연(Latency)과 화면 끊김(Jank)을 줄이기 위해 현대의 GC 알고리즘들은 STW 시간을 최소화하거나 회피하는 병렬 및 동시 처리 방식으로 발전하고 있습니다 [2, 4, 5].
## 한 줄
> **"매 GC + 매 mutator 의 동시 실행 매 X — 매 모든 application thread 의 freeze, 매 GC 의 reclaim 의 후 의 resume"**. 1960s LISP MTS GC 매 origin → 1990s incremental → 2010s concurrent → 2026 매 ZGC / Shenandoah / Go 1.5+ 의 sub-millisecond STW. 매 STW 매 매 latency 의 archenemy.
## 📖 구조화된 지식 (Synthesized Content)
* **원인 및 메커니즘**
가비지 컬렉터가 더 이상 사용되지 않는 객체를 정리하고 메모리를 재사용하기 위해서는 힙 영역에 배타적으로 접근해야 하며, 이 과정에서 애플리케이션은 처리 작업이 완료될 때까지 정지(halt)해야 합니다 [1]. V8 엔진의 경우, 자바스크립트 실행을 멈추고 메인 스레드에서 순차적으로 GC 작업을 수행하는 것이 가장 직관적인 STW 방식입니다 [2, 6].
## 매 핵심
* **성능에 미치는 영향**
STW 중단 시간이 길어지면 애플리케이션의 성능 저하를 초래합니다. 특히 메인 스레드에 지연과 화면 끊김(Jank) 현상을 유발하여 사용자 경험을 떨어뜨리고 전체 프로그램의 처리량(Throughput)을 감소시킵니다 [2]. GC 로그에서 긴 'Duration' 값은 긴 STW 중단을 나타냅니다 [7]. V8에서 병렬(Parallel) 기법을 사용하더라도 이는 본질적으로 'stop-the-world' 방식이며 자바스크립트 실행이 멈추게 되지만, 총 중단 시간을 스레드 수로 나누어 줄일 수 있습니다 [8].
### 매 왜 STW 의 필요
- **Heap traversal consistency**: 매 mark phase 매 reference graph 의 stable 의 require — 매 mutator 매 concurrent write 의 invariant break.
- **Root scanning**: 매 thread stack + 매 register 의 snapshot 의 atomic 매 collect.
- **Pointer update**: 매 compacting GC 매 매 reference 의 rewrite 의 atomic 매 require.
* **주요 발생 시점**
* 스위프(Sweep) 작업이나 마크(Mark) 단계가 배타적 접근 권한을 가지고 실행될 때 STW 중단이 발생합니다 [3, 9].
* IBM JVM의 'gencon' 정책에서는 'nursery' 영역을 정리하는 스캐빈지([[Scavenge|Scavenge]]) 작업이나 글로벌 사이클의 초기 및 최종 마크 단계가 짧은 STW 중단 동안 실행됩니다 [10].
* 동시 마크(Concurrent mark) 작업을 사용하더라도 메모리가 고갈되어 스위프 작업이 시작될 때나, 루트 객체를 다시 스캔할 때는 STW 중단이 필요합니다 [9].
### 매 STW phase
- **Initial mark** (root scan) — 매 short.
- **Final mark / remark** — 매 mutator 의 missed reference 의 catch-up.
- **Reference processing** (weak/soft refs).
- **Cleanup / class unloading**.
* **STW 완화 및 회피 기법**
* **점진적 및 동시 처리:** 점진적 동시 마크(Incremental concurrent mark [[Processing|Processing]]) 처리는 글로벌 STW 가비지 컬렉션을 피함으로써 중단 시간을 고르게 분산시킵니다 [4].
* **[[Orinoco|Orinoco]] 가비지 컬렉터:** V8 엔진의 최신 가비지 컬렉터인 Orinoco는 기존의 'stop-the-world' 휴식 모델에서 벗어나, 메인 스레드의 부하를 줄이기 위해 병렬(Parallel), 점진적(Incremental), 동시(Concurrent) 스위핑 및 마킹 기술을 도입했습니다 [5, 11].
### 매 modern GC 의 STW
- **HotSpot G1**: ~10-200ms (heap size 의 dependent).
- **HotSpot ZGC** (JDK 21+): < 1ms 매 always (concurrent compaction).
- **HotSpot Shenandoah**: < 10ms (Brooks pointers).
- **Go runtime**: < 0.5ms (concurrent + tri-color + write barrier).
- **V8 Orinoco**: < 1ms typical (parallel + concurrent + incremental).
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
- **정책 변화:** Programming & Language 분야의 자동 자산화 수행.
### 매 응용
1. SLO design (p99 latency budget).
2. JVM tuning (heap + GC choice).
3. Real-time / financial / game 의 latency-critical app.
## 🔗 지식 연결 (Graph)
- **Related Topics:** [[Garbage Collection|Garbage Collection]], Heap memory, Orinoco, [[Mark-Sweep|Mark-Sweep]]
- **Projects/Contexts:** [[V8 JavaScript Engine|V8 JavaScript Engine]], IBM Java Virtual Machine (VM)
- **Contradictions/Notes:** 제공된 소스들 사이에서 내용 상의 모순은 없으며, V8 엔진과 IBM JVM 환경 모두에서 가비지 컬렉션 중 발생하는 'Stop-the-world'의 기본 개념과 이를 최적화(병렬, 동시, 점진적 처리)하여 일시 정지 시간을 줄이려는 공통된 발전 방향을 보여줍니다 [3-5, 8].
## 💻 패턴
---
*Last updated: 2026-04-19*
---
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
**언제 이 지식을 쓰는가:**
- *(TODO)*
**언제 쓰면 안 되는가:**
- *(TODO)*
## 🧪 검증 상태 (Validation)
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
## 🧬 중복 검사 (Duplicate Check)
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
## 🕓 변경 이력 (Changelog)
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
## 💻 코드 패턴 (Code Patterns)
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
```text
# TODO
### Pattern 1: 매 JVM 의 STW 의 measure (GC log)
```bash
# Java 21+
java -Xlog:gc*:file=gc.log:time,uptime,level,tags -Xmx4g -XX:+UseZGC App
# 매 log 의 분석
grep 'Pause' gc.log | awk '{print $NF}' | sort -n | tail
```
## 🤔 의사결정 기준 (Decision Criteria)
### Pattern 2: 매 V8 의 GC pause 의 trace (Node.js)
```bash
node --trace-gc --trace-gc-verbose app.js
# [12345:0x..] 1234 ms: Mark-sweep 64.5 (98.4) -> 32.1 (98.4) MB, 12.3 / 0.0 ms
```
**선택 A를 써야 할 때:**
- *(TODO)*
### Pattern 3: 매 Go 의 GODEBUG 의 STW trace
```bash
GODEBUG=gctrace=1 ./myapp
# gc 1 @0.012s 0%: 0.012+0.36+0.005 ms clock, ...
# ^^^^^ ^^^^^^^^ ^^^^^
# STW init concurrent STW final
```
**선택 B를 써야 할 때:**
- *(TODO)*
### Pattern 4: 매 STW-aware code (allocation 의 reduce)
```ts
// V8 매 large allocation 매 LO space → mark-sweep 의 trigger
// Hot path 매 매 allocation 의 minimize
const buf = Buffer.allocUnsafe(1024); // reuse
function process(data: Uint8Array): number {
let sum = 0;
for (let i = 0; i < data.length; i++) sum += data[i]; // 매 no allocation
return sum;
}
```
**기본값:**
> *(TODO)*
### Pattern 5: 매 production GC tuning (JVM)
```bash
# 매 SLO p99 < 50ms 매 latency-critical service
java -Xmx8g -Xms8g \
-XX:+UseZGC -XX:+ZGenerational \
-XX:+UnlockExperimentalVMOptions \
-XX:SoftMaxHeapSize=6g \
-Xlog:gc*:file=gc.log \
-jar app.jar
```
## ❌ 안티패턴 (Anti-Patterns)
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Java batch / throughput | Parallel GC (longer STW OK) |
| Java latency-critical (p99 < 50ms) | ZGC (JDK 21+) or Shenandoah |
| Java legacy heap < 4G | G1 (default JDK 17+) |
| Go service | runtime default — tune `GOGC` |
| Node.js 매 long-lived process | `--max-old-space-size`, profile incremental marking |
| 매 Hard real-time (audio, robotics) | manual memory mgmt — 매 GC 의 X (Rust, C++) |
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
**기본값**: 매 latency app — 매 ZGC (Java) / 매 default Go runtime / 매 V8 incremental.
## 🔗 Graph
- 부모: [[V8 가비지 컬렉션(Garbage Collection)]] · [[가비지 컬렉터(Garbage Collector)]]
- 변형: [[Mark-Sweep-Compact(메이저 GC)]] · [[Major GC]] · [[Scavenge]]
- 응용: [[V8 Engine]] · [[자바 가상 머신(JVM)]] · [[동시성 및 점진적 마킹(Concurrent Incremental Marking)]]
- Adjacent: [[Memory Management]] · [[오리노코(Orinoco GC)]] · [[Cheneys Algorithm]]
## 🤖 LLM 활용
**언제**: 매 GC log 의 parse + summarize, 매 STW outlier 의 root-cause hypothesis, 매 GC flag 의 trade-off 분석.
**언제 X**: 매 production GC flag 의 LLM-only 의 decision — 매 load test 의 confirm 의 필요.
## ❌ 안티패턴
- **매 GC 의 manual trigger** (`System.gc()`, `--expose-gc`) 매 production — 매 STW 의 force, 매 worse latency.
- **매 huge heap** (-Xmx32g) + 매 G1 의 expectation 의 STW < 10ms — 매 G1 의 multi-GB heap 매 longer pause 의 inevitable, 매 ZGC 의 use.
- **매 short-lived object 의 fixed pool 의 cache** — 매 generational GC 의 already 의 efficient. 매 over-engineering.
- **매 GC log 의 production 의 disable** — 매 incident 의 post-mortem 의 impossible.
## 🧪 검증 / 중복
- Verified (HotSpot ZGC tuning guide JDK 21, Go runtime/mgc.go, V8 blog 'Orinoco' 2020-2024).
- 신뢰도 A.
- 중복 risk: [[Major GC]] (related phase), [[동시성 및 점진적 마킹(Concurrent Incremental Marking)]] (technique that 매 reduces STW).
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — STW phases, modern GC pause budgets, tuning patterns 정리 |