Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS non blocking IO and other frameworks like ASP.NET MVC not-blocking io via async/await [closed]

What difference between node.js non-blocking model and ASP.NET MVC non-blocking async/await with Tasks ? i meant they successfully solving the same problem in the same way or i missed something ? I think other framework have had the same solution before node ?

like image 442
Ark Avatar asked May 02 '15 17:05

Ark


2 Answers

At a high level, they are equivalent, with one major difference. In Node, all requests are handled on the same thread; whereas in ASP.NET, all requests are handled by the thread pool. Node is a single-threaded asynchronous approach, while ASP.NET is a multi-threaded asynchronous (or synchronous) approach.

For this reason, Node cannot handle synchronous APIs at all, and if there is an API that should be asynchronous but isn't, Node will pretend it's asynchronous by pushing it onto a thread pool thread so that the main thread can continue handling other requests.

In contrast, ASP.NET is multithreaded from the get-go, so pushing synchronous work onto a thread pool thread is an anti-pattern in that environment.

In theory, this would imply that ASP.NET is more scalable on a multi-core server, but AFAIK no one has proven/disproven that. One mitigating approach that Node servers can use is to run multiple copies of Node on the same server, along with a load balancer (nginx, or just another copy of Node). However, any shared state / caches are forced to be out-of-proc at that point.

Regarding which one was "first" to support asynchrony, I'd bet probably ASP.NET. ASP.NET has supported asynchrony since it's first release, and MVC added support in 2.0 IIRC. However, it's not until the recent release of .NET 4.5 with async and await that asynchrony has become (relatively) easy; before that, most companies did not deem it worth the complexity.

like image 62
Stephen Cleary Avatar answered Oct 15 '22 08:10

Stephen Cleary


From what I gather, the only difference is in Node.js, non-blocking is the only way to do I/O. Whereas in .NET you can block threads if you really want to. There may be legitimate reasons for this, btw. But, in Node.js you don't really have this option.

like image 35
beautifulcoder Avatar answered Oct 15 '22 10:10

beautifulcoder