SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Server-Side JavaScript
                  Developement
                      Node.JS Quick Tour

                     q3boy <q3boy1@gmail.com>
                       from http://cnodejs.org/




10年12月22日星期三
Server-Side JavaScript
                   Development
10年12月22日星期三
先驱


               Aptana Jaxer (SpiderMonkey)




                     Helma (Rhino)


10年12月22日星期三
问题
               • 缺乏统一标准
               • 技术生态圈的问题


10年12月22日星期三
Revelutions in 2009
          •    CommonJS (ServerJS), by Dangoor

          •    JSConf, by Chris Williams & Iterative Designs

          •    Node, by Ray Dahl.

10年12月22日星期三
Node's goal is to provide an easy
               way to build scalable network
               programs

                                  -- nodejs.org



10年12月22日星期三
Ray Dahl
10年12月22日星期三
发展历史

               • 1/5/2009 Ryah Dahl 提出项目构想
               • 2/15/2009 项目启动
               • 5/31/2009 发布初始版本
               • ......
               • 11/16/2010 v0.3.1 发布

10年12月22日星期三
社区与生态圈

               • 目前在官方wiki上有近600个module
               • 超过20位活跃的开发者
               • 每天都在进步


10年12月22日星期三
基础库

               • libev (event loop)
               • libeio (nonblocked posix, thread pool)
               • v8 (javascript engine by google)


10年12月22日星期三
核心思想

               • 非阻塞
               • 单线程
               • 事件驱动


10年12月22日星期三
传统模式下的io操作




                程序逻辑需要等待io操作完成



10年12月22日星期三
非阻塞io操作




               利用io操作的等待时间做其它工作



10年12月22日星期三
单线程 - 优势

               • 程序逻辑简单
               • 系统资源占用低
               • 无通信与锁开销带来高性能


10年12月22日星期三
单线程 - 劣势

               • 一个程序仅能在一个cpu上运行

               • 一旦程序异常将导致整个进程崩溃


10年12月22日星期三
解决方案 - Web Worker
10年12月22日星期三
性能
               • AMD Opteron 2200 单核, 4G RAM
               • socket client 20,000+ qps
               • socket server 17,000 qps
               • http server 4,400 qps
               • 内存消耗 30~40m
               • see more. <http://nodejs.kongwu.net/blog/?
                 p=8>


10年12月22日星期三
一些限制

               • SSL支持不够成熟
               • Windows
               • 1G 堆栈内存限制(by v8)


10年12月22日星期三
适用场景

               • Web框架
               • 大并发负载中间层服务
               • Spider


10年12月22日星期三
Digg in the node
10年12月22日星期三
安装

               $ git clone git://github.com/ry/node.git
               $ cd node
               $ ./configure --prefix=$HOME/node
               $ make install



10年12月22日星期三
Hello World!




               Familiar & Simple


10年12月22日星期三
单线程
                 $ node singleThread.js
                 1
                 2
                 3
                 4




10年12月22日星期三
CommonJS




               $ node CommonJS.js
               foobar

10年12月22日星期三
非阻塞io




               $ node nonblocking.js
               Reading my.txt ...
               my.txt
               Here is contents in "my.txt".
10年12月22日星期三
HTTP服务




10年12月22日星期三
TCP服务
                   $ node tcpServer.js &
                   $ telnet locahost 1234
                   Welcome!
                   > Node is so Cooool.
                   Node is so Cooool.
                   >




10年12月22日星期三
文件监听



               $ node watchFile.js &
               $ sleep 3; touch my.txt
               the current mtime is: 1292594780000
               the previous mtime was: 1292594752000

10年12月22日星期三
子进程




               $ node childProcess.js
               hello
               world
10年12月22日星期三
String vs Buffer

               高负载时String带来的问题

               • 内存开销较大
               • node不能直接得到v8中String的指针,在
                socket操作时需要执行memcopy

               • 高负载时v8的gc对性能的影响

10年12月22日星期三
String vs Buffer




                   With String
10年12月22日星期三
String vs Buffer




                   With Buffer
10年12月22日星期三
带来的性能改进




                 With String
10年12月22日星期三
带来的性能改进




                 With Buffer
10年12月22日星期三
Want to see more?
10年12月22日星期三
包管理

               • PHP: pear
               • Python: PyPI, setuptools
               • Ruby: Gems

               • Node:

10年12月22日星期三
安装与使用
               $ cat >>~/.npmrc <<NPMRC
               root = ~/.node_libraries
               binroot = ~/bin
               manroot = ~/share/man
               NPMRC
               $ curl http://npmjs.org/install.sh | sh


               $ npm ls
               $ npm install package_name
               $ npm update


10年12月22日星期三
IDE base on node




                http://www.cloud9ide.com/



10年12月22日星期三
Links
               • http://www.commonjs.org/
               • http://nodejs.org/
               • http://howtonode.org/
               • https://github.com/ry/node/wiki
               • https://github.com/ry/node/wiki/modules
               • https://github.com/isaacs/npm
10年12月22日星期三
10年12月22日星期三
Node in Taobao
               •   UED
                   •   nodejs-kissy by 拔赤<bachi@taobao.com>
               •   EDP
                   •   http://cnodejs.org/ (致力于在国内推广node技术, coming
                       soon)
                   •   node-reverse-proxy (超轻型反向代理, 支持轮循, coming
                       soon)
                   •   node-myfox (mysql分布式集群 2011 Q1)
                   •   node-glider (多数据源的数据中间层服务 2011 Q2)
                   •   node-kvproxy (key-value集群访问代理 2011 Q2)



10年12月22日星期三
10年12月22日星期三

Weitere ähnliche Inhalte

Andere mochten auch

López vidal isaac angel
López vidal isaac angelLópez vidal isaac angel
López vidal isaac angelIsaac López
 
Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...
Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...
Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...Spazio Giovani onlus
 
Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...
Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...
Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...MARY VERA
 
ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber
ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber
ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber OECD Environment
 
Presentacion pnfs inicial- 19-9
Presentacion pnfs  inicial- 19-9Presentacion pnfs  inicial- 19-9
Presentacion pnfs inicial- 19-9irenelicia
 
Emerging Countries Care through the digital hospital
Emerging Countries Care through the digital hospital Emerging Countries Care through the digital hospital
Emerging Countries Care through the digital hospital MEDx eHealthCenter
 
Powerpoint mangement thème iii icemba 2016
Powerpoint mangement thème iii icemba  2016Powerpoint mangement thème iii icemba  2016
Powerpoint mangement thème iii icemba 2016sciafrique
 
Cours les instument d'urbanisme Programmation urbaine
Cours les instument d'urbanisme Programmation urbaineCours les instument d'urbanisme Programmation urbaine
Cours les instument d'urbanisme Programmation urbaineArchi Guelma
 
Marzo pasa la_voz inicial rincones
Marzo pasa la_voz inicial rincones Marzo pasa la_voz inicial rincones
Marzo pasa la_voz inicial rincones MARY VERA
 
Breakout D summary slides CCXG GF September 2016
Breakout D summary slides CCXG GF September 2016 Breakout D summary slides CCXG GF September 2016
Breakout D summary slides CCXG GF September 2016 OECD Environment
 
Digital hospitals market report sweden_20151215
Digital hospitals market report sweden_20151215Digital hospitals market report sweden_20151215
Digital hospitals market report sweden_20151215Business Finland
 
Session 2 - Presentation by Dermott Crombie on behalf of Paul Camuti
Session 2 - Presentation by Dermott Crombie on behalf of Paul CamutiSession 2 - Presentation by Dermott Crombie on behalf of Paul Camuti
Session 2 - Presentation by Dermott Crombie on behalf of Paul CamutiOECD Environment
 
Orientaciones Didácticas para el Nivel Inicial-Parte 6-
Orientaciones Didácticas para el Nivel Inicial-Parte 6-Orientaciones Didácticas para el Nivel Inicial-Parte 6-
Orientaciones Didácticas para el Nivel Inicial-Parte 6-Rincones del Jardin
 

Andere mochten auch (18)

Recursos naturales
Recursos naturalesRecursos naturales
Recursos naturales
 
López vidal isaac angel
López vidal isaac angelLópez vidal isaac angel
López vidal isaac angel
 
Tajmahal
TajmahalTajmahal
Tajmahal
 
Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...
Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...
Incontro di orientamento con genitori delle scuole Croce - Faré Lissone 15 ot...
 
