background preloader

Understanding the node.js event loop

Understanding the node.js event loop
So the largest waste with current programming technologies comes from waiting for I/O to complete. There are several ways in which one can deal with the performance impact (from Sam Rushing): The second basis thesis is that thread-per-connection is memory-expensive: [e.g. that graph everyone showns about Apache sucking up memory compared to Nginx] Apache is multithreaded: it spawns a thread per request (or process, it depends on the conf). You can see how that overhead eats up memory as the number of concurrent connections increases and more threads are needed to serve multiple simulataneous clients. There is no way of making code run in parallel within a single request. If you do that in one request, other requests can be processed just fine while the database is running it's sleep. Having asynchronous I/O is good, because I/O is more expensive than most code and we should be doing something better than just waiting for I/O. First-class functions. E.g. I really enjoyed your article. Ed, ed Related:  TUTORIELS, COURS, FORMATIONS ETC

Introduction - Chrome V8 Welcome to the developer documentation for V8. V8 is Google's open source, high performance JavaScript engine. It is written in C++ and is used in Google Chrome, Google's open source browser. This documentation is aimed at C++ developers who want to use V8 in their applications, as well as anyone interested in V8's design and performance. This document introduces you to V8, while the remaining documentation shows you how to use V8 in your code and describes some of its design details, as well as providing a set of JavaScript benchmarks for measuring V8's performance. About V8 V8 implements ECMAScript as specified in ECMA-262, 5th edition, and runs on Windows (XP or newer), Mac OS X (10.5 or newer), and Linux systems that use IA-32, x64, or ARM processors. V8 compiles and executes JavaScript source code, handles memory allocation for objects, and garbage collects objects it no longer needs. V8 enables any C++ application to expose its own objects and functions to JavaScript code.

Asynchronous Code Design with Node.js – Shine Solutions Group The asynchronous event-driven I/O of Node.js is currently evaluated by many enterprises as a high-performance alternative to the traditional synchronous I/O of multi-threaded enterprise application server. The asynchronous nature means that enterprise developers have to learn new programming patterns, and unlearn old ones. They have to undergo serious brain rewiring, possibly with the help of electroshocks. Start Rewiring To work with Node.js it is essential to understand how asynchronous programming works. Dependent and Independent Code Callback functions are the basic building block of asynchronous event-driven programming in Node.js. The following shows an example of how to switch a synchronous I/O operation to the asynchronous counterpart, and shows the use of the callback function. Synchronous Asynchronous var fs = require('fs'), processId; fs.readdir(" In the synchronous example the CPU waits at the fs.readdirSync() I/O operation, so this is the operation that needs to be changed.

Benchmarking Node.js - basic performance tests against Apache + PHP :: Change(b)log Several days ago I have done few very basic performance tests to see how node.js server behaves compared to Apache when serving very simple pages. All tests were executed on dual-core Intel T4200 2 GHZ machine with 4 GB RAM running Ubuntu 10.04 Lucid (with X). For comparison I have used node.js 0.1.103 on one side, and Apache 2.2.14 with prefork MPM and PHP 5.2.10 on the other, hitting them with ApacheBench 2.3 and total of 100,000 request with 1,000 concurrent requests during first test: ab -r -n 100000 -c 1000 <url> and then with total of 1,000,000 requests and 20,000 concurrent requests during the second one: ab -r -n 1000000 -c 20000 <url> Basic "Hello World" node.js server used for testing: and equally basic "Hello World" PHP file for Apache: Results 1) Total request: 100,000; concurrency level: 1,000 node.js results: Apache results: CPU Usage: node.js vs Apache/PHP in ApacheBench test - 100k requests, 1k concurrent requests 2) Total requests: 1,000,000; concurrency level: 20,000 Conclusions

Books and videos so you can easily learn Node.js programming By: +David Herron; Date: 2017-07-01 11:19 Tags: Have you heard about Node.js, but aren't sure what it is? Maybe you know about this exciting new software development platform, Node.js, but don't know where to start learning it? Node.js is an exciting new platform for developing web applications, application servers, any sort of network server or client, and general purpose programming. By supporting JavaScript on the server it means software teams can share code and ideas and methodologies between front-end and back-end. There is tremendous excitement about Node.js, and it's already widely used in production websites. Node.JS Web Development - Third Edition An excellent introduction to web application development in Node.js. NOTE -- I am the author of this book. Node.js in Action An example-driven tutorial on Node.js software development. Web Development with Node and Express: Leveraging the JavaScript Stack UDEMY: The Complete Node JS Developer Course UDEMY: Advanced Node.js Development

Slide - Cluster Node.JS - nodejs.org Un exécutable: node Un moteur performant: v8 Un cœur minimal: KISS Une API filesystem & network: HTTP/1.1 Mais surtout une API asynchrone et un single-thread event loop En tous cas c'est plus facile qu'Erlang, et vachement plus puissant que PHP Node.JS - Installation Node.JS - HTTP/1.1 Les navigateurs supportent tous partiellement HTTP/1.1. Un nouveau verbe: UPGRADE Le cache: ETag, If-Modified-Since Réseau: Connexions persistantes, Pipelining, Chunk Transfer Encoding... Node.JS supporte tout le protocole. Node.JS - Modules Don't Repeat Yourself Don't Reinvent the Wheel Learn 2 Search, mother fucker! Une implémentation de CommonJS: require() Un dépôt de modules: NPM Un dépôt de modules: NPM There's a module for that Node.JS - API asynchrone Single-Thread Event Loop: l'analogie du roi Le roi ordonne à ses messagers, qui reviennent dès qu'ils le peuvent, et le roi traite les réponses au fur et à mesure, une à la fois. Single-Thread et performances On y reviendra plus tard... Ted Dziuba

Felix's Node.js Guide Slide - Performances Node.JS - nodejs.org Un exécutable: node Un moteur performant: v8 Un cœur minimal: KISS Une API filesystem & network: HTTP/1.1 Mais surtout une API asynchrone et un single-thread event loop En tous cas c'est plus facile qu'Erlang, et vachement plus puissant que PHP Node.JS - Installation Node.JS - HTTP/1.1 Les navigateurs supportent tous partiellement HTTP/1.1. Un nouveau verbe: UPGRADE Le cache: ETag, If-Modified-Since Réseau: Connexions persistantes, Pipelining, Chunk Transfer Encoding... Node.JS supporte tout le protocole. Node.JS - Modules Don't Repeat Yourself Don't Reinvent the Wheel Learn 2 Search, mother fucker! Une implémentation de CommonJS: require() Un dépôt de modules: NPM Un dépôt de modules: NPM There's a module for that Node.JS - API asynchrone Single-Thread Event Loop: l'analogie du roi Le roi ordonne à ses messagers, qui reviennent dès qu'ils le peuvent, et le roi traite les réponses au fur et à mesure, une à la fois. Single-Thread et performances On y reviendra plus tard... Ted Dziuba

workshopper/learnyounode: Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.

Related: