Node.js: Difference between revisions

Content deleted Content added
Overview: running a browser to execute server code is just a bad hack
Tag: references removed
AnomieBOT (talk | contribs)
Rescuing orphaned refs ("node_cluster_module_doc" from rev 1252607916)
Line 240:
A thread pool handles the execution of parallel tasks in Node.js. The main thread function call posts tasks to the shared task queue, which threads in the thread pool pull and execute. Inherently non-blocking system functions such as networking translate to kernel-side non-blocking sockets, while inherently blocking system functions such as file I/O run in a blocking way on their own threads. When a thread in the thread pool completes a task, it informs the main thread of this, which in turn, wakes up and executes the registered callback.
 
A downside of this single-threaded approach is that Node.js does not allow [[vertical scaling]] by increasing the number of [[CPU core]]s of the machine it is running on without using an additional module, such as cluster,<ref name="node_cluster_module_doc">{{cite web |title=Node.js's cluster module |url=https://nodejs.org/api/cluster.html |access-date=19 October 2017 |website=nodejs.org}}</ref> StrongLoop Process Manager,<ref>{{Cite web|url=http://strong-pm.io/|title=StrongLoop Process Manager|website=strong-pm.io}}</ref> or pm2.<ref>{{cite web|url=https://github.com/Unitech/pm2|title=GitHub - Unitech/pm2: Production process manager for Node.js applications with a built-in load balancer|work=GitHub|date=12 June 2021}}</ref> However, developers can increase the default number of threads in the libuv thread pool. The server [[operating system|operating system (OS)]] is likely to distribute these threads across multiple cores.<ref>{{cite web|url=http://www.future-processing.pl/blog/on-problems-with-threads-in-node-js/|title=On problems with threads in node.js - Future Processing|author=Aleksander Kasiuk|date=22 April 2015}}</ref> Another problem is that long-lasting computations and other CPU-bound tasks freeze the entire event-loop until completion.{{citation needed|date=March 2017}}
 
=== V8 ===