Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node.js, toy or power tool ?

Node.js, toy or power tool ?

Node.js is a relatively newcomer in server side platforms but has garnered the attention of both developers and businesses. We will explore if it lives up to the hype, the ecosystem, where is it a good fit and where it falls short.

Ovidiu Dimulescu

October 06, 2012
Tweet

More Decks by Ovidiu Dimulescu

Other Decks in Technology

Transcript

  1. Node.js, toy or power tool?
    Jacksonville Code Camp, 2012
    Ovidiu Dimulescu
    @odimulescu
    speakerdeck.com/odimulescu

    View Slide

  2. • What problem?
    • How’s Node.js helping?
    • Use cases
    • Industry support
    • Coding in Node.js
    • Ecosystem
    • Questions ?
    Agenda

    View Slide

  3. About @odimulescu
    • Working on the Web since 1997

    • Organizer for JaxMUG.com
    • Co-Organizer for Jax Big Data meetup

    View Slide

  4. Node.js - What’s the problem?
    Fast CPUs Spinning wheels
    How do we saturate the CPU doing useful work?

    View Slide

  5. Node.js - How’s it helping?
    • Uses event-driven, non-blocking IO
    • Enforces async throughout*

    View Slide

  6. Multi-Threaded Servers
    *Credit: blog.cloudfoundry.com

    View Slide

  7. Node.js - Single Thread, Event-ed
    *Credit: blog.cloudfoundry.com

    View Slide

  8. Node.js - Concurrency
    Node.js Event Loop
    Rq1
    Rq2
    Rq1
    Rq2
    Green - Request Executing
    Red - IO wait

    View Slide

  9. Node.js - Concurrency
    Higher Concurrency
    Same Latency
    Thread
    Node.js

    View Slide

  10. Node.js - Been there, done that
    Event Machines
    • - Twisted
    • - EventMachine
    • - Mina, Netty, Atmosphere, vertx.io
    • - POE
    Others
    • Erlang
    • Scala / Akka

    View Slide

  11. Node.js - But ...
    They mix async with sync and the mentality is
    towards sync in libraries, drivers etc.

    View Slide

  12. • Proxy between different data layers
    • Soft real-time apps
    • Crawlers
    • CLI tools
    • Quick prototyping
    • Lower HW and Operational cost*
    Node.js - Use Cases

    View Slide

  13. • Culture mismatch
    • Uses Javascript
    • Requests are CPU intensive
    • Apps relies on specific libraries / functionality
    • Transactional systems
    Node.js - Not best fit

    View Slide

  14. Node.js - Industry Support

    View Slide

  15. Node.js - Industry Usage

    View Slide

  16. 1. Go to nodejs.org
    2. Download and run installer
    Node.js - Installation

    View Slide

  17. 1. Go to nodejs.org
    2. Download and run installer
    What’s included?
    node - binary
    npm - cli package manager
    built-in support for http, net, dns
    Node.js - Installation

    View Slide

  18. 1. Regular Installation
    2. Make it a service
    Windows - NSSM, srvany, etc.
    Unix - Distro dependent
    3. Front-end WS Integration
    IIS 7+ Integration - iisnode
    Apache - mod_proxy or mod_rewrite
    Nginx - rewrite or proxy
    HAProxy, stunnel
    Node.js - Server Installation

    View Slide

  19. Lowest privileges
    Unix: drop to non-root via setuid / setguid
    Front with a secure Proxy
    Enable safeguards
    “use strict”
    Node.js - Considerations

    View Slide

  20. CLI Version - helloworld.js
    console.log(“Hello world”);
    $ node helloworld.js
    Hello World
    Web Version
    Node.js - Hello World

    View Slide

  21. Web - Router Version
    Node.js - Hello World

    View Slide

  22. Node.js - I will call you back

    View Slide

  23. Node.js - When, then

    View Slide

  24. Serial independent
    Runs a series of functions one after the previous function completed
    Serial dependent
    Runs a series of functions passing previous results into next function
    Parallel fashion
    Runs a series of function in parallel
    Queue
    Runs a series of function in parallel up to desired concurrency
    Library Choices
    Async, Groupie, Step, Q, etc.
    Node.js - Flow libraries

    View Slide

  25. Module - mymodule.js
    Node.js - Modules
    Client mymodule_client.js

    View Slide

  26. Node.js - Modules
    require(‘mylib’) - Lookup order
    1. package.json -> ./lib/mylib.js
    2. index.js
    3. index.node
    package.json

    View Slide

  27. • console
    • log4js
    • Winston
    • GELF - Graylog Extended Log Format
    • Windows Event Log
    ...
    Node.js - Logging

    View Slide

  28. $ npm install node-inspector
    $ node --debug-brk myapp.js
    $ node --debug myapp.js
    debugger listening on port 5858
    $ node-inspector
    visit http://0.0.0.0:8080/debug?port=5858 to start debugging
    Debuggers
    WebKit based: Chrome
    Eclipse V8 Debugger Plugin, JetBrains WebStorm
    Other Tools
    v8-profiler, node-profiler
    nodetime.com
    Node.js - Debugging

    View Slide

  29. Node.js - Inspector

    View Slide

  30. Node.js - Debugging

    View Slide

  31. Database Drivers
    MS SQL, MongoDB, PostgreSQL, MySQL, Oracle, SQLite,
    Redis, CouchDB, Hive, Riak, Cassandra
    ORMs
    sequelize, persist, LazyBoy, Model, jugglingdb, node-orm
    Transactions, Connection Pooling
    node-mysql-queues
    Node.js - DB / ORM

    View Slide

  32. • Derby
    • Express
    • Flatiron
    • Meteor
    • Mojito
    • Tower
    ...
    Browserify - Node to Browser conversion
    Node.js - Web frameworks

    View Slide

  33. • assert - built in
    • API Easy
    • Cucumber
    • httpmock, nock, mockery
    • NodeUnit
    • Soda
    ...
    Node.js - Testing frameworks

    View Slide

  34. Node.js - Scaling out

    View Slide

  35. Node.js - Scaling out
    *Credit: blog.evantahler.com

    View Slide

  36. • Reuse existing JavaScript skill and code
    • Low resource usage
    • Performant VM (Google’s V8)
    • Active Community, Lots of resources
    • Package Manager
    • Enforces Async across
    • Quick Prototyping
    • Growing Industry support
    Node.js - Wrapping up

    View Slide

  37. Questions ?
    Ovidiu Dimulescu
    @odimulescu
    speakerdeck.com/odimulescu

    View Slide