MPM Worker, Prefork और Event
In this page:
एक MPM क्या करता है
Apache जो हर request handle करता है उसे चलने के लिए कोई execution unit -- एक process या एक thread -- चाहिए होता है। MPM एक pluggable module है जो decide करता है कि वह unit क्या है और Apache उनमें से कितने ready रखता है। किसी भी समय exactly एक MPM active होता है, startup पर चुना गया।
Prefork
prefork हर request को एक अलग, single-threaded process से handle करता है। यह सबसे पुराना और सबसे simple model है, और इसका बड़ा advantage compatibility है -- non-thread-safe modules (classically Apache में सीधे compiled mod_php) को इसकी ज़रूरत होती है। cost memory की है: हर process Apache का पूरा वज़न carry करती है, इसलिए यह RAM की per-unit बाकी alternatives से कम simultaneous connections तक scale करता है।
Worker
worker कई processes इस्तेमाल करता है, हर एक कई threads चलाती है, ताकि ज़्यादा requests कम processes की memory share करें -- high concurrency में prefork से कहीं halka। requirement यह है कि इस्तेमाल में हर module thread-safe हो, क्योंकि अब कई requests same process के अंदर simultaneously चल सकती हैं।
Event
event, worker का एक refinement है और ज़्यादातर Linux distributions पर modern default है। यह active request handle करने वाले thread को सिर्फ idle रखे गए connections से अलग करता है, हर idle connection के लिए एक पूरा worker thread बांधने की बजाय कई keep-alive connections manage करने के लिए dedicated threads की एक छोटी संख्या इस्तेमाल करते हुए।
Active MPM चुनना और Check करना
apachectl -V दिखाता है कि किसी given Apache build पर कौन सा MPM चल रहा है। Ubuntu पर, MPMs switch करना बस एक disable करके दूसरा enable करने जितना simple है a2dismod/a2enmod से (जैसे sudo a2dismod mpm_prefork फिर sudo a2enmod mpm_event), उसके बाद एक restart। practice में, event इस्तेमाल करें जब तक कि कोई specific चीज़ -- आमतौर पर एक पुराना, non-thread-safe module -- आपको prefork पर force न करे।
उदाहरण: Checking and switching the active MPM (Ubuntu)
# Check which MPM is compiled/active
apachectl -V | grep -i mpm
# Switch from prefork to event
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo systemctl restart apache2
{# 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). #}
- बिना किसी असली वजह के default से
preforkपर रहना, worker/event की memory-per-concurrency में कहीं बेहतर performance miss करते हुए। - worker/event पर switch करना जबकि अभी भी किसी module पर depend कर रहे हों जो thread-safe नहीं है, load में crashes या corrupted responses cause करते हुए।
- MPM बदलने के बाद Apache को पूरी तरह restart करने की बजाय reload करना -- MPM process startup पर चुना जाता है और सिर्फ एक reload change apply नहीं करेगा।
Chapter Quiz — Complete all 4 topics to unlock
0/4 topics done
Complete these topics first: