Node.JS 简述

node.js 是什么?

 

  • 一个为可伸缩的服务器端和网络应用设计的完整的软件平台
  • 开源项目
  • 和JavaScript的解析器绑定
  • 该平台能在多数主流的系统工作

成功案例?

怎么工作?

  • 基于Chrome的V8 JavaScript runtime,可方便地构建快速,可扩展的网络应用 

 

  • 采用事件驱动,非阻塞I/ O模型,使得它轻便,高效,完美的跨分布式设备运行数据密集型的实时应用

总体结构

两个主要组件

  • Main core, 由 C 和 C++编写
  • Modules, 诸如 Libuv library 和 V8 runtime engine, 也是由C++编写
  • 由一个主线程来处理所有请求
  • API in JavaScript
  • 通过node绑定服务器端操作
  • 依赖谷歌的V8引擎 
  • Libuv负责异步I / O和事件循环

v8 runtime engine

  • 即时编译器,用C ++编写
  • 编译器,优化和垃圾收集器组成

libuv

  • 负责Node的异步I / O操作
  • 包含固定大小的线程池

主要特征

单线程

  • 大多数其他类似的web平台是多线程
  • 随着每一个新的要求,会产生新的堆分配
  • 有序处理每一个请求

事件驱动

  • Typically implemented using library sand a block call, but Node is non-blocking throughout!
  • Implemented using language construct
  • Automatically terminated
  • Tightly coupled to V8 engine

非阻塞IO

  • 所有请求会被暂时存储在堆
  • 请求会有顺序被处理
  • 可以支持约1,000,000次并发请求 

一个简单的🌰

Title Text

Subtitle

Subtitle

优势分析

  • Because of its single-threaded, non-blocking scheme, Node can Asynchronous, event-based scheme allows for scalability, lower
  • support nearly 1 million concurrent connections
  • memory usage & CPU overhead  Can be used to implement an entire JavaScript-based web application Requests are acknowledged quickly due to asynchronous nature Native JSON handling Easy RESTful services Speedy native bindings in C Due to its real-time nature, it’s possible to process files while they are being uploaded

 

适用场景

  • REST + JSON APIs Backend for single-page web apps with same language for client • Quick prototyping Rapidly evolving applications: media sites, marketing, etc. Chat applications Ideal for computing and orchestration tasks divided using worker processes

劣势

Node & V8 runtime engine are tightly coupled Because it is single-threaded, it has a single point of failure for all • requests (low fault-tolerance) • • • Developers beware of exception handling Currently lacking standards regarding code quality Without a complete v1.0, backwards-compatibility is bogging down code base​

不适用的场景

  • CPU-bound tasks • Applications needing to process large amounts of data in parallel, • unless using worker processes

nodejs展望

Subtitle

Made with Slides.com