设为首页 收藏本站
查看: 967|回复: 0

[经验分享] nodejs使用(1)安装

[复制链接]

尚未签到

发表于 2017-2-21 10:08:44 | 显示全部楼层 |阅读模式
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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-345119-1-1.html 上篇帖子: nodejs和npm入门 下篇帖子: nodejs websocket html5 实时
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表