[wp_pdfjs id=1058 ]
At the end of the talk I give some examples of which I think are particular good use cases for Node.js. I also make some notes about running Node in a productive environment.
Slide # 1
- Introduce Yourself 😉
- Henning Kropp @ GfK Nurago
- Who has NOT heard of Node.js before?
- Node.js is 5 years old
- Node.js hottest tech topic:
- We want to find out WHY?
- Aim of the Talk:
- Introduce Node.js
- Explain Event Driven / Event Loop
- Show Sample Use Cases
- Some Notes about Production Node
- What Do This Companies Have in Common?
- Remember the Browser Wars?
- Race for Fastest Runtime Environment / VM
- Other Platforms:
- Microsoft -> .Net
- Oracle -> Java/JVM
- Apple -> ObjectC
- Google -> Go and other???
- Nashorn Part of JDK8 (maybe)
- Chakra Part of Windows 8 and Windows RT
- At Nurago:
- …. Server Not so Much… 😦
- Last but not Least:
- Hundreds of Thousands of Websites Developed in JS
- Thousands of JS Developers
- Key Facts:
- Used and Backed by Key IT Companies
- Thousands of Developers
- Resources & Ecosystem
- A lot of Money and Man Years
- One Language Client/Server
- Douglas Crockford responsible for maturity
- JS the Good Parts the Only Book One should Read
- JSLint for Static Code Analysis
- Netscape Enterprise Server 1994
- Also IIS in 90s
- Since 2008 CommJS specification for not Browser
- Command line tools
- Desktop GUI-based applications
- Hybrid applications (Titanium, Adobe AIR)
- RingoJS -> Java Based
- Don’t Know Much About Jetpack
- AND NODE.JS
- Why Node?
- Event Driven
- Single Threaded!
- Need to Understand Modern Web requirements
- Need to Understand Non-Blocking
- Need to Understand Event Driven
- But Before that Have Some Look at Some Code
- Examples! Code!
- Node.js is Essentially About Networking!
- createServer() Does not Block
- Non-blocking thru Callbacks
- Callbacks, Functions First-Class Citizens in JS
- One of the Good Parts
- Running Apache Benchmark
- Able to Scale the Webserver on Laptop to 900 Concurrent
- Next: What Does Single Threaded Mean?
- Node.js is Single Threaded!
- How Does this Scale on my Laptop?
- Trying 10 con. Requests.
- What Time Do You Expect?
- Node is Blocking/Single Threaded
- Node API is Not Blocking
- File Read/Write … I/O
- Node Uses the Event Loop
- Next Simple REST
- Simple Example of REST
- Why Would We Need a Networking Framework?
- Why Event Driven?
- Have to Look at Modern Web Requirements!
- This is The Classic Web
- Process by Order
- Apache Spawns Process/Thread for Every Request
- Today Web is a Eventful Web
- User Want Imitate Responses
- Small but many Requests
- For example:
- Instant Search at Google
- Every Search at Google with Auto Completion Results in Multiple Requests
- User Expects this Behaviour
- Who Ever Had the Pleasure of Scaling a Web App Probably used NginX
- NginX and Node.js -> Event Driven!
- NEXT: Lets have a look at the Event Loop!
- Events are put on the Event Loop
- Like ‘onRequest‘
- One/Many Callbacks per Event
- A Thread waiting for Request
- If Requests Occurs, Callback is Run
- Than Response is Send to Client
- Everything (I/O) is Asynchronous
- File reads
- Database Access
- Callback Function is Used
- HOW IS DIFF FROM TRADITIONAL WEBSERVER?
- Event Loop @ a McDonalds
- Imagine Ur at the Counter Placing an Order
- Process/Thread = Cashier
- Cashier Taking Order and Waits for Burger and Fries
- One Process for one Order
- Only after Assemble Order finished -> Next Order/Customer
- Most the Time Waiting for Burger and Fries
- Apache Basically Works that Way
- While We wait for Burger People line Up
- All have to wait till Cashier is finished w/ One Order
- Who can We Scale This?
- We could Create hire more Processes
- Can get crowded behind the Counter
- Still Most of the Time Waiting
- What the Apache is Doing
- How Does McD Scale This, If a Order Takes Longer Than Certain Time?
- You get a Number!
- That’s Event Driven
- When the Burger is Ready Process Stops What he was Doing and Serves the Burger
- Process Does Not Wait
- Node is Useful for I/O!
- Network, Files, Databases …
- File Server for Example
- What of This Code is Async?
- What of This Code is Blocking?
- Where is the Event Loop Here?
- Node.js as a Proxy
- Most Popular Proxy Module is http-proxy
- nodejitsu.com Uses http-proxy
- Not very Readable Example, Lets Skip Details 😉
- Jsdom is Slow, Often Used PhantomJS
- Forever Restarts, and Detaches From Shell
- Cluster creates Worker for each CPU Core
- One Node Server/Thread per CPU Core
- Example later
- Cloud support with Windows Azure and nodjitsu and many more
- Node Production Environment Does Some Optimizations
- And Others
- Example of Cluster Usage
- All Workers Run on Same Port