Motores electricos (1)
Motores electricos (1)Motores electricos (1)
Motores electricos (1)
 
Robots ch
Robots chRobots ch
Robots ch
 
Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...
Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...
Guia didactica de estrategias para el desarrollo de la ciencia en educacion-i...
 
ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber
ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber
ENV GLOBAL FORUM OCT 2016 - Session 2 - K. Habtegaber
 
Presentacion pnfs inicial- 19-9
Presentacion pnfs  inicial- 19-9Presentacion pnfs  inicial- 19-9
Presentacion pnfs inicial- 19-9
 
Emerging Countries Care through the digital hospital
Emerging Countries Care through the digital hospital Emerging Countries Care through the digital hospital
Emerging Countries Care through the digital hospital
 
Powerpoint mangement thème iii icemba 2016
Powerpoint mangement thème iii icemba  2016Powerpoint mangement thème iii icemba  2016
Powerpoint mangement thème iii icemba 2016
 
Cours les instument d'urbanisme Programmation urbaine
Cours les instument d'urbanisme Programmation urbaineCours les instument d'urbanisme Programmation urbaine
Cours les instument d'urbanisme Programmation urbaine
 
Marzo pasa la_voz inicial rincones
Marzo pasa la_voz inicial rincones Marzo pasa la_voz inicial rincones
Marzo pasa la_voz inicial rincones
 
Breakout D summary slides CCXG GF September 2016
Breakout D summary slides CCXG GF September 2016 Breakout D summary slides CCXG GF September 2016
Breakout D summary slides CCXG GF September 2016
 
Digital hospitals market report sweden_20151215
Digital hospitals market report sweden_20151215Digital hospitals market report sweden_20151215
Digital hospitals market report sweden_20151215
 
Session 2 - Presentation by Dermott Crombie on behalf of Paul Camuti
Session 2 - Presentation by Dermott Crombie on behalf of Paul CamutiSession 2 - Presentation by Dermott Crombie on behalf of Paul Camuti
Session 2 - Presentation by Dermott Crombie on behalf of Paul Camuti
 
Possible ways ahead
Possible ways aheadPossible ways ahead
Possible ways ahead
 
Orientaciones Didácticas para el Nivel Inicial-Parte 6-
Orientaciones Didácticas para el Nivel Inicial-Parte 6-Orientaciones Didácticas para el Nivel Inicial-Parte 6-
Orientaciones Didácticas para el Nivel Inicial-Parte 6-
 

Ähnlich wie Node.js Quick Tour

Zh120226techparty jeff kit-ios-toolbox
Zh120226techparty jeff kit-ios-toolboxZh120226techparty jeff kit-ios-toolbox
Zh120226techparty jeff kit-ios-toolboxZoom Quiet
 
Android vs e pub
Android vs e pubAndroid vs e pub
Android vs e pub永昇 陳
 
Full stack-development with node js
Full stack-development with node jsFull stack-development with node js
Full stack-development with node jsXuefeng Zhang
 
Nodejs介绍
Nodejs介绍Nodejs介绍
Nodejs介绍myzykj
 
那些年,我們一起用過的 Xcode
那些年,我們一起用過的 Xcode那些年,我們一起用過的 Xcode
那些年,我們一起用過的 XcodeMikimoto Chuang
 
Node js实践
Node js实践Node js实践
Node js实践myzykj
 
KISSY 1.3-released
KISSY 1.3-releasedKISSY 1.3-released
KISSY 1.3-releasedyiming he
 
何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)
何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)
何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)Xu Wang
 
WOT Cloud Computing Architect Summit
WOT Cloud Computing Architect SummitWOT Cloud Computing Architect Summit
WOT Cloud Computing Architect SummitDocker, Inc.
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJSTechParty@UIC
 
这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkitLainZQ
 
敏捷模式下的百度研发基础环境建设 1
敏捷模式下的百度研发基础环境建设 1敏捷模式下的百度研发基础环境建设 1
敏捷模式下的百度研发基础环境建设 1drewz lin
 
Douban qcon2009 beijing
Douban qcon2009 beijingDouban qcon2009 beijing
Douban qcon2009 beijingdrewz lin
 
