Load Balancing क्या है
In this page:
mod_proxy_balancer
Load balancing mod_proxy पर बनता है, mod_proxy_balancer plus एक specific balancing algorithm module (default round-robin approach के लिए mod_lbmethod_byrequests) add करते हुए। Ubuntu पर: sudo a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests।
एक Balancer Cluster Define करना
एक <Proxy "balancer://mycluster"> block backend servers को BalancerMember lines की तरह list करता है, और ProxyPass "/" "balancer://mycluster/" traffic को एक fixed address की बजाय cluster पर भेजता है। Apache फिर आने वाली requests को हर listed member में distribute कर देता है।
Balancing Methods
byrequests (default) requests को round-robin फैलाता है, optionally हर BalancerMember पर एक loadfactor से weighted। bytraffic request count की बजाय transfer हुए bytes से balance करता है। bybusyness नई requests को उस backend पर भेजता है जिसकी अभी सबसे कम active requests हों, जो uneven request processing times वाले backends को plain round-robin से बेहतर handle करता है।
Session Persistence और Health Checks
अगर application session data को (Redis जैसे shared store की बजाय) एक single server पर memory में store करता है, किसी given user की requests को same backend पर landing करते रहना ज़रूरी है -- BalancerMember इसके लिए route-based "sticky sessions" support करता है। BalancerMember ... retry=60 Apache को fail होते backend को requests भेजना automatically रोकने भी देता है, दिए गए seconds के बाद इसे दोबारा try करते हुए।
उदाहरण: A simple two-backend load balancer
<Proxy "balancer://mycluster">
BalancerMember "http://127.0.0.1:8001"
BalancerMember "http://127.0.0.1:8002"
</Proxy>
ProxyPass "/" "balancer://mycluster/"
ProxyPassReverse "/" "balancer://mycluster/"
{# Flagged by hand after confirming a runner can't handle this example
(a shell command / go.mod file stored as a TopicExample, a language
feature the configured runner version doesn't support, or output
that blows a runner's sandbox limit) -- see TopicExample.norun.
Never render the run button for these, regardless of language,
since it would just fail at execute_code (or worse, hang the
Judge0 queue on a submission that can never finish cleanly). #}
- local memory में session state रखने वाले backends में, sticky sessions के बिना, load balance करना -- जब भी request अलग backend पर land करे users log out हो जाते हैं या data खो देते हैं।
- mod_proxy_balancer और lbmethod module enable करना भूल जाना, ताकि ProxyPass में
balancer://addresses बस resolve ही न हों। - कोई retry/health-check behavior configure न करना, ताकि Apache traffic का एक हिस्सा उस backend को भेजता रहे जो पहले से down है।
Chapter Quiz — Complete all 4 topics to unlock
0/4 topics done
Complete these topics first: