KeepAlive सेटिंग
In this page:
Connections Reuse करना क्यों मायने रखता है
एक TCP connection खोलने (और, HTTPS के लिए, इसके ऊपर एक TLS handshake पूरा करने) की असली overhead होती है। 40 assets वाला एक page जो हर एक के लिए एक नया connection खोलता उसे यह cost 40 बार pay करनी पड़ती। KeepAlive एक response के बाद connection को खुला रखता है ताकि अगली request इसे तुरंत reuse कर सके।
Directives
KeepAlive On feature को on कर देता है (modern Apache में यह default से on है)। MaxKeepAliveRequests cap करता है कि एक connection पर कितनी requests serve की जा सकती हैं इससे पहले कि इसे close किया जाए (0 का मतलब unlimited है)। KeepAliveTimeout set करता है कि एक idle connection पर एक और request के लिए Apache कितने seconds wait करे इससे पहले कि इसे close करे।
Trade-off
एक लंबा KeepAliveTimeout एक browser को page के कई assets में connections reuse करने में मदद करता है, लेकिन हर kept-alive connection एक worker/thread को busy रखता है, भले ही यह कुछ भी न कर रहा हो। एक busy server पर, बहुत लंबा timeout high traffic में available workers खत्म कर सकता है; बहुत छोटा value शुरू में KeepAlive का पूरा मतलब ही खत्म कर देता है।
यह MPM के साथ कैसे Interact करता है
एक लंबा KeepAliveTimeout कितना costly है यह इस पर बहुत depend करता है कि कौन सा Multi-Processing Module (MPM) इस्तेमाल में है -- अगले lesson में covered। prefork MPM हर kept-alive connection के लिए एक पूरी process बांध देता है, जिससे लंबा timeout costly हो जाता है; event को specifically keep-alive connections को कहीं ज़्यादा efficiently handle करने के लिए design किया गया था।
उदाहरण: A sensible KeepAlive configuration
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
{# 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). #}
- एक busy server पर KeepAliveTimeout बहुत ज़्यादा (30+ seconds) set करना, idle connections पर workers बांधते हुए और server actually कितने concurrent visitors serve कर सकता है यह कम करते हुए।
- चीज़ों को "simplify" करने के लिए KeepAlive को पूरी तरह disable करना, जो आमतौर पर real-world page loads को धीमा कर देता है क्योंकि अब हर asset को अपना नया connection चाहिए।
- यह consider किए बिना KeepAliveTimeout tune करना कि कौन सा MPM active है -- same value की cost prefork बनाम event के under बहुत अलग होती है।
Chapter Quiz — Complete all 4 topics to unlock
0/4 topics done
Complete these topics first: