docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
---
|
||||
id: wiki-2026-0508-load-balancing-strategies
|
||||
title: Load Balancing Strategies
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Load Balancer, LB, Reverse Proxy]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [networking, load-balancer, nginx, envoy, haproxy, aws-alb]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack: { language: Config, framework: Nginx/Envoy/HAProxy/AWS }
|
||||
---
|
||||
|
||||
# Load Balancing Strategies
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 LB = traffic 분산 + health check + sticky"**. 알고리즘은 균등성과 affinity의 trade-off.
|
||||
|
||||
## 매 핵심
|
||||
### 매 알고리즘
|
||||
- **Round-robin**: 순차. 단순, 동질 서버.
|
||||
- **Weighted RR**: 용량 차등.
|
||||
- **Least connections**: 활성 연결 최소. long-lived 적합.
|
||||
- **Least response time**: 평균 응답 + connection 수.
|
||||
- **IP hash**: client IP→server. session affinity.
|
||||
- **Consistent hash**: cache/shard. node 추가 시 K/n key만 재배치.
|
||||
- **Random / P2C**: power of two choices, least-loaded 선택. 간단·강력.
|
||||
|
||||
### 매 Layer
|
||||
- **L4 (TCP/UDP)**: 빠름, opaque. NLB, HAProxy TCP mode.
|
||||
- **L7 (HTTP)**: header/path 기반 라우팅, TLS 종료. ALB, Nginx, Envoy.
|
||||
|
||||
### 매 Health check
|
||||
- Active: /health 주기적 GET
|
||||
- Passive: 실제 요청 실패 카운트
|
||||
- Slow start: 신규 노드에 점진적 traffic
|
||||
- Outlier detection (Envoy): 연속 5xx → eject
|
||||
|
||||
### 매 Session affinity (sticky)
|
||||
- Cookie-based (LB가 cookie 발급)
|
||||
- Source IP (NAT 뒤에 모이면 unbalanced)
|
||||
- Header-based (custom)
|
||||
|
||||
### 매 응용
|
||||
1. Web app: ALB + multi-AZ
|
||||
2. gRPC/HTTP2: Envoy (L7 multiplex)
|
||||
3. DB read replica: ProxySQL, PgBouncer
|
||||
4. Cache shard: consistent hash (Redis cluster)
|
||||
5. Service mesh: Envoy sidecar (Istio, Linkerd)
|
||||
|
||||
## 💻 패턴
|
||||
### Nginx upstream
|
||||
```nginx
|
||||
upstream backend {
|
||||
least_conn; # algorithm
|
||||
server app1:8080 weight=3 max_fails=3 fail_timeout=30s;
|
||||
server app2:8080 weight=1;
|
||||
server app3:8080 backup; # only if others down
|
||||
keepalive 32;
|
||||
}
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://backend;
|
||||
proxy_set_header Host $host;
|
||||
proxy_next_upstream error timeout http_502 http_503;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### HAProxy
|
||||
```
|
||||
backend web
|
||||
balance leastconn
|
||||
option httpchk GET /health
|
||||
server s1 10.0.0.1:8080 check weight 100
|
||||
server s2 10.0.0.2:8080 check weight 50
|
||||
cookie SRV insert indirect nocache # sticky
|
||||
```
|
||||
|
||||
### Envoy (L7, gRPC)
|
||||
```yaml
|
||||
clusters:
|
||||
- name: api
|
||||
type: STRICT_DNS
|
||||
lb_policy: LEAST_REQUEST
|
||||
health_checks:
|
||||
- timeout: 1s
|
||||
interval: 5s
|
||||
http_health_check: { path: "/health" }
|
||||
outlier_detection:
|
||||
consecutive_5xx: 5
|
||||
base_ejection_time: 30s
|
||||
load_assignment:
|
||||
cluster_name: api
|
||||
endpoints:
|
||||
- lb_endpoints:
|
||||
- endpoint: { address: { socket_address: { address: api1, port_value: 8080 }}}
|
||||
```
|
||||
|
||||
### AWS ALB (Terraform)
|
||||
```hcl
|
||||
resource "aws_lb" "app" {
|
||||
name = "app-alb"
|
||||
load_balancer_type = "application"
|
||||
subnets = var.public_subnets
|
||||
}
|
||||
resource "aws_lb_target_group" "api" {
|
||||
port = 8080
|
||||
protocol = "HTTP"
|
||||
health_check { path = "/health"; interval = 15 }
|
||||
stickiness { type = "lb_cookie"; enabled = true }
|
||||
}
|
||||
```
|
||||
|
||||
### Consistent hash (Python sketch)
|
||||
```python
|
||||
import bisect, hashlib
|
||||
class Ring:
|
||||
def __init__(self, nodes, vnodes=150):
|
||||
self.ring = []
|
||||
for n in nodes:
|
||||
for i in range(vnodes):
|
||||
h = int(hashlib.md5(f"{n}-{i}".encode()).hexdigest(), 16)
|
||||
bisect.insort(self.ring, (h, n))
|
||||
def get(self, key):
|
||||
h = int(hashlib.md5(key.encode()).hexdigest(), 16)
|
||||
i = bisect.bisect(self.ring, (h, ""))
|
||||
return self.ring[i % len(self.ring)][1]
|
||||
```
|
||||
|
||||
### P2C (power of two choices)
|
||||
```python
|
||||
import random
|
||||
def p2c(servers, load):
|
||||
a, b = random.sample(servers, 2)
|
||||
return a if load[a] <= load[b] else b
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | LB / 알고리즘 |
|
||||
|---|---|
|
||||
| AWS web app | ALB + round_robin |
|
||||
| TCP / 빠름 | NLB / HAProxy L4 |
|
||||
| gRPC, mesh | Envoy least_request |
|
||||
| Cache shard | Consistent hash |
|
||||
| DB connection pool | PgBouncer/ProxySQL |
|
||||
| Bare metal HTTP | Nginx least_conn |
|
||||
| 동질 서버 + short req | RR/Random |
|
||||
| 이질 서버 / long conn | Weighted least-conn |
|
||||
|
||||
**기본값**: HTTP는 ALB or Nginx least_conn. 마이크로서비스는 Envoy.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Distributed-Systems]]
|
||||
- 변형: [[Consistent-Hashing]], [[Reverse-Proxy]]
|
||||
- 응용: [[High-Availability]], [[Service Mesh]], [[CDN]]
|
||||
- Adjacent: [[API-Gateway]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: config 작성, 알고리즘 선택, troubleshoot 가설.
|
||||
**언제 X**: production tuning은 metric 기반 검증 필수.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- IP hash + NAT/CGNAT (모든 client가 한 노드)
|
||||
- Sticky session 과의존 → 노드 죽으면 세션 다 잃음
|
||||
- Health check 너무 짧은 interval → flapping
|
||||
- L7 LB에서 keepalive 비활성화 → 성능↓
|
||||
- Hash ring vnode 부족 → 불균형
|
||||
- TLS termination만 보고 backend mTLS 무시
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Nginx/Envoy/HAProxy docs, Mitzenmacher P2C, AWS ELB docs). 신뢰도 A.
|
||||
- 중복: 없음.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Envoy/AWS/consistent-hash 코드 추가 |
|
||||
Reference in New Issue
Block a user