nodejs使用(1)安装

nodejs试用
===============
1,下载安装
./configure --prefix=/home/god/nodejs
make
make install

2,read doc
简单看一下安装后的目录结构,可以看见有许多python的代码
god@hanyh-laptop:~/nodejs$ ls -R
.:
bin include lib share

./bin:
node node-repl node-waf

./include:
node

./include/node:
config.h ev.h node_config.h node.h node_version.h v8.h
eio.h node_buffer.h node_events.h node_object_wrap.h v8-debug.h v8-profiler.h

./lib:
node

./lib/node:
wafadmin

./lib/node/wafadmin:
ansiterm.py Configure.py Environment.py Logs.py Options.py py3kfixes.py Scripting.py Task.py Utils.py
Build.py Constants.py __init__.py Node.py pproc.py Runner.py TaskGen.py Tools

./lib/node/wafadmin/Tools:
ar.py compiler_cxx.py dmd.py gdc.py icc.py libtool.py osx.py suncxx.py xlcxx.py
cc.py compiler_d.py d.py gnu_dirs.py icpc.py misc.py preproc.py unittestw.py
ccroot.py config_c.py gas.py gob2.py __init__.py nasm.py python.py winres.py
compiler_cc.py cxx.py gcc.py gxx.py intltool.py node_addon.py suncc.py xlc.py

./share:
man

./share/man:
man1

./share/man/man1:
node.1


设置路径:
======================================================
export PATH=$PATH:/home/god/nodejs/bin/

写入第一个例子:server1.js

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/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


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/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


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