If a web server is non-blocking, does this mean it is handling IO the same as node.js?

醉酒当歌 提交于 2019-12-21 10:17:54

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/35660710/if-a-web-server-is-non-blocking-does-this-mean-it-is-handling-io-the-same-as-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!