Node.js是什麼?

Node.js是一個服務器端程序,運程V8 Javascript,也就是服務器端的JavaScript。

傳統服務器(如Apache, Tomcat) 每接受一個連接,將爲其分配一個線程。這樣每臺服務器同時處理的連接就受到很大的限制,假如一臺服務器內存爲8GB,一個線程分配2M,那爲同時處理的連接數大約爲4000左右。

Node.js改變了這種連接方式,而使用了事件驅動。新的連接到來時會在Node引擎中註冊一個事件,而不是創建一個新的線程。Node.js沒有鎖的概念,所以永遠不會死鎖,同時可以支持數萬個連接。


What problem does Node solve?

Node's stated number one goal is "to provide an easy way to build scalable network programs". What's the issue with current server programs? Let's do the math. In languages like Java™ and PHP, each connection spawns a new thread that potentially has an accompanying 2 MB of memory with it. On a system that has 8 GB of RAM, that puts the theoretical maximum number of concurrent connections at about 4,000 users. As your client-base grew, if you wanted your web application to support more users, you had to add more and more servers. Of course, this adds to a business's server costs, traffic costs, labor costs, and more. Adding to those costs are the potential technical issues — a user can be using different servers for each request, so any shared resources have to be shared across all the servers. For all these reasons, the bottleneck in the entire web application architecture (including traffic throughput, processor speed, and memory speed) was the maximum number of concurrent connections a server could handle.

Node solves this issue by changing how a connection is made to the server. Instead of spawning a new OS thread for each connection (and allocating the accompanying memory with it), each connection fires an event run within the Node engine's process. Node also claims that it will never deadlock, since there are no locks allowed, and it doesn't directly block for I/O calls. Node claims that a server running it can support tens of thousands of concurrent connections.

So, now that you have a program that can handle tens of thousands of concurrent connections, what can you actually build with Node? It would be awesome if you had a web application that required this many connections. That's one of those "if you have this problem, it's not a problem" kind of problems. Before we get to that, let's look at how Node works and how it's designed to run.

http://www.ibm.com/developerworks/opensource/library/os-nodejs/#N10084





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章