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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值