Skip to content

YinglunQ/100-new-requests-while-still-serving-the-first

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aargh, 100 new requests while still serving the first one!

As described in article Aargh, 100 new requests while still serving the first one!;

Node.js has only one thread processing JavaScript code. What happens if a request comes in and a file needs to be read from the disk, and in the meantime there are 100 new incoming connections?

Wouldn't the file read callback have to wait until all the other connections are served?

Well, yes, the callback would have to wait for other events to be processed first. But it's all very ok.

Contents

server.js - reads file for first request and does nothing for the rest, uses request counter

run.sh - starts server and initiates 100 concurrent connections using ab

Run test case

Run

npm install
bash run.sh

and you'll see that file read initiated from serving request #1 completes only after other requests have arrived.

serving request #1
serving request #2
serving request #3
.
.
.
serving request #99
serving request #100
file read for request #1 complete

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 87.4%
  • Shell 12.6%