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:  Introduction to Node.js and why it's faster than JavaNodeJs

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.

LessCSS pour la production avec node.js et npm | Tilap LessCSS est un framework simplifiant le travail au niveau CSS, en permettant l'utilisation de variables et fonctions grâce à une compilation javascript.Très pratique, il fait gagner en lisibilité et en rapidité de développement. Néanmoins, si pour le développement c'est un réel gain, en production ça l'est beaucoup moins : la feuille de style est interprétée en javascript à chaque affichage de page. Je vous propose donc ici l'installation et l'utilisation d'un compilateur, permettant une fois vos développements achevés, de compiler vos fichiers less en un css unique, avec en bonus la compression pour un maximum de performances. Installation de l'outillage L'installation et l'utilisation suivantes sont pour un système Debian/Ubuntu et nécessite l'ajout de repo tierce, ce qui peut dans certaines entreprises être une contrainte forte. Comme me l'a fait remarqué Dan Petty, les packages ne sont à ce jour pas disponibles sous ARM. Compilation Optimisation

Understanding node.js Node.js обычно вызывал у людей, которым я о нём рассказывал, две различные реакции. В основном они воспринимали его «как есть», однако многие были сбиты с толку. Если вы относитесь ко второй группе, я попробую объяснить, что же такое Node.js: Это инструмент командной строки. Вы скачиваете архив, компилируете и устанавливаете его.Это позволит вам выполнять программы на JavaScript, набрав 'node my_app.js' в терминале.JavaScript выполняется движком V8 (тем самым, благодаря которому так быстро работает Google Chrome).Node.js предоставляет API для доступа к сети и файловой системе из JavaScript.«Но я могу сделать то, что мне необходимо, с помощью Python, Ruby, Java, PHP,… !». Да, это я уже слышал. «Ближе к делу!» Хорошо. «Что?» Всё верно, всё выполняется параллельно, за исключением вашего кода. Каждый день начинается с того, что один слуга будит короля и спрашивает, нужно ли ему что-нибудь. Как только слуга завершает какую-то задачу, он приходит к царю и докладывает. Конечно. Вы это поняли!

StrongLoop | What Makes Node.js Faster Than Java? Every few weeks someone posts a Java vs Node benchmark, like PayPal’s or Joey Whelan’s. As one of maintainers of Node core and contributors to many npm modules, StrongLoop is happy to see Node winning lately. Everyone knows benchmarks are a specific measurement and don’t account for all cases. Sometimes Java is faster. High concurrency matters But there’s one thing we can all agree on: At high levels of concurrency (thousands of connections) your server needs to go to asynchronous non-blocking. While Java or Node or something else may win a benchmark, no server has the non-blocking ecosystem of Node.js today. Big companies, committed vendors and engaged community We’re going to help keep maturing Node and the ecosystem of tools and libraries as well. Use StrongOps to Monitor Node Apps Ready to start monitoring event loops, manage Node clusters and chase down memory leaks? Get trained in Node.js and API development Looking for Node.js and API development training? What’s next?

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

The Naked Technologist » ql.io and Node.js Article Now Available in August JSMag What is Node.js? | Charles Wang Node.js is an event-driven, non-blocking I/O model. It is a server side JavaScript environment that is based on the V8 JavaScript Engine developed by Google.The V8 JavaScript Engine allows Chrome to run Javascript code much faster. It is able to do this by compiling the JavaScript directly into native machine code. Other browsers interpret JavaScript, or execute it as byte code. What are some benefits for using JavaScript and node.js for server side programming? Both the front and back end of the a web application can be developed in the same languageminimize developer learning curvesminimize developer context switches What are modules in Node.js? Node uses modules which are libraries that extend its functionality. When should you use Node.js? You want to use Node.js in applications that require: Heavy I/OEvent-driven behaviorHigh Scalability (i.e. many clients)When your application requires a persistent connection to the server for connection to the server for continuous data transfer.

Related: