Home
home

Cilium Tunning.. (2)

1. 패킷 버퍼 / 큐 관리

net.core.rmem_max, net.core.wmem_max
용도: 소켓 수신/송신 버퍼 최대 크기.
영향: iperf3 같은 대량 트래픽에서 buffer 부족으로 인한 드롭 방지. 큰 값으로 올리면 대역폭 활용이 좋아짐.
기본값(212992) → 수 MB 이상으로 확장 권장 (16MB)
sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.wmem_max=16777216 # default sysctl -w net.core.rmem_max=212992 sysctl -w net.core.wmem_max=212992
Bash
복사
net.core.netdev_max_backlog
용도: NIC가 커널로 전달한 패킷을 큐에 쌓는 최대 길이.
영향: burst traffic 상황에서 패킷 드롭 줄임.
기본값(1000) → 수만 단위 (예: 16384 이상).
sysctl -w net.core.netdev_max_backlog=16384 # default sysctl -w net.core.netdev_max_backlog=1000
Bash
복사
net.core.optmem_max
용도: 소켓 옵션에 쓸 수 있는 메모리 최대 크기.
영향: 대규모 연결 시 부족 현상 방지.
기본값(81920)
sysctl -w net.core.optmem_max=163840 # default sysctl -w net.core.optmem_max=81920
Bash
복사

2. TCP 성능 최적화

net.ipv4.tcp_rmem, net.ipv4.tcp_wmem
용도: TCP 소켓의 min/default/max 버퍼.
영향: RTT 높은 환경이나 고대역폭-고지연(BDP)에서 필수.
기본값(4096 87380 6291456) → 수십 MB로 확장 가능.
sysctl -w "net.ipv4.tcp_rmem=67108864 134217728 268435456" sysctl -w "net.ipv4.tcp_wmem=67108864 134217728 268435456" # default sysctl -w "net.ipv4.tcp_rmem=4096 131072 6291456" sysctl -w "net.ipv4.tcp_wmem=4096 131072 6291456"
Bash
복사
net.ipv4.tcp_mtu_probing
용도: Path MTU discovery 실패 시 자동으로 MSS 줄이는 기능.
영향: 터널(VXLAN, Geneve) 경로에서 MTU mismatch 드롭 방지.
기본값(0) → 1
sysctl -w net.ipv4.tcp_mtu_probing=1 # default sysctl -w net.ipv4.tcp_mtu_probing=0
Bash
복사
net.ipv4.tcp_fin_timeout, net.ipv4.tcp_tw_reuse
용도: 짧은 수명 TCP 연결 다룰 때 TIME_WAIT 줄임.
영향: 대규모 short-lived connection 성능 개선.
기본값(60/2)
sysctl -w net.ipv4.tcp_fin_timeout=30 sysctl -w net.ipv4.tcp_tw_reuse=1 # default sysctl -w net.ipv4.tcp_fin_timeout=60 sysctl -w net.ipv4.tcp_tw_reuse=2
Bash
복사

3. UDP 및 Connection Tracking

net.netfilter.nf_conntrack_max
용도: 커널 conntrack 테이블 크기.
영향: Pod-to-Pod/Service 대규모 연결 시 OOM/Drop 방지.
기본값(262144): 메모리 의존. 최소 수십만 단위 권장.
sysctl -w net.netfilter.nf_conntrack_max=655350 # default sysctl -w net.netfilter.nf_conntrack_max=262144
Bash
복사
net.netfilter.nf_conntrack_tcp_timeout_established
용도: Established TCP 연결 유지 시간.
영향: 연결 수가 많은 경우 timeout 조정 필요.
기본값(432000)
sysctl -w net.netfilter.nf_conntrack_tcp_timeout_established=3600 # default sysctl -w net.netfilter.nf_conntrack_tcp_timeout_established=432000
Bash
복사

4. 인터럽트 및 멀티큐

