var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
运行:
god@hanyh-laptop:~/nodejs/work$ node server1.js
Server running at http://127.0.0.1:8124/
ab压力测试
====================================================
nodejs的数据
==========================================
god@hanyh-laptop:~/nodejs/work$ ab -c 50 -n 10000 http://127.0.0.1:8124/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8124
Document Path: /
Document Length: 12 bytes
Concurrency Level: 50
Time taken for tests: 1.694 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 760000 bytes
HTML transferred: 120000 bytes
Requests per second: 5903.01 [#/sec] (mean)
Time per request: 8.470 [ms] (mean)
Time per request: 0.169 [ms] (mean, across all concurrent requests)
Transfer rate: 438.11 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 9
Processing: 0 8 4.5 8 37
Waiting: 0 8 4.4 8 37
Total: 1 8 4.4 8 37
Percentage of the requests served within a certain time (ms)
50% 8
66% 10
75% 11
80% 11
90% 14
95% 17
98% 21
99% 22
100% 37 (longest request)
nginx的数据
==========================================
god@hanyh-laptop:~/nodejs/work$ ab -c 50 -n 10000 http://127.0.0.1:7000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Server Software: nginx/0.7.67
Server Hostname: 127.0.0.1
Server Port: 7000
Document Path: /
Document Length: 151 bytes
Concurrency Level: 50
Time taken for tests: 1.086 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3622534 bytes
HTML transferred: 1511057 bytes
Requests per second: 9205.48 [#/sec] (mean)
Time per request: 5.432 [ms] (mean)
Time per request: 0.109 [ms] (mean, across all concurrent requests)
Transfer rate: 3256.56 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 1.2 2 9
Processing: 1 3 1.1 3 9
Waiting: 0 2 1.0 2 9
Total: 3 5 2.0 4 14
Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 7
80% 8
90% 9
95% 9
98% 9
99% 10
100% 14 (longest request)
RPS和nginx相差只30%左右,性能相当惊人
基本设计
=================================
不用线程解决并发问题,线程难度大且有些问题性能不好
简化的事件模型,没有一个显式的start-the-event-loop过程,类似浏览器的一样隐藏事件模型,脚本启动后就自动进入事件模型状态
多核的支持:多进程。The fundamentals of scalable systems are fast networking and non-blocking design—the rest is message passing. In future versions, Node will be able to fork new processes