f8b21af4be
10_Wiki/Topics 대규모 정리: - 오류 캡처/미완성 stub 문서 227개 제거 - 교차폴더 중복 43클러스터 병합 (63파일 → redirect) - 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건 - 카테고리 MOC 6개 신규 생성 - Graph 섹션 미해결 related-keyword 링크 10,058건 제거 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
194 lines
5.6 KiB
Markdown
194 lines
5.6 KiB
Markdown
---
|
|
id: wiki-2026-0508-cache-miss-rates
|
|
title: Cache Miss Rates
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [Cache Miss Rate, Cache Hit Rate, Cache Efficiency]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.9
|
|
verification_status: applied
|
|
tags: [performance, cache, profiling, cpu, memory]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: agnostic
|
|
framework: agnostic
|
|
---
|
|
|
|
# Cache Miss Rates
|
|
|
|
## 매 한 줄
|
|
> **"매 cache lookup 의 fail (data 의 cache 외 fetch) ratio"**. CPU L1/L2/L3 cache, browser HTTP cache, application-level memoization, CDN edge cache 의 universal metric — `miss / (hit + miss)`. 2026 perspective: Apple Silicon M4 의 huge L2 (16MB+), 매 Cloudflare/Fastly tiered cache, 매 LLM prompt-cache (Anthropic) 의 cost-driven optimization.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 hierarchy (CPU)
|
|
- **L1**: 32-128KB / core, ~1-4 cycles.
|
|
- **L2**: 256KB-2MB / core, ~10-15 cycles.
|
|
- **L3**: 8-128MB shared, ~40 cycles.
|
|
- **DRAM**: >100ns, ~200-300 cycles. 매 miss 의 huge cost.
|
|
|
|
### 매 miss types (3C)
|
|
- **Compulsory** (cold): 매 first access.
|
|
- **Capacity**: 매 working set > cache size.
|
|
- **Conflict**: 매 set-associative collision.
|
|
- (+) **Coherence**: multi-core invalidation.
|
|
|
|
### 매 measurement
|
|
- **CPU**: `perf stat -e cache-misses,cache-references` (Linux).
|
|
- **HTTP**: `cf-cache-status: HIT/MISS` headers.
|
|
- **App**: hit/miss counter on cache wrapper.
|
|
|
|
### 매 응용
|
|
1. 매 hot loop 의 data layout (SoA vs AoS) tuning.
|
|
2. 매 CDN cache key strategy.
|
|
3. 매 LLM prompt-cache 의 prefix stability.
|
|
|
|
## 💻 패턴
|
|
|
|
### Pattern 1 — 매 cache-friendly layout (SoA)
|
|
```ts
|
|
// 매 BAD (AoS) — 매 padding / strided access
|
|
const particles = [{ x: 0, y: 0, vx: 1, vy: 1 }, /* ... */];
|
|
|
|
// 매 GOOD (SoA) — 매 sequential, cache-line dense
|
|
const xs = new Float32Array(N), ys = new Float32Array(N);
|
|
const vxs = new Float32Array(N), vys = new Float32Array(N);
|
|
for (let i = 0; i < N; i++) {
|
|
xs[i] += vxs[i];
|
|
ys[i] += vys[i];
|
|
}
|
|
```
|
|
|
|
### Pattern 2 — 매 LRU cache (memoization)
|
|
```ts
|
|
class LRU<K, V> {
|
|
private map = new Map<K, V>();
|
|
constructor(private capacity: number) {}
|
|
|
|
get(key: K): V | undefined {
|
|
if (!this.map.has(key)) return;
|
|
const v = this.map.get(key)!;
|
|
this.map.delete(key);
|
|
this.map.set(key, v); // refresh
|
|
return v;
|
|
}
|
|
set(key: K, val: V) {
|
|
if (this.map.has(key)) this.map.delete(key);
|
|
else if (this.map.size >= this.capacity) {
|
|
this.map.delete(this.map.keys().next().value!);
|
|
}
|
|
this.map.set(key, val);
|
|
}
|
|
}
|
|
```
|
|
|
|
### Pattern 3 — 매 hit rate metric
|
|
```ts
|
|
class CountingCache<K, V> {
|
|
private hits = 0;
|
|
private misses = 0;
|
|
constructor(private inner: Map<K, V>, private load: (k: K) => V) {}
|
|
|
|
get(k: K): V {
|
|
if (this.inner.has(k)) { this.hits++; return this.inner.get(k)!; }
|
|
this.misses++;
|
|
const v = this.load(k);
|
|
this.inner.set(k, v);
|
|
return v;
|
|
}
|
|
hitRate(): number { return this.hits / (this.hits + this.misses || 1); }
|
|
}
|
|
```
|
|
|
|
### Pattern 4 — 매 HTTP cache header
|
|
```http
|
|
GET /api/posts/123
|
|
Cache-Control: public, max-age=300, stale-while-revalidate=86400
|
|
ETag: "abc123"
|
|
|
|
# CDN response
|
|
cf-cache-status: HIT
|
|
age: 42
|
|
```
|
|
|
|
### Pattern 5 — 매 stable key (CDN)
|
|
```ts
|
|
// 매 BAD — query order varies
|
|
fetch(`/api/list?b=2&a=1`);
|
|
fetch(`/api/list?a=1&b=2`); // 매 different cache key
|
|
|
|
// 매 GOOD — canonical
|
|
const params = new URLSearchParams();
|
|
[...Object.entries(args)].sort().forEach(([k, v]) => params.set(k, v));
|
|
fetch(`/api/list?${params}`);
|
|
```
|
|
|
|
### Pattern 6 — 매 LLM prompt cache (Anthropic)
|
|
```python
|
|
# 매 stable system prefix → cache hit (90% cost reduction)
|
|
client.messages.create(
|
|
model="claude-opus-4-7",
|
|
system=[
|
|
{"type": "text", "text": LARGE_STABLE_PREFIX,
|
|
"cache_control": {"type": "ephemeral"}},
|
|
],
|
|
messages=[{"role": "user", "content": query}],
|
|
)
|
|
```
|
|
|
|
### Pattern 7 — 매 CPU perf measure
|
|
```bash
|
|
perf stat -e cache-references,cache-misses,L1-dcache-load-misses ./app
|
|
# 매 miss rate = misses / references
|
|
```
|
|
|
|
### Pattern 8 — 매 prefetch hint
|
|
```ts
|
|
// 매 link prefetch (browser)
|
|
<link rel="prefetch" href="/next-page" as="document">
|
|
|
|
// 매 software prefetch (WASM/native via SIMD intrinsics)
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Approach |
|
|
|---|---|
|
|
| 매 hot loop slow | profile cache-misses, switch to SoA. |
|
|
| 매 CDN low hit rate | normalize key, raise max-age. |
|
|
| 매 LLM cost high | prompt-cache stable prefix. |
|
|
| 매 working set > cache | partition (tiling), reduce. |
|
|
| 매 frequent-but-changing | LRU + TTL. |
|
|
|
|
**기본값**: 매 measure first (perf, CDN headers, app counter), 매 90%+ hit rate target on hot caches.
|
|
|
|
## 🔗 Graph
|
|
- 부모: [[Performance]]
|
|
- 변형: [[CDN]] · [[Memoization]]
|
|
- 응용: [[Prompt Cache]]
|
|
- Adjacent: [[CPU Overhead]] · [[Buffer Allocation]] · [[Batching]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: 매 cache strategy design, hit rate target setting, prompt-cache prefix structuring.
|
|
**언제 X**: 매 hardware-specific cache line size assumption — vendor docs 의.
|
|
|
|
## ❌ 안티패턴
|
|
- **매 cache everything**: 매 cold data cache space waste.
|
|
- **매 unstable cache key**: 매 hit rate near zero.
|
|
- **매 no eviction**: unbounded memory.
|
|
- **매 measuring without baseline**: 매 hit rate alone meaningless — 매 latency / cost outcome 의.
|
|
- **매 caching mutable data without invalidation**: stale read bug.
|
|
|
|
## 🧪 검증 / 중복
|
|
- Reference (Hennessy & Patterson, Cloudflare cache docs, Anthropic prompt caching docs).
|
|
- 신뢰도 A.
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup — cache hierarchy + LRU + HTTP + prompt-cache patterns |
|