Blocking I/O ஆனது operation முடியும் வரை calling thread-ஐ நிறுத்துகிறது; non-blocking I/O உடனடியாகத் திரும்பி, operation நிறைவடையும் போது thread மற்ற வேலையைச் செய்ய அனுமதிக்கிறது. Sync எதிராக async என்பது அதே கருத்தை API level-இல் விவரிக்கிறது.
Blocking I/O ஆனது operation முடியும் வரை calling thread-ஐ நிறுத்துகிறது; non-blocking I/O உடனடியாகத் திரும்பி, operation நிறைவடையும் போது thread மற்ற வேலையைச் செய்ய அனுமதிக்கிறது. Sync எதிராக async என்பது அதே கருத்தை API level-இல் விவரிக்கிறது.
read()-இல் நிறுத்தப்படுகிறது. எளிமையானது, ஆனால் thread முழு நேரமும் செயலற்று இருக்கிறது — N மெதுவான 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 எண்ணிக்கைகளைக் கையாளுகின்றன, சரியாக I/O non-blocking ஆக இருப்பதால் — காத்திருப்பு ஒரு thread-ஐக் கட்டுப்படுத்தாது. scripts-இல் எளிமைக்காக blocking calls-ஐப் பயன்படுத்துங்கள்; high-concurrency network services-க்கு non-blocking-ஐப் பயன்படுத்துங்கள், மேலும் CPU-heavy வேலையுடன் event loop-ஐ ஒருபோதும் block செய்ய வேண்டாம்.
விரிவான பதில்களுடன் கூடிய IT நேர்காணல் கேள்விகளின் நூலகம் — Junior முதல் Senior வரை.
நன்கொடை