Blocking I/O, operation పూర్తయ్యే వరకు calling thread ను ఆపుతుంది; non-blocking I/O వెంటనే తిరిగి వస్తుంది మరియు operation పూర్తయ్యే సమయంలో thread ను ఇతర పని చేయనిస్తుంది. Sync vs async అదే ఆలోచనను API స్థాయిలో వివరిస్తుంది.
Blocking I/O, operation పూర్తయ్యే వరకు calling thread ను ఆపుతుంది; non-blocking I/O వెంటనే తిరిగి వస్తుంది మరియు operation పూర్తయ్యే సమయంలో thread ను ఇతర పని చేయనిస్తుంది. Sync vs async అదే ఆలోచనను API స్థాయిలో వివరిస్తుంది.
read() పై ఆగిపోతుంది. సరళం, కానీ thread మొత్తం సమయం idle గా ఉంటుంది — 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 counts ను నిర్వహిస్తాయి, ఖచ్చితంగా I/O non-blocking కావడం వల్ల — waiting ఒక thread ను ఆక్రమించదు. scripts లో సరళత కోసం blocking calls ను ఉపయోగించండి; high-concurrency network services కోసం non-blocking ను ఉపయోగించండి, మరియు CPU-heavy పనితో event loop ను ఎప్పుడూ block చేయవద్దు.
జూనియర్ నుండి సీనియర్ వరకు వివరణాత్మక సమాధానాలతో IT ఇంటర్వ్యూ ప్రశ్నల లైబ్రరీ.
విరాళం