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