net.core.somaxconn
용도: listen backlog 최대 크기.
영향: 서버 Pod에서 동시 연결 수용에 영향.
기본값(4096)
sysctl -w net.core.somaxconn=8192 # default sysctl -w net.core.somaxconn=4096
Bash
복사
RPS/RFS (/sys/class/net/<if>/queues/*/rps_cpus)
용도: NIC RX queue를 여러 CPU에 분산.
영향: 단일 CPU 병목 완화, 다중 스트림 성능 향상.
기본값(0)
XPS (/sys/class/net/<if>/queues/*/xps_cpus)
용도: 송신 경로 CPU affinity 조정.
영향: 캐시 로컬리티 개선, 레이턴시 낮춤.
기본값(0)

5. MTU / Offload

ifconfig <iface> mtu / ip link set mtu
용도: MTU 크기 조정 (1500 vs 9000 Jumbo frame).
영향: 큰 패킷 처리 시 CPU 오버헤드 줄임. (단, 터널링 시 MTU mismatch 위험)
ethtool offload 옵션 (GRO, GSO, TSO 등)
용도: NIC offload 기능 on/off.
영향: CPU 부하 감소 vs 지연 편차.
Cilium 같은 eBPF datapath와 충돌하는 경우 꺼야 할 때 있음.

EC2 인스턴스 환경에서 실습

