Blocking I/O operation संपेपर्यंत calling thread थांबवते; non-blocking I/O लगेच परत येते आणि operation पूर्ण होत असताना thread ला इतर काम करू देते. Sync विरुद्ध async हीच कल्पना API पातळीवर वर्णन करते.
Blocking I/O operation संपेपर्यंत calling thread थांबवते; non-blocking I/O लगेच परत येते आणि operation पूर्ण होत असताना thread ला इतर काम करू देते. Sync विरुद्ध async हीच कल्पना API पातळीवर वर्णन करते.
read() वर थांबतो. सोपे, पण thread संपूर्ण वेळ निष्क्रिय असतो — N slow clients ना सेवा देण्यासाठी तुम्हाला N threads लागतात.Blocking: ──[ wait for disk ]── (thread stuck, does nothing)
Non-blocking: ──▶ returns now; event loop notified when ready
// Blocking: nothing else runs until the file is read
const data = fs.readFileSync('big.txt');
// Non-blocking: thread keeps going; callback fires later
fs.readFile('big.txt', (err, data) => { /* handle later */ });
// or async/await on top of non-blocking primitives
const data2 = await fs.promises.readFile('big.txt');
हे scalable servers चे गाभा आहे. Node.js आणि nginx थोड्या threads वर प्रचंड connection counts हाताळतात कारण नेमके I/O non-blocking आहे — वाट पाहणे thread अडकवत नाही. Scripts मध्ये सोपेपणासाठी blocking calls वापरा; high-concurrency network services साठी non-blocking वापरा, आणि CPU-heavy कामाने कधीही event loop block करू नका.
सविस्तर उत्तरांसह IT मुलाखत प्रश्नांचे ग्रंथालय — Junior पासून Senior पर्यंत.
देणगी द्या