Websocket talk in nodejs.tw
Websocket talk in nodejs.twWebsocket talk in nodejs.tw
Websocket talk in nodejs.twHsu Ping Feng
 
[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例YC Ling
 
Artifacts management with CI and CD
Artifacts management with CI and CDArtifacts management with CI and CD
Artifacts management with CI and CDChen-Tien Tsai
 
OpenLab.Taipei #2 PORTA2030
OpenLab.Taipei #2 PORTA2030OpenLab.Taipei #2 PORTA2030
OpenLab.Taipei #2 PORTA2030Rex Tsai
 
July.2011.w3ctech
July.2011.w3ctechJuly.2011.w3ctech
July.2011.w3ctechKai Cui
 
SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践lifesinger
 

Ähnlich wie Node.js Quick Tour (20)

Zh120226techparty jeff kit-ios-toolbox
Zh120226techparty jeff kit-ios-toolboxZh120226techparty jeff kit-ios-toolbox
Zh120226techparty jeff kit-ios-toolbox
 
Android vs e pub
Android vs e pubAndroid vs e pub
Android vs e pub
 
Full stack-development with node js
Full stack-development with node jsFull stack-development with node js
Full stack-development with node js
 
Nodejs介绍
Nodejs介绍Nodejs介绍
Nodejs介绍
 
那些年,我們一起用過的 Xcode
那些年,我們一起用過的 Xcode那些年,我們一起用過的 Xcode
那些年,我們一起用過的 Xcode
 
Node js实践
Node js实践Node js实践
Node js实践
 
KISSY 1.3-released
KISSY 1.3-releasedKISSY 1.3-released
KISSY 1.3-released
 
何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)
何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)
何时浮云散尽(在北邮北邮纪阳老师移动互联网课程上的讲义)
 
WOT Cloud Computing Architect Summit
WOT Cloud Computing Architect SummitWOT Cloud Computing Architect Summit
WOT Cloud Computing Architect Summit
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit
 
敏捷模式下的百度研发基础环境建设 1
敏捷模式下的百度研发基础环境建设 1敏捷模式下的百度研发基础环境建设 1
敏捷模式下的百度研发基础环境建设 1
 
Douban qcon2009 beijing
Douban qcon2009 beijingDouban qcon2009 beijing
Douban qcon2009 beijing
 
Websocket talk in nodejs.tw
Websocket talk in nodejs.twWebsocket talk in nodejs.tw
Websocket talk in nodejs.tw
 
Kubernetes on gcp
Kubernetes on gcpKubernetes on gcp
Kubernetes on gcp
 
[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例
 
Artifacts management with CI and CD
Artifacts management with CI and CDArtifacts management with CI and CD
Artifacts management with CI and CD
 
OpenLab.Taipei #2 PORTA2030
OpenLab.Taipei #2 PORTA2030OpenLab.Taipei #2 PORTA2030
OpenLab.Taipei #2 PORTA2030
 
July.2011.w3ctech
July.2011.w3ctechJuly.2011.w3ctech
July.2011.w3ctech
 
SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践
 

Node.js Quick Tour

  • 1. Server-Side JavaScript Developement Node.JS Quick Tour q3boy <q3boy1@gmail.com> from http://cnodejs.org/ 10年12月22日星期三
  • 2. Server-Side JavaScript Development 10年12月22日星期三
  • 3. 先驱 Aptana Jaxer (SpiderMonkey) Helma (Rhino) 10年12月22日星期三
  • 4. 问题 • 缺乏统一标准 • 技术生态圈的问题 10年12月22日星期三
  • 5. Revelutions in 2009 • CommonJS (ServerJS), by Dangoor • JSConf, by Chris Williams & Iterative Designs • Node, by Ray Dahl. 10年12月22日星期三
  • 6. Node's goal is to provide an easy way to build scalable network programs -- nodejs.org 10年12月22日星期三
  • 8. 发展历史 • 1/5/2009 Ryah Dahl 提出项目构想 • 2/15/2009 项目启动 • 5/31/2009 发布初始版本 • ...... • 11/16/2010 v0.3.1 发布 10年12月22日星期三
  • 9. 社区与生态圈 • 目前在官方wiki上有近600个module • 超过20位活跃的开发者 • 每天都在进步 10年12月22日星期三
  • 10. 基础库 • libev (event loop) • libeio (nonblocked posix, thread pool) • v8 (javascript engine by google) 10年12月22日星期三
  • 11. 核心思想 • 非阻塞 • 单线程 • 事件驱动 10年12月22日星期三
  • 12. 传统模式下的io操作 程序逻辑需要等待io操作完成 10年12月22日星期三
  • 13. 非阻塞io操作 利用io操作的等待时间做其它工作 10年12月22日星期三
  • 14. 单线程 - 优势 • 程序逻辑简单 • 系统资源占用低 • 无通信与锁开销带来高性能 10年12月22日星期三
  • 15. 单线程 - 劣势 • 一个程序仅能在一个cpu上运行 • 一旦程序异常将导致整个进程崩溃 10年12月22日星期三
  • 16. 解决方案 - Web Worker 10年12月22日星期三
  • 17. 性能 • AMD Opteron 2200 单核, 4G RAM • socket client 20,000+ qps • socket server 17,000 qps • http server 4,400 qps • 内存消耗 30~40m • see more. <http://nodejs.kongwu.net/blog/? p=8> 10年12月22日星期三
  • 18. 一些限制 • SSL支持不够成熟 • Windows • 1G 堆栈内存限制(by v8) 10年12月22日星期三
  • 19. 适用场景 • Web框架 • 大并发负载中间层服务 • Spider 10年12月22日星期三
  • 20. Digg in the node 10年12月22日星期三
  • 21. 安装 $ git clone git://github.com/ry/node.git $ cd node $ ./configure --prefix=$HOME/node $ make install 10年12月22日星期三
  • 22. Hello World! Familiar & Simple 10年12月22日星期三
  • 23. 单线程 $ node singleThread.js 1 2 3 4 10年12月22日星期三
  • 24. CommonJS $ node CommonJS.js foobar 10年12月22日星期三
  • 25. 非阻塞io $ node nonblocking.js Reading my.txt ... my.txt Here is contents in "my.txt". 10年12月22日星期三
  • 27. TCP服务 $ node tcpServer.js & $ telnet locahost 1234 Welcome! > Node is so Cooool. Node is so Cooool. > 10年12月22日星期三
  • 28. 文件监听 $ node watchFile.js & $ sleep 3; touch my.txt the current mtime is: 1292594780000 the previous mtime was: 1292594752000 10年12月22日星期三
  • 29. 子进程 $ node childProcess.js hello world 10年12月22日星期三
  • 30. String vs Buffer 高负载时String带来的问题 • 内存开销较大 • node不能直接得到v8中String的指针,在 socket操作时需要执行memcopy • 高负载时v8的gc对性能的影响 10年12月22日星期三
  • 31. String vs Buffer With String 10年12月22日星期三
  • 32. String vs Buffer With Buffer 10年12月22日星期三
  • 33. 带来的性能改进 With String 10年12月22日星期三
  • 34. 带来的性能改进 With Buffer 10年12月22日星期三
  • 35. Want to see more? 10年12月22日星期三
  • 36. 包管理 • PHP: pear • Python: PyPI, setuptools • Ruby: Gems • Node: 10年12月22日星期三
  • 37. 安装与使用 $ cat >>~/.npmrc <<NPMRC root = ~/.node_libraries binroot = ~/bin manroot = ~/share/man NPMRC $ curl http://npmjs.org/install.sh | sh $ npm ls $ npm install package_name $ npm update 10年12月22日星期三
  • 38. IDE base on node http://www.cloud9ide.com/ 10年12月22日星期三
  • 39. Links • http://www.commonjs.org/ • http://nodejs.org/ • http://howtonode.org/ • https://github.com/ry/node/wiki • https://github.com/ry/node/wiki/modules • https://github.com/isaacs/npm 10年12月22日星期三
  • 41. Node in Taobao • UED • nodejs-kissy by 拔赤<bachi@taobao.com> • EDP • http://cnodejs.org/ (致力于在国内推广node技术, coming soon) • node-reverse-proxy (超轻型反向代理, 支持轮循, coming soon) • node-myfox (mysql分布式集群 2011 Q1) • node-glider (多数据源的数据中间层服务 2011 Q2) • node-kvproxy (key-value集群访问代理 2011 Q2) 10年12月22日星期三