Worker Node : m8g.8xlarge (시간당 $1.4)
Control Plane Node : c7g.large (시간당 $0.08)
ami : /aws/service/canonical/ubuntu/server/24.04/stable/current/arm64/hvm/ebs-gp3/ami-id
# 배포 cat <<EOF | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: iperf3-server spec: selector: matchLabels: app: iperf3-server replicas: 1 template: metadata: labels: app: iperf3-server spec: containers: - name: iperf3-server image: networkstatic/iperf3 args: ["-s"] ports: - containerPort: 5201 --- apiVersion: v1 kind: Service metadata: name: iperf3-server spec: selector: app: iperf3-server ports: - name: tcp-service protocol: TCP port: 5201 targetPort: 5201 - name: udp-service protocol: UDP port: 5201 targetPort: 5201 type: ClusterIP --- apiVersion: apps/v1 kind: Deployment metadata: name: iperf3-client spec: selector: matchLabels: app: iperf3-client replicas: 1 template: metadata: labels: app: iperf3-client spec: containers: - name: iperf3-client image: networkstatic/iperf3 command: ["sleep"] args: ["infinity"] EOF # 확인 : 서버와 클라이언트가 어떤 노드에 배포되었는지 확인 kubectl get deploy,svc,pod -owide # 서버 파드 로그 확인 : 기본 5201 포트 Listen kubectl logs -l app=iperf3-server -f
Bash
복사
측정 방법
A) TCP 5201, 측정시간 5초
kubectl exec -it deploy/iperf3-client -- iperf3 -c iperf3-server -t 5
Bash
복사
B) UDP 사용, 역방향 모드(-R)
kubectl exec -it deploy/iperf3-client -- iperf3 -c iperf3-server -u -b 20G
Bash
복사
C) TCP, 쌍방향 모드(-R)
kubectl exec -it deploy/iperf3-client -- iperf3 -c iperf3-server -t 5 --bidir
Bash
복사
D) TCP 다중 스트림(30개), -P(number of parallel client streams to run)
kubectl exec -it deploy/iperf3-client -- iperf3 -c iperf3-server -t 10 -P 2
Bash
복사
같은 노드에 구성
kubectl patch deploy/iperf3-server -p '{ "spec":{"template":{"spec":{"nodeSelector":{ "kubernetes.io/hostname":"k8s-worker1" }}}}}'
Bash
복사
kubectl patch deploy/iperf3-client -p '{ "spec":{"template":{"spec":{"nodeSelector":{ "kubernetes.io/hostname":"k8s-worker1" }}}}}'
Bash
복사
kubectl rollout status deploy/iperf3-server kubectl rollout status deploy/iperf3-client kubectl get pod -owide
Bash
복사
A) TCP 5201, 측정시간 5초
항목
A-1
A-2
A-3
Throughput (Gbps)
65.0
65.8
65.1
Retransmissions
5946
4450
7451
Cwnd (KB, Max)
639
684
512
raw data
B) UDP 사용, 역방향 모드(-R) - 20G
항목
B-1
B-2
B-3
Throughput (Gbps, recv)
6.06
5.83
6.14
Packet Loss (%)
2.2%
5.4%
0.67%
Jitter (ms)
0.001
0.001
0.002
raw data
C) TCP, 쌍방향 모드(-R)
항목
C-1
C-2
C-3
Throughput TX (Gbps)
41.0
43.5
43.1
Retransmissions (TX)
3001
5243
4648
Cwnd (KB, Max)
588
865
1090
Throughput RX (Gbps)
32.3
31.8
33.8
Retransmissions (RX)
1094
1485
2427
raw data
D) TCP 다중 스트림(30개), -P(number of parallel client streams to run)
항목
D-1
D-2
D-3
Throughput (Gbps, Sum)
84.8
82.8
89.3
Retransmissions (SUM)
40076
20535
1322
Cwnd (KB, per-stream-max)
588
484
492
raw data
서로 다른 노드에 구성
kubectl patch deploy/iperf3-server -p '{ "spec":{"template":{"spec":{"nodeSelector":{ "kubernetes.io/hostname":"k8s-worker2" }}}}}'
Bash
복사
kubectl patch deploy/iperf3-client -p '{ "spec":{"template":{"spec":{"nodeSelector":{ "kubernetes.io/hostname":"k8s-worker1" }}}}}'
Bash
복사
kubectl rollout status deploy/iperf3-server kubectl rollout status deploy/iperf3-client kubectl get pod -owide
Bash
복사
A) TCP 5201, 측정시간 5초
항목
A-1
A-2
A-3
Throughput (Gbps)
7.9
7.9
7.9
Retransmissions
3
6
0
Cwnd (KB, Max)
raw data
B) UDP 사용, 역방향 모드(-R) - 20G
항목
B-1
B-2
B-3
Throughput (Gbps, recv)
7.92
7.92
Packet Loss (%)
0
0
Jitter (ms)
0.0
0.0
raw data
C) TCP, 쌍방향 모드(-R)
항목
C-1
C-2
C-3
Throughput TX (Gbps)
7.9
Retransmissions (TX)
0
Cwnd (KB, Max)
Throughput RX (Gbps)
Retransmissions (RX)
raw data
D) TCP 다중 스트림(30개), -P(number of parallel client streams to run)
항목
D-1
D-2
D-3
Throughput (Gbps, Sum)
Retransmissions (SUM)
Cwnd (KB, per-stream-max)
raw data
kubectl exec -it deploy/iperf3-client -- iperf3 -c iperf3-server -t 10 -P 8
Bash
복사
항목
Default 1
Default 2
Default 3
Throughput (Mbps)
756
757
747
Retransmissions
63820
62999
63100
항목
Default 1
Default 2
Default 3
Throughput (Gbps)
14.8
14.8
14.8
Retransmissions
0
0
11
sysctl -w net.core.rmem_max=4194304 # default sysctl -w net.core.rmem_max=212992
Bash
복사
항목
1
2
3
Throughput (Mbps)
753
736
757
Retransmissions
61472
59669
66484
항목
1
2
3
Throughput (Gbps)
91.9
92.4
90.5
Retransmissions
84
94
3532
sysctl -w "net.ipv4.tcp_rmem=67108864 134217728 268435456" # default sysctl -w "net.ipv4.tcp_rmem=4096 131072 6291456"
Bash
복사
항목
1
2
3
Throughput (Mbps)
836
737
766
Retransmissions
38004
57547
61216
항목
1
2
3
Throughput (Gbps)
92.6
92.3
92.5
Retransmissions
104
54
107
sysctl -w net.ipv4.tcp_mtu_probing=1 # default sysctl -w net.ipv4.tcp_mtu_probing=0
Bash
복사
항목
1
2
3
Throughput (Mbps)
742
699
741
Retransmissions
69769
70349
68482
항목
1
2
3
Throughput (Gbps)
93.5
91.6
93.1
Retransmissions
136
5
138