What are the benefits of java.nio for a web server?

I know this is a recurring question, and I read articles similar to the following http://www.mailinator.com/tymaPaulMultithreaded.pdf saying that it is not necessarily true that nio scale is better than io.

But I'm struggling to understand how java nio can scale when developing a web server, than the traditional acceptor / workflow architecture? Let me explain:

Typically, Java web servers use the following template to handle connections:

  • Several acceptor threads limited by the number of kernel blocks in the accept Server Server () method:

    while (true) {
      socket = serverSocket.accept();
      // handleRequest submits the socket to a queue
      handleRequest(socket);
      socket.close();
    }
    
  • When a client socket is retrieved, it is sent to a non-blocking queue and then processed by the workflow from the workflow pool. The number of workflows depending on the duration of the io operations.

How will using java.nio make this architecture more scalable?

I mean, I still need to have workflows to handle the request, which will perform blocking operations (access to the database or file system, calling external services). If backend operations are not performed asynchronously, as in node.js, I will still need processed threads that would limit overall scalability against 1 or 2 event manager threads.

+5
source share
2 answers

, . :

  • IO ( )
  • - - - .

NIO , , , . : NIO , .

, , . ... ?

, , :

  • , , " ", (.. , , L1, L2, L3 .. - "" -, "", , L1, L2, L3, , , , ( , ))
  • ( )

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

, -, HTTP-, , , ( ). , 10k . , , - 10k . Java (-Xss) 256 . 10k 2 !!!!!!!! : - , , 2 . , , .

NIO, ( 1!) 10k, (.. CPU ) (.. ), , NIO.

+14

NIO IO concurrency, , , IO, , , , / .

+3

All Articles