9

I will soon be using a server named Undertow. The website says:

Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO

If Undertow allows non-blocking, is that the same as node.js? I don't mean the languages or anything like that. I have a separate project where I thought node.js would have been a good choice, but if I can use a single product for multiple projects it would be helpful.

EDIT: I found this question. Java NIO non-blocking mode vs node.js asychronous operation And I am starting to think I have confused things.

Community
  • 1
  • 1
johnny
  • 19,272
  • 52
  • 157
  • 259
  • Possible duplicate of [Java NIO non-blocking mode vs node.js asychronous operation](http://stackoverflow.com/questions/20740961/java-nio-non-blocking-mode-vs-node-js-asychronous-operation) – user207421 Feb 26 '16 at 23:53

2 Answers2

5

Undertow is based on the JBoss XNIO library and like Nodejs, XNIO relies on operating system capabilities (epoll or kqueue when available) to be notified for IO events (when data is available to read from a socket for example).

In Undertow, accepting incoming requests is done following this model, by the IO threads. Doing blocking operations on these threads would mean delaying the handling of new incoming requests. See Undertow's documentation on IO threads

Next to the IO threads, Undertow manages another thread pool, the Worker threads, to handle blocking tasks (think of tasks like calling a webservices or querying a database.) And this is what you wont get with Nodejs!

To use a Worker thread, the request handling has to be dispatched from the IO thread. The API is comprehensive and easy to use, again, see Undertow's documentation, as a starting point.

ant1g
  • 969
  • 9
  • 13
  • Do you mean using Undertow than Node.js I could process much more requests? What about memory utilization? – Carlos Alberto Apr 24 '17 at 20:19
  • No this is not what I mean. It is pretty much impossible to answer such question, it does not even really make sense. It all depends on what you do in these requests. What I am saying is that with Undertow you can use regular java threads - the worker threads (they map to kernel threads) to do blocking tasks (DB calls, file handling...), and this you can't do in Nodejs. With Nodejs you don't really have this concern of blocking tasks (if you know what you are doing) because most of the libraries you use will expect a callback to be called when the task is finished. – ant1g Apr 25 '17 at 20:51
0

From Wikipedia:

In computer science, asynchronous I/O, or non-blocking I/O is a form of input/output processing that permits other processing to continue before the transmission has finished.

Non-blocking and asynchronous are synonyms, and this is how all the standard node.js web servers work.

bolav
  • 6,938
  • 2
  • 18
  • 42
  • So do you think it is just a choice between environments? – johnny Feb 26 '16 at 21:26
  • Not at all. This just means that the different web servers are using the same technology for handling IO. There are still a lot of differences in functionality and performance. I do not have enough experience with the different servers to be able to recommend any of the options here. – bolav Feb 26 '16 at 21:43
  • Wikipedia wrong again. Asynchronous and non-blocking are two different models, not synonyms for each other. In non-blocking mode, the transfer is either complete or didn't happen when the I/O call returns. – user207421 Feb 26 '16 at 23:51
  • I fixed Wikipedia but failed to note it here. – user207421 Feb 05 '20 at 01:00