Node architecture and js performance

I have a question about Node js architecture and performance.

I did a bunch of reading on this topic (including stack overflows), and I still have a couple of questions. I would like to do 2 things:

  • Summarize what I learned from scanning various sources in a semi-concise manner to make sure my conclusions are correct.
  • Ask a couple of questions about streaming and Node performance that I couldn’t determine with the exact answers from my research.

Node has a single-threaded asynchronous event processing architecture

single  - threaded - There is one stream of events that sends asynchronous work (the result is usually I / O, but can be a computation) and performs a callback (i.e., processing async work results).

  • the flow of events starts in an endless "cycle of events" that performs 2 tasks above; a) process requests by sending asynchronous work, and b) noticing that the previous results of the asynchronous processing work are ready and perform a callback to process the results.

  • The general analogy here is the restaurant clerk: the flow of events is an ultra-fast waiter who takes orders (service requests) from the dining room and delivers orders to the kitchen that will be prepared (sends asynchronous work), but also notices when the food is ready (asynchronous results) and returns it back to the table (making a callback).

  • ; , . , ​​ , , , , .

, (, -), : .

   FIRST [ASYNC: read a file, figure out what to get from the database] THEN 
   [ASYNC: query the database] THEN 
   [format and return the result].

"ASYNC" - " ", "FIRST []" "THEN []" , .

, , :

  • /

  • promises, .then()

  • async, () async.

, asynch/await .

, ... ? !

, , , , , " " (.. ):

  • Node , - libuv, ? , libuv Node ( ) -, async - ? , - " " async, , " " - node? , ? , ? , ?

  • , libuv ( pthreads, ?). "" , " " , , libuv API?

  • , , node - : ( ) - , CPU , , , - ( ), , Node asynch I/O OS/kernel, ? SOMETHING , I/O ... , , ​​ , ? , , , libuv... , ( ) , ?... , , , ?

+6
1

SO , . , .

" " / node? , ? , ? , ?

, - : .

, . , , ( ) ( , ). . , , - ( , DOS- ), .

, . . , , , . , .

. (.. ). , OS ?

. ​​ .

- , . , . , - ( , , ..), , , . CPU , ( , ). / , , -.

​​. ( ) , , ( OS- ) .

, ?

, API, :

  • /: , , , , . , -. , , .

  • -. , ? , . , , . , .

- , , . :

  • /: , , , , ? .

  • Async I/O: , wait CPU, , . ​​ !

, libuv ( pthreads, ?). "" , " ", async

.

, , -, . Tcl async I/O node 80- . . node , , - , API .

SOMETHING , I/O

, (1) . , , select() C. C, TCP/IP , select(). Google " c". , C : , , ?

, ?... , , , ?

, (1), , , . . , . - , , .

/ - . , node.js, , , nginx apache2.

- , CGI , , node.js, - , . -, HTTP (, node Express.js) - FastCGI.


. , ? 90- - 2000- -. Tcl, , , , 500% , C ( , bash), apache ( apache2 , apache2). : tcl -, async-I/O. , C ( , C -, tcl C ).

node.js , Java, , async I/O. , - API ( , promises) , - C.

, , select() C.

+3

All Articles