![]() ![]() Basic Node.js architectureĪt a high level, Node.js combines the Google V8 JavaScript engine, a single-threaded non-blocking event loop, and a low-level I/O API. In 2019, the Node.js Foundation and JS Foundation merged to form the OpenJS Foundation. Node.js was also embraced as a Linux Foundation Collaborative Project. In 2015, the Node.js project was turned over to the Node.js Foundation, and became governed by the foundation’s technical steering committee. Joyent owned, governed, and supported the Node.js development effort for many years. A native Windows version of Node.js debuted in 2011. NPM, written by Isaac Schlueter, launched in 2010. The JavaScript-based Node.js platform was introduced in 2009, by Ryan Dahl, for Linux and MacOS, as a more scalable alternative to the Apache HTTP Server. Most prominently, the open-source Google Chrome V8 JavaScript engine, which does just-in-time compilation, inlining, and dynamic code optimization, can actually outperform C++ code for some loads, and outperforms Python for most use cases. That changed as several research efforts aimed at making JavaScript faster began to bear fruit. Initially, many programmers dismissed JavaScript as useless for “real work” because its interpreter ran an order of magnitude more slowly than compiled languages. In fact, the JavaScript language was actually based primarily on the Scheme and Self languages, with superficial Java-like semantics. The name JavaScript was chosen for marketing purposes, as Sun’s Java language was widely hyped at the time. A version of JavaScript for the Netscape Enterprise Server was introduced shortly afterwards. JavaScript was initially intended to enable animations and other manipulations of the browser document object model (DOM). In 1995 Brendan Eich, then a contractor to Netscape, created the JavaScript language to run in Web browsers-in 10 days, as the story goes. ![]() NPM, the Node package manager, is part of the standard Node.js installation, although it has its own website. Much of Node’s utility comes from its large package library, which is accessible from the npm command. Node.js incorporates the Google Chrome V8 JavaScript engine, which supports ECMAScript 2015 (ES6) syntax without any need for an ES6-to-ES5 transpiler such as Babel. You can use any language that transpiles to JavaScript, for example TypeScript and CoffeeScript. ![]() Also note that Node applications aren’t limited to pure JavaScript. Node.js turns out to be quite useful for desktop applications in addition to servers. Node’s approach to scaling with callback functions requires less memory to handle more connections than most competitive architectures that scale with threads, including Apache HTTP Server, the various Java application servers, IIS and ASP.NET, and Ruby on Rails. The callback function can handle requests with non-blocking I/O calls, and if necessary can spawn threads from a pool to execute blocking or CPU-intensive operations and to load-balance across CPU cores. It runs a single-threaded event loop registered with the system to handle connections, and each new connection causes a JavaScript callback function to fire. The presence of a large number of threads can cause a heavily loaded system to spend precious cycles on thread scheduling and context switching, which adds latency and imposes limits on scalability and throughput. While spawning threads incurs less memory and CPU overhead than forking processes, it can still be inefficient. Conceptually, this makes perfect sense, but in practice it incurs a great deal of overhead. In the traditional approach to creating web servers, for each incoming request or connection the server spawns a new thread of execution or even forks a new process to handle the request and send a response. ![]() In other words, Node.js wastes no time or resources on waiting for I/O requests to return. Node.js is a JavaScript runtime environment that achieves low latency and high throughput by taking a “non-blocking” approach to serving requests. Keeping the latency low and the throughput high while scaling up and out is not easy. Scalability, latency, and throughput are key performance indicators for web servers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |