Load Balancing: L4 vs L7, HAProxy, Nginx, F5, Algorithms และ Health Checks

Load Balancing: L4 vs L7, HAProxy, Nginx, F5, Algorithms และ Health Checks

Load Balancing กระจาย traffic ไปยังหลาย servers เพื่อเพิ่ม availability และ performance L4 Load Balancing ทำงานที่ Transport layer (TCP/UDP), L7 Load Balancing ทำงานที่ Application layer (HTTP/HTTPS), HAProxy เป็น open-source load balancer ที่เร็วที่สุด, Nginx เป็น web server + reverse proxy + load balancer, F5 BIG-IP เป็น enterprise ADC ครบวงจร, Algorithms กำหนดวิธีกระจาย traffic และ Health Checks ตรวจสอบว่า backend servers ยังทำงานอยู่

Modern applications ต้องการ high availability (99.99%+) และ scalability: single server ไม่สามารถ handle traffic ทั้งหมดได้, single point of failure = downtime Load balancer เป็น critical infrastructure ที่อยู่หน้า servers ทั้งหมด กระจาย requests, ตรวจสอบ health, และ route traffic อย่าง intelligent

L4 vs L7 Load Balancing

Feature L4 (Transport) L7 (Application)
Layer TCP/UDP (IP + port) HTTP/HTTPS (URL, headers, cookies, content)
Decision Based On Source/dest IP + port URL path, host header, cookie, HTTP method, content type
Performance เร็วมาก (ไม่ parse application data) ช้ากว่า (ต้อง parse HTTP/HTTPS)
SSL Termination ไม่ได้ (pass-through) ได้ (decrypt → inspect → re-encrypt or forward)
Content Routing ไม่ได้ ได้ (route /api → API servers, /static → CDN)
Session Persistence Source IP only Cookie-based, header-based, URL-based
Use Case TCP services (database, SMTP, gaming, non-HTTP) Web applications, APIs, microservices

Load Balancing Algorithms

Algorithm How Best For
Round Robin วนส่ง request ไปแต่ละ server เท่าๆ กัน (1→2→3→1→2→3) Servers เหมือนกัน, requests คล้ายกัน
Weighted Round Robin Server ที่แรงกว่าได้ weight มากกว่า (server1:3, server2:1) Servers ไม่เท่ากัน (different CPU/RAM)
Least Connections ส่งไป server ที่มี active connections น้อยที่สุด Requests ที่ใช้เวลาต่างกัน (long-lived connections)
Weighted Least Connections Least connections + weight factor Mixed server capacity + variable request duration
IP Hash Hash source IP → same client → same server เสมอ Session persistence without cookies
Least Response Time ส่งไป server ที่ response เร็วที่สุด Optimize user experience (fastest response)
Random สุ่มเลือก server Simple, works well with large server pools

HAProxy

Feature รายละเอียด
คืออะไร Open-source L4/L7 load balancer — fastest, most reliable (used by GitHub, Reddit, Stack Overflow)
Performance Handle millions of connections, sub-millisecond latency
L4 Mode TCP proxy (database, mail, custom protocols)
L7 Mode HTTP proxy (URL routing, header manipulation, SSL termination)
Health Checks TCP, HTTP, custom scripts — remove unhealthy backends automatically
Stats Built-in stats page (real-time monitoring of backends)
ACLs Access Control Lists สำหรับ content-based routing
SSL SSL termination + SSL passthrough + re-encryption

Nginx

Feature รายละเอียด
คืออะไร Web server + reverse proxy + load balancer (most popular web server globally)
Load Balancing Round robin, least connections, IP hash, random (Plus: least time)
Reverse Proxy Proxy pass requests ไป backend servers (caching, SSL termination)
Caching Built-in content caching (reduce backend load)
Nginx Plus Commercial version: active health checks, session persistence, live dashboard, API
Use Case Web serving + load balancing + API gateway (all-in-one)

F5 BIG-IP

Feature รายละเอียด
คืออะไร Enterprise Application Delivery Controller (ADC) — hardware + virtual + cloud
LTM (Local Traffic Manager) L4-L7 load balancing, SSL offload, connection optimization
GTM/DNS Global server load balancing (GSLB) — route traffic ข้าม data centers
ASM Web Application Firewall (WAF) — protect against OWASP Top 10
APM Access Policy Manager — VPN, SSO, access control
iRules TCL-based scripting สำหรับ custom traffic manipulation
Price แพง (enterprise pricing) — แต่ครบทุก feature

Health Checks

Type How Detects
TCP Check Open TCP connection → success = healthy Server is reachable and port is open
HTTP Check Send HTTP request → check status code (200 OK) Web server is running and responding correctly
HTTPS Check HTTP check with SSL/TLS SSL certificate valid + app healthy
Custom Script Run custom health check script Application-specific health (DB connection, queue depth)
Active LB actively sends health probes at intervals Proactive detection (find issues before users do)
Passive Monitor real traffic responses for errors Detect issues from actual user traffic (no extra probe traffic)

Cloud Load Balancers

Cloud L4 L7 Global
AWS NLB (Network Load Balancer) ALB (Application Load Balancer) Global Accelerator
Azure Azure Load Balancer Application Gateway Front Door
GCP Network Load Balancing HTTP(S) Load Balancing Cloud CDN + Global LB

Load Balancing Best Practices

Practice รายละเอียด
HA LB Deploy LB in active-passive หรือ active-active pair (LB ไม่ควรเป็น SPOF)
Health Checks ใช้ application-level health checks (ไม่ใช่แค่ TCP port open)
SSL Termination Terminate SSL ที่ LB → backend ใช้ HTTP (ลด CPU load บน servers)
Connection Draining เมื่อ remove server → drain existing connections ก่อน (graceful removal)
Sticky Sessions ใช้เฉพาะเมื่อจำเป็น (ลด load distribution efficiency)
Monitoring Monitor LB metrics: active connections, throughput, error rate, latency

ทิ้งท้าย: Load Balancing = Foundation of Scalable Architecture

Load Balancing L4 vs L7: L4 = fast/TCP-based | L7 = smart/HTTP-based (URL routing, SSL termination) Algorithms: round robin, least connections, IP hash, least response time (choose based on workload) HAProxy: fastest open-source LB (GitHub, Reddit use it) — L4 + L7 Nginx: web server + reverse proxy + LB (most popular, all-in-one) F5 BIG-IP: enterprise ADC (LTM + GTM + WAF + APM — expensive but complete) Health Checks: TCP, HTTP, custom script — active (probe) + passive (monitor real traffic) Best Practice: HA pair, app-level health checks, SSL termination, connection draining, monitoring

อ่านเพิ่มเติมเกี่ยวกับ Cloud Networking AWS VPC Azure VNet และ Container Networking Docker Kubernetes CNI ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com

จัดส่งรวดเร็วส่งด่วนทั่วประเทศ
รับประกันสินค้าเคลมง่าย มีใบรับประกัน
ผ่อนชำระได้บัตรเครดิต 0% สูงสุด 10 เดือน
สะสมแต้ม รับส่วนลดส่วนลดและคะแนนสะสม

© 2026 SiamLancard — จำหน่ายการ์ดแลน อุปกรณ์ Server และเครื่องพิมพ์ใบเสร็จ

SiamLancard
Logo
Free Forex EA Download — XM Signal · EA Forex ฟรี
iCafeForex.com - สอนเทรด Forex | SiamCafe.net
Shopping cart