SlideShare a Scribd company logo
1 of 107
Download to read offline
Becoming a Node.js ninja on
   Cloud Foundry
   Patrick Chanezon, Senior Director, Developer Relations
   chanezonp@vmware.com, @chanezon
   With slides from Raja Rao DV




  March 2012               www.cloudfoundry.com
                                                            © 2009 VMware Inc. All rights reserved

Wednesday, March 28, 12
P@ in a nutshell

                          • French, based in San Francisco
                          • Senior Director, Developer Relations,VMware
                          • Software Plumber, API guy, mix of Enterprise and
                          Consumer
                                  • 18 years writing software, backend guy with a
                                  taste for javascript
                                  • 2 y Accenture (Notes guru), 3 y Netscape/AOL
                                  (Servers, Portals), 5 y Sun (ecommerce, blogs,
                                  Portals, feeds, open source)
                          • 6 years at Google, API guy (first hired, helped start the
                          team)
                                  • Adwords, Checkout, Social, HTML5, Cloud


Wednesday, March 28, 12
Sketching Things



   Slender clouds. On the pavilion a small rain.
   Noon, but I’m too lazy to open the far cloister.
   I sit looking at moss so green my clothes are soaked with color.
     Wang Wei (699-759)




    3

Wednesday, March 28, 12
Taking a Nap by a Mountain Window



   Resting my body in a monk’s cloud chamber, my dreams relax.
   Pine trees and cranes rise between screen and pillow.
   A beautiful pheasant makes a long song.
   My hand pushes the window, and the mountain fill my eyes.
        Zhu Yunming (1461-1527)




    4

Wednesday, March 28, 12
Looking for the Hermit and Not Finding Him



   Beneath a pine I question a boy.
   He says, “Master has gone to gather herbs somewhere on the
   mountain
   but who knows where? The clouds are deep.”
        Jiao Dao (778-841)




    5

Wednesday, March 28, 12
Looking for the Hermit and Not Finding Him


   Lu mountain stands beside the Southern Dipper
   In clouds reaching silken like a nine-panelled screen
   With its shadows in a crystal lake deepening the green water.
   The Golden Gate opens into two mountain ranges.
   Li Bai (701-762)




    6

Wednesday, March 28, 12
Agenda
     1.   About Node.js
          •   Internal working of Node.js
          •   Buzz around Node.js
          •   Who is using it
          •   What kind of apps are being built

     2.   Coding in Node.js
          •   Sync v/s Async coding (Callbacks)
          •   Classes & Modules (CommonJS)
          •   Node.js EventEmitters
          •   npm & package.json

     3.   Node.js & Cloud Foundry (w/ demo)
          •   Hello World app in Cloud Foundry
          •   Using Sticky Sessions
          •   CloudFoundry Module & connecting to Redis, MongoDB etc.
          •   Express.js (RESTful) app
          •   Socket.io + Express.js (Real-time) app

     4.   Final demo
          •    An sample app that uses concepts & modules talked above




    7

Wednesday, March 28, 12
About Node.js



   Node.js is a non-blocking, event-driven I/O platform that is built on
   Google Chrome’s v8 engine.

   -    It is ~80% C/C++ & ~20% JS (APIs)
   -    Uses CommonJS module system.
   -    Executes JavaScript on the server
   -    Built by Ryan Dahl
   -    Sponsored by Joyent

                                                              Ryan Dahl
                                                            (Node.js creator)




    8

Wednesday, March 28, 12
What is the biggest advantage of Node.js?




                      Biggest thing Node.js brings to the table
                        (other than JS) is savings in I/O cost




    9

Wednesday, March 28, 12
The cost of I/O




                          http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/



    10

Wednesday, March 28, 12
So how does Node.js save I/O cost?




                          Node.js saves I/O cost by implementing
                           Non-blocking, event driven I/O model




    11

Wednesday, March 28, 12
Event-driven, non-blocking I/O platform/server


 What exactly is a event-driven, non-blocking server?

 How is it different from a multi-threaded server?



                           Multi-threaded blocking server
                                         v/s
                          Event-driven, non-blocking server




    12

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection




                                                                      DB




                                                                      FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1
                                                                      DB




                                                                      FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                                                      DB




                                                                      FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                      DB




                                                                      FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB

                                                                Blocking




                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2
                                                                Blocking




                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request
                                                                Blocking




                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking




                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3
 Refreshes 2 times


                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3
 Refreshes 2 times


                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3
 Refreshes 2 times


                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3
 Refreshes 2 times


                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3   T4
 Refreshes 2 times


                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3   T4
 Refreshes 2 times


                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3   T4 T5
 Refreshes 2 times


                                                                           FS


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3   T4 T5
 Refreshes 2 times



       User4                                                               FS
 refreshes 3 times


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3   T4 T5
 Refreshes 2 times



       User4                                  T6                           FS
 refreshes 3 times


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3   T4 T5
 Refreshes 2 times



       User4                                  T6                           FS
 refreshes 3 times


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                           DB
      User2               i/o request         T2
                                                                Blocking
       User3                                  T3   T4 T5
 Refreshes 2 times



       User4                                  T6                           FS
 refreshes 3 times


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                            DB
      User2               i/o request         T2
                                                                 Blocking
       User3                                  T3   T4 T5
 Refreshes 2 times



                                              T6   T7 T8                    FS
       User4                                                T9
 refreshes 3 times


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1               i/o request
                                              T1
                                                                            DB
      User2               i/o request         T2
                                                                 Blocking
                                                                   I/O
       User3                                  T3   T4 T5
 Refreshes 2 times



                                              T6   T7 T8                    FS
       User4                                                T9
 refreshes 3 times


                                               Multi threaded
                                                   server
      T   Thread




    13

Wednesday, March 28, 12
Multi-threaded server - Threads are spawned for every connection



      User1                          i/o request
                                                                  T1
                                                                                                DB
      User2                          i/o request                  T2
                                                                                     Blocking
                                                                                       I/O
       User3                                                      T3   T4 T5
 Refreshes 2 times



                                                                  T6   T7 T8                    FS
       User4                                                                    T9
 refreshes 3 times


                                                                   Multi threaded
                                                                       server
      T   Thread
                          Because every I/o is blocking,
                          server spawns a thread per connection
                          to support multiple requests




    13

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                    JS                  C/C++



                                           T1
                                                                                   DB
                                           V8
                                                Event loop
                                                (Libev)


                                                                             t2
                                                                       t1Libio
                                                                        POSIX
                                                Single                   Asynct4
                                                thread                 t3
                                                                       Threads
                                                serves                      t6
                                                all users              t5
                                                                             t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                             Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                  C/C++


                                                                              DB
                                           Event loop
                                           (Libev)


                                                                        t2
                                                                  t1Libio
                                                                   POSIX
                                           Single                   Asynct4
                                           thread                 t3
                                                                  Threads
                                           serves                      t6
                                           all users              t5
                                                                        t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                        Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                    JS                  C/C++


                                                                                   DB
                                                Event loop
                                                (Libev)


                                                                             t2
                                                                       t1Libio
                                                                        POSIX
                                                Single                   Asynct4
                                                thread                 t3
                                                                       Threads
                                                serves                      t6
                                                all users              t5
                                           T1                                t7    FS
                                           V8



    T1    JS Thread running
    V8    your code (Single threaded)
                                                             Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                  C/C++


                                                                              DB
                                           Event loop
                                           (Libev)


                                                                        t2
                                                                  t1Libio
                                                                   POSIX
                                           Single                   Asynct4
                                           thread                 t3
                                                                  Threads
                                           serves                      t6
                                           all users              t5
                                                                        t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                        Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                  C/C++


                                                                              DB
                                           Event loop
                                           (Libev)


                                                                        t2
                                                                  t1Libio
                                                                   POSIX
                                           Single                   Asynct4
                                           thread                 t3
                                                                  Threads
                                           serves                      t6
                                           all users              t5
                                                                        t7    FS


                                                T1
    T1    JS Thread running                     V8
    V8    your code (Single threaded)
                                                        Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                  C/C++


                                                                              DB
                                           Event loop
                                           (Libev)


                                                                        t2
                                                                  t1Libio
                                                                   POSIX
                                           Single                   Asynct4
                                           thread                 t3
                                                                  Threads
                                           serves                      t6
                                           all users              t5
                                                                        t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                        Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                   C/C++


                                                                               DB
                                           Event loop
                                           (Libev)


                                                                         t2
                                                                   t1Libio
                                                                    POSIX
                                           Single                    Asynct4
                                           thread                  t3
                                                                   Threads
                                           serves       T1              t6
                                           all users    V8         t5
                                                                         t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                         Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                  C/C++


                                                                              DB
                                           Event loop
                                           (Libev)


                                                                        t2
                                                                  t1Libio
                                                                   POSIX
                                           Single                   Asynct4
                                           thread                 t3
                                                                  Threads
                                           serves                      t6
                                           all users              t5
                                                                        t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                        Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                  C/C++


                                                                              DB
                                                        T1
                                           Event loop   V8
                                           (Libev)


                                                                        t2
                                                                  t1Libio
                                                                   POSIX
                                           Single                   Asynct4
                                           thread                 t3
                                                                  Threads
                                           serves                      t6
                                           all users              t5
                                                                        t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                        Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                  C/C++


                                                                              DB
                                           Event loop
                                           (Libev)


                                                                        t2
                                                                  t1Libio
                                                                   POSIX
                                           Single                   Asynct4
                                           thread                 t3
                                                                  Threads
                                           serves                      t6
                                           all users              t5
                                                                        t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                        Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                               JS                      C/C++

                                                       T1
                                                       V8
                                                                                  DB
                                           Event loop
                                           (Libev)


                                                                            t2
                                                                      t1Libio
                                                                       POSIX
                                           Single                       Asynct4
                                           thread                     t3
                                                                      Threads
                                           serves                          t6
                                           all users                  t5
                                                                            t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                            Node.js

   t1         POSIX threads doing
         t2
              async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                          JS                      C/C++

                                                                  T1
        User1                           i/o request               V8
                                                                                             DB
                                                      Event loop
                                                      (Libev)


                                                                                       t2
                                                                                 t1Libio
                                                                                  POSIX
                                                      Single                       Asynct4
                                                      thread                     t3
                                                                                 Threads
                                                      serves                          t6
                                                      all users                  t5
                                                                                       t7    FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                                       Node.js

   t1           POSIX threads doing
         t2
                async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                          JS                         C/C++

                                                                  T1
        User1                           i/o request               V8
                                                                                                          DB
                                                      Event loop
                                                      (Libev)


                                                                  delegate i/o to               Non-blocking
                                                                                          t2       I/O
                                                                      libeio        t1Libio
                                                                                     POSIX
                                                      Single                          Asynct4
                                                      thread                        t3
                                                                                    Threads
                                                      serves                             t6
                                                      all users                     t5
                                                                                          t7              FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                                       Node.js

   t1           POSIX threads doing
         t2
                async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                          JS                         C/C++

                                                                  T1
        User1                           i/o request               V8
                                                                                                          DB
                                                      Event loop
        User2                           i/o request   (Libev)


                                                                  delegate i/o to               Non-blocking
                                                                                          t2       I/O
                                                                      libeio        t1Libio
                                                                                     POSIX
                                                      Single                          Asynct4
                                                      thread                        t3
                                                                                    Threads
                                                      serves                             t6
                                                      all users                     t5
                                                                                          t7              FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                                       Node.js

   t1           POSIX threads doing
         t2
                async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                          JS                         C/C++

        User1                           i/o request
                                                                                                          DB
                                                      Event loop
        User2                           i/o request   (Libev)


                                                                  delegate i/o to               Non-blocking
                                                                                          t2       I/O
                                                                      libeio        t1Libio
                                                                                     POSIX
                                                      Single                          Asynct4
                                                      thread                        t3
                                                                                    Threads
                                                      serves                             t6
                                                      all users                     t5
                                                                                          t7              FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                                       Node.js

   t1           POSIX threads doing
         t2
                async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                               JS                         C/C++

        User1                           i/o request
                                                                                                               DB
                                                           Event loop
        User2                           i/o request        (Libev)

                                                      T1               delegate i/o to               Non-blocking
                                                                                               t2       I/O
                                                      V8                   libeio        t1Libio
                                                                                          POSIX
                                                           Single                          Asynct4
                                                           thread                        t3
                                                                                         Threads
                                                           serves                             t6
                                                           all users                     t5
                                                                                               t7              FS



    T1    JS Thread running
    V8    your code (Single threaded)
                                                                            Node.js

   t1           POSIX threads doing
         t2
                async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                                JS                         C/C++

         User1                           i/o request
                                                                                                                DB
                                                            Event loop
         User2                           i/o request        (Libev)

                                                       T1               delegate i/o to               Non-blocking
                                                                                                t2       I/O
                                                       V8                   libeio        t1Libio
       User3                                                                               POSIX
 Refreshes 2 times                                          Single                          Asynct4
                                                            thread                        t3
                                                                                          Threads
                                                            serves                             t6
                                                            all users                     t5
                                                                                                t7              FS



    T1     JS Thread running
    V8     your code (Single threaded)
                                                                             Node.js

    t1           POSIX threads doing
          t2
                 async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                                JS                           C/C++

         User1                           i/o request
                                                                                                                  DB
                                                            Event loop
         User2                           i/o request        (Libev)

                                                       T1               delegate i/o to                 Non-blocking
                                                                                                  t2       I/O
                                                       V8                   libeio          t1Libio
       User3                                                                                 POSIX
 Refreshes 2 times                                          Single                            Asynct4
                                                            thread                          t3
                                                                                            Threads
                                                            serves                                t6
                                                            all users                       t5
                                                                                                   t7             FS
                                                                                  i/o result returned
                                                                                   2 EL after x time

    T1     JS Thread running
    V8     your code (Single threaded)
                                                                             Node.js

    t1           POSIX threads doing
          t2
                 async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                                JS                           C/C++

         User1                           i/o request
                                                                                                                  DB
                                                            Event loop
         User2                           i/o request        (Libev)

                                                       T1               delegate i/o to                 Non-blocking
                                                                                                  t2       I/O
                                                       V8                   libeio          t1Libio
       User3                                                                                 POSIX
 Refreshes 2 times                                          Single                            Asynct4
                                                            thread                          t3
                                                                                            Threads
                                                            serves                                t6
                                                            all users                       t5
       User4
 refreshes 3 times
                                                                                                   t7             FS
                                                                                  i/o result returned
                                                                                   2 EL after x time

    T1     JS Thread running
    V8     your code (Single threaded)
                                                                             Node.js

    t1           POSIX threads doing
          t2
                 async I/O (multi-threaded)
   t3


    14

Wednesday, March 28, 12
Non-blocking & Evented I/O (Node.js server)

                                                                           JS                           C/C++

         User1                           i/o request
                                                                                                                             DB
                                                                       Event loop
         User2                           i/o request                   (Libev)

                                                                  T1               delegate i/o to                 Non-blocking
                                                                                                             t2       I/O
                                                                  V8                   libeio          t1Libio
       User3                                                                                            POSIX
 Refreshes 2 times                                                     Single                            Asynct4
                                                                       thread                          t3
                                                                                                       Threads
                                                                       serves                                t6
                                                                       all users                       t5
       User4
 refreshes 3 times
                                                                                                              t7             FS
                                                                                             i/o result returned
                                                                                              2 EL after x time

    T1     JS Thread running
    V8     your code (Single threaded)
                                                                                        Node.js

    t1           POSIX threads doing
          t2
                 async I/O (multi-threaded)
   t3                                         Everything except your (JS) code is runs in parallel (by libio)


    14

Wednesday, March 28, 12
Event-driven, non-blocking I/O server



 Real-world example of the two models?


                     Multi-threaded blocking server (Apache)
                                        v/s
                     Event-driven, non-blocking server (Nginx)




    15

Wednesday, March 28, 12
Apache V/s Nginx: performance




                             Reqs/sec v/s concurrent connections


                          At ~4000 concurrent connections,
                          - Nginx can serve ~9000 reqs/sec
                          - Apache can serve ~3000 reqs/sec
                          Ref: http://blog.webfaction.com/a-little-holiday-present


    16

Wednesday, March 28, 12
Apache V/s Nginx: Memory usage




                                 Memory v/s concurrent connections


                               At ~4000 concurrent connections,
                               - Nginx uses 3MB memory
                               - Apache uses 40MB memory
                          Ref: http://blog.webfaction.com/a-little-holiday-present

    17

Wednesday, March 28, 12
Saving I/O is great, what else is happening w/ Node.js?




         Let’s look at community, libraries, buzz around Node.js




    18

Wednesday, March 28, 12
Other things going on for Node.js

                          2nd most popular watched on git




    19

Wednesday, March 28, 12
Other things going on for Node.js

                                   8,000+ libraries/modules/servers




                                        High-level library categories
     Web frameworks        Oracle                           Multiple protocols          Command Line Option Parsers
                           NoSQL and Key/Value              HTTP                        Parser Generators
     Routers
                           Mongo                            FTP                         Other Parsers
     Static file servers                                                                Debugging / Console Utilities
                           Hive                             E-mail
     Microframeworks       Redis                            XMPP                        Compression
     Frameworks                                                                         Graphics
                           CouchDB                          Other networking            Sound
     Middleware            Other NoSQL implementations      RPC                         Payment Gateways
     JSGI                  Miscellaneous and multiple DB    Web Sockets & Ajax          API clients
     Connect               Templating                       Message Queues              Control flow / Async goodies
     Other middleware      CSS Engines                      Class systems               I18n and L10n modules
                           Content Management Systems       Testing / Spec Frameworks   Boilerplates
     Other                 Build and Deployment             Wrappers                    Continuous Integration Tools
     Database              Package Management Systems       Parsers                     DDD, CQRS, EventSourcing
     MS SQL Server         Module Loader                    JSON                        Desktop application related
                           OpenSSL / Crypto / Hashing       XML                         JavaScript threads
     PostgreSQL                                                                         Other
     MySQL                 SMTP
     SQLite                TCP / IP


                                    https://github.com/joyent/node/wiki/modules



    20

Wednesday, March 28, 12
Other things going on for Node.js

      Node in Production!
            •   LinkedIn, Yahoo!, Microsoft, eBay, Twitter etc.
            •   >1000 other companies/startups are using it in production

      All kinds of interesting apps:
            End-user apps:
            • Real-time apps
            • Mobile apps
            • CRMs, Web sites etc. etc.

            Platform apps (Servers / Services):
            • Node-http-proxy - Node.js implementation of reverse proxy like nginx
            • Ldapjs – - Node.js implementation of LDAP server itself
            • SMTP – Node.js implementation of SMTP server itself
            • XMPP, SSH, RPC, many more.




    21

Wednesday, March 28, 12
Agenda – part 2
     1.   About Node.js
          •   Internal working of Node.js
          •   Buzz around Node.js
          •   Who is using it
          •   What kind of apps are being built

     2.   Coding in Node.js
          •   Sync v/s Async coding (Callbacks)
          •   Classes & Modules (CommonJS)
          •   Node.js EventEmitters
          •   npm & package.json

     3.   Node.js & Cloud Foundry
          •   Hello World app in Cloud Foundry
          •   Using Sticky Sessions
          •   CloudFoundry Module & connecting to Redis, MongoDB etc
          •   Express.js (RESTful) app
          •   Socket.io + Express.js (Real-time) app

     4.   Demo
          •  An sample app that uses concepts & modules talked above




    22

Wednesday, March 28, 12
Let’s look at the code..




 How does async code differ from sync(regular) code?




                               Synchronous code
                                      v/s
                              Asynchronous Code




    23

Wednesday, March 28, 12
Callbacks – Control flow
   Use case: Let’s say we have an item’s id and want to get its name from DB and print it


  //Synchronous & blocking code               //Async & non-blocking code
  function getItemNameById(id) {              function getItemNameById(id, callback) {
        //blocks or waits for DB                      db.get(id, callback); //step 2
          return db.get(id); //step 2                 //nothing is returned here
  }                                           }

  var name = getItemNameById(100); //step 1   //step 3
                                              Some internal function calls the callback w/ result
  //print name in step 3
  console.log(name); //step 3                 //You create a callback helper function
                                              function displayHelperCallback(name) {
                                                      console.log(name); //step 4
                                              }

 Things to note:                              //pass callback function to consume the result
                                              getItemNameById(100, displayHelperCallback); //step 1
 1. Async code doesn’t directly ‘return’
    anything
 2. Instead, it takes a function(callback)
    & calls that function when result
    becomes available



    24

Wednesday, March 28, 12
Callbacks – Control flow (detailed version in Node.js)
  //YOUR APP
  var db = require(‘db’);
  function getItemNameById(id, callback) {
           db.get(id, callback); //step 2
  }

  //You create a callback helper function
  function displayHelperCallback(name) {
           console.log(name); //step 103
  }

  //pass callback function to consume the result                      //step 5
  getItemNameById(100, displayHelperCallback); //step 1
                                                                      V8 is free to run other functions in the event-
                                                                      loop.
  //INTERNALS OF A DB LIBRARY (HIGH LEVEL)
                                                                      //step 5, step 6 ..step 100
  function db() {                                                     Say v8 notices 95 other things to do (in the
    this.dbConnection = net.connection(); // connects to DB           event loop), it starts executing them one by
  }                                                                   one.
  db.prototype.get = function(id, callback) {
     var self = this; //step 3
     this.dbConnection.write(id, function(result) { //step 4          At some point b/w step 3 and step 100,
                                                             Step 5   returns result & asks to run
        self. receiveFromDB(result, callback);//step 101
    });                                                               dbConnection.write’s callback.
  }
                                                                      This event goes to the back of the queue as
  db.prototype.receiveFromDB = function(result, callback) {           step 101
    callback(result); //Execute callback step step 102
  }


     25

Wednesday, March 28, 12
Node.js




 How can I better organize my code?




                          Classes & CommonJS module




    26

Wednesday, March 28, 12
JavaScript Classes (Prototypical inheritance)

  //JavaScript prototypical inheritance          Node.js also provides handy util.inherits function to
                                                 inherit.
  //Super Class                                  - This also provides ‘subclass.super_’ to access
  function Automobile(license, model) {             super class’ functions
    this.license = license;
    this.model = model;                          var require(‘util’); //import util module
  }
                                                 //Super Class
  Automobile.prototype.getModel = function() {   function Automobile(license, model) {
    return model;                                  this.license = license;
  }                                                this.model = model;
                                                 }
  //Sub class
  function Car(license, model) {                 Automobile.prototype.getModel = function() {
    Automobile.call(this, license, model);         return model;
  }                                              }

  Car.prototype = new Automobile();              //Sub class
  Car.prototype.constructor = Car;               function Car(license, model) {
                                                   Automobile.call(this, license, model);
                                                 }

                                                 util.inherits(Car, Automobile);




    27

Wednesday, March 28, 12
CommonJS modules

 //Automobile.js file                                      Things to note:
 function Automobile(license, model) {                     1. Allows keeping JS code in separate
   this.license = license;                                    files
   this.model = model;
 }
                                                           2. Use “exports.<name>” to export
 Automobile.prototype.getModel = function() {                 something
   return model;
 }                                                         1. Use require(‘path/to/module’) to
 exports.Automobile = Automobile;                             import it

                                                           2. use require(‘module’).<name> to
                                                              access things inside module
 //Car.js file
 var util = require('util');
 var module = require('./Automobile');
 var Automobile = module.Automobile;

 function Car(license, model) {
         Automobile.call(this, license, model);
 }

 util.inherits(Car, Automobile);

 console.log(new Car("1232", "BMW").model); //prints BMW



    28

Wednesday, March 28, 12
CommonJS modules: Exporting multiple things

 //myModule.js file                                           Things to note:
 exports.myFunction = function () {                           1. You can directly export function,
   return ‘hi there’;                                            arrays, variables
 }
 exports.myArray = [‘foo’, ‘bar’];
                                                              2. You can export multiple things from
 exports.myVariable = ‘I’m a variable’;                          one file using ‘exports’



 //app.js file
 var myModule = require('./myModule');

 console.log(myModule.myFunction()); //prints ‘’hi there’
 console.log(myModule.myArray[1]); //prints ‘bar’
 console.log(myModule.myVariable); //prints I’m a variable’




    29

Wednesday, March 28, 12
CommonJS modules: ‘exports’ v/s ‘module.exports’

 //myModule.js file                                         Things to note:
 module.exports = function () {                                 If you want to export only one
   return ‘hi there’;                                           thing.. so that it can be used
 }                                                              directly by the recepient, you can
                                                                use..
                                                                module.exports = <something>;

                                                                Warning:
                                                                If you use both module.exports
 //app.js file                                                  and exports.bla, exports.bla will
 var myFunction = require('./myModule');                        NOT be exported(ignored)

 console.log(myModule.myFunction()); //prints ‘’hi there’




    30

Wednesday, March 28, 12
Node.js EventEmitter (A utility class that allows emitting events)




 EventEmitter class implements Observer pattern and provides on and emit
 APIs
 • It is used when creating(not using) an async library.



                            Node.js EventEmitter




    31

Wednesday, March 28, 12
Events – Node.js EventEmitter                     (A node.js utility class that allows emitting events)


  //Simplified EventEmitter (Observer pattern)

  function EventEmitter() {
    //store events and callbacks like {event1: [callback1, callback2] , event2 : [cb3, cb4]…}
    this.eventNameAndCallbackList = {};
  }

  //Allow others to add a callback(function) for a event name(string)
  EventEmitter.prototype.on = function(eventName, callback) {
     //add eventName and callback to eventNameAndCallbackList
  };

  //When an event is emitted, call each callbacks in a loop
  EventEmitter.prototype.emit = function(eventName) {
    for(var i =0; i < currentCallbacks.length ; i++) {
           currentCallbacks[i](); //call each callback
     }
  };

  exports.EventEmitter = EventEmitter;




    32

Wednesday, March 28, 12
Events – Node.js EventEmitter (continued)

   Say you are writing an I/O library & writing readFromDB function but don’t know how to handle
   async DB result.

   You can solve it by..
   1. Inheriting your class from EventEmitter
   2. Then you can use its ‘emit’ function to an event when data arrives (asynchronously)
   3. You ask people who’ll be using your library to implement ‘on’ function

                          //myIOModule.js
                          var util = require('util');
                          var events = require('events');

                          //myIOClass is a subclass of events.EventEmitter class
                          var MyIOClass = function () {
                            events.EventEmitter.call(this);
                          };
                          util.inherits(MyIOClass, events.EventEmitter);

                          MyIOClass.prototype.readFromDB = function(query){
                                 // <--reads data code here -->
                                 this.emit('data', "some data");
                          }
                          exports.MyIOClass = MyIOClass; //export the class




    33

Wednesday, March 28, 12
Events – Node.js EventEmitter (continued)


   Say you are an end-user trying to use DB library to read result from DB..

   1. You’ll have to implement ‘on’ function for the given event name (‘data’) and set a callback
   2. DB libraries internal function will call your callback when the result comes back


                          //app.js
                          var myIOModule = require('./myIOModule');

                          var myIOClass = new myIOModule.MyIOClass();
                          myIOClass.on('data', function (data) {
                            console.log(data);
                          });

                          myIOClass.readFromDB('select * from users');




    34

Wednesday, March 28, 12
Events – A library can emit multiple events

            I/O libraries usually emit multiple events.. connected,
            disconnected, error, ready, data, result etc.

            //So you can listen to all of them..
            function myFunction() {
               db.on(‘error’, function(e) {
                 console.error(e);
              });

              db.on(‘connect’, function() { //db is connected
                db.query(user);
             });
              db.on(‘disconnect’, function(){
               console.log(‘db disconnected’);
             });

                db.connect(‘127.0.0.1’, ‘100’);
            }

    35

Wednesday, March 28, 12
Events – Error/Exception handling

            //Say there was an exception trying to connect to db.
            Function () {
              try {
                 db.connect(‘127.0.0.1’, ‘4000’); // failed to connect; connectionException
               } catch (e) {
                 console.error(e);
               }
            }

            Above try/catch won’t handle it because the act of connection itself is an i/o



            //Say there was an exception trying to connect to db.
            Function () {
              //Typically I/O libraries triggers ‘error’ event. We’ll need to listen to that event
              db.on(‘error’, function(e) {
                 console.error(e);
              });

                db.connect(‘127.0.0.1’, ‘100’); // failed to connect; connectionException
            }




    36

Wednesday, March 28, 12
Installing external modules – npm (Node Package Manager)

    Use npm (Node Package Manager) to install modules         Things to note:
    npm install <moduleName>                                  1. npm = Node Package Manager
    e.x. npm install express                                  2. It is a CLI to install modules from
                                                              3. Using package.json is preferred
    Modules are copied into ./node_modules folder
    /myapp
    /myapp/node_modules/express                               1. Need to be careful about versions

                                                              2. You need to have all the modules
                                                                    pre-installed (i.e. npm install)
    //Instead keep ALL dependencies in package.json file in
    root of your app and run:                                       before uploading your app to
    npm install                                               Cloud Foundry

    //package.json
    {
      "name": ”MyApp",
      "description": ”My awesome twitter app",
      "version": "2.5.8",
      "author": ”Raja<rajar@vmware.com>",
      "dependencies": {
        "express": “2.3.4”,
        "mime": "",
        "connect-redis": ">= 0.0.1"
      }
    }


    37

Wednesday, March 28, 12
Installing external modules - npm & package.json

    Use npm (Node Package Manager) to install modules         Things to note:
    npm install <moduleName>                                  1. npm = Node Package Manager
    e.x. npm install express                                  2. It is a CLI to install modules from
                                                              3. Using package.json is preferred
    Modules are copied into ./node_modules folder
    /myapp
    /myapp/node_modules/express                               1. Need to be careful about versions

                                                              2. You need to have all the modules
                                                                    pre-installed (i.e. npm install)
    //Instead keep ALL dependencies in package.json file in
    root of your app and run:                                       before uploading your app to
    npm install                                               Cloud Foundry

    //package.json
    {
      "name": ”MyApp",
      "description": ”My awesome twitter app",
      "version": "2.5.8",
      "author": ”Raja<rajar@vmware.com>",
      "dependencies": {
        "express": “2.3.4”,
        "mime": "",
        "connect-redis": ">= 0.0.1"
      }
    }


    38

Wednesday, March 28, 12
Agenda – part 3
     1.   About Node.js
          •   Internal working of Node.js
          •   Buzz around Node.js
          •   Who is using it
          •   What kind of apps are being built

     2.   Coding in Node.js
          •   Sync v/s Async coding (Callbacks)
          •   Classes & Modules (CommonJS)
          •   Node.js EventEmitters
          •   npm & package.json

     3.   Node.js & Cloud Foundry (w/ demo)
          •   Cloud Foundry – Open PaaS
          •   Hello World app in Cloud Foundry
          •   Scaling - Using Sticky Sessions
          •   CloudFoundry Module & connecting to Redis, MongoDB etc
          •   Express.js (RESTful) app
          •   Socket.io + Express.js (Real-time) app

     4.   Demo
          •  An sample app that uses concepts & modules talked above



    39

Wednesday, March 28, 12
Cloud Foundry




                 Cloud Foundry – Open Platform as a Service




    40

Wednesday, March 28, 12
What is Cloud Computing?




                  Cloud According to my daughter Eliette (10 years old)

  41


Wednesday, March 28, 12
Cloud Stack - Classic Pyramid




                                  Software
                                 As A Service


                            Platform As A Service



                          Infrastructure As A Service




  42


Wednesday, March 28, 12
Cloud Stack - By Value




                               Software
                              As A Service




                          Platform As A Service




                               Infrastructure
                               As A Service




  43


Wednesday, March 28, 12
Agility as a survival skill

   § Consumer software is becoming like fashion
       • Phone apps, social apps, short lifetime, fast lifecycles
       • Ab testing
   § Clay shirky situational apps
   § Kent Beck, Usenix 2011 Talk, “Software G-Forces”
       change in software process when frequency grows
   § Cloud Platforms enables an Agile culture, driver for innovation
       • Scalability is built in the platforms
       • Can iterate faster
       • Focus on design
   § Cloud Platforms lets developers focus on driving business value




  44


Wednesday, March 28, 12
Platforms


   § Raise the Unit of currency to be application & services instead of
        infrastructure
   § Google App Engine, Cloud Foundry, Joyent, Heroku, Stax
        (Cloudbees), Amazon elastic beanstalk, Microsoft Azure, AppFog
   §   Single or a few languages, services
   §   Start of Multi language Polyglot platforms
   §   Enabler for Agile Developers -> Create Business value faster
   §   Lack of standards: risk, vendor lock-in
   §   Enterprise needs:
        • Control, customizability
        • Private/Hybrid Cloud
        • Avoid lock-in


  45


Wednesday, March 28, 12
Main Risk: Lock-In




                          Welcome to the hotel california
                          Such a lovely place
                          Such a lovely face
                          Plenty of room at the hotel california
                          Any time of year, you can find it here

                          Last thing I remember, I was
                          Running for the door
                          I had to find the passage back
                          To the place I was before
                          ’relax,’ said the night man,
                          We are programmed to receive.
                          You can checkout any time you like,
                          But you can never leave!




  46


Wednesday, March 28, 12
Cloud Foundry open PaaS - Choice of frameworks




Wednesday, March 28, 12
Cloud Foundry open PaaS - Choice of frameworks

                                                    OSS community




Wednesday, March 28, 12
Cloud Foundry open PaaS - Choice of application services




                                Ap
                                   p

                  Data
                                   lica


                 Services
                                       'o
                                        n	
  S
                                           erv



                              Msg
                                              ice



                            Services
                                                 	
  In
                                                   ter
                                                      fac




                                        Other
                                                         e




                                       Services




Wednesday, March 28, 12
Cloud Foundry open PaaS - Choice of application services




vFabric
Postgres
                                Ap
                                   p

                  Data
                                   lica


                 Services
                                       'o
                                        n	
  S



       vFabric
                                           erv



       RabbitMQTM             Msg
                                              ice



                            Services
                                                 	
  In
                                                   ter
                                                      fac




                                        Other
                                                         e




                                       Services

                 Additional partners
                 services …




Wednesday, March 28, 12
Cloud Foundry open PaaS - Choice of clouds




                                Ap




                                                                                   e
                                                                                fac
                                                                                          Private	
  
                                   p

                  Data
                                   lica


                 Services




                                                                             ter
                                                                                          Clouds	
  
                                       'o




                                                                           r	
  In
                                        n	
  S




                                                                        ide
                                           erv



                                                                                     Public


                                                                      ov
                              Msg
                                              ice



                            Services



                                                                	
  Pr
                                                                                     Clouds              Partners
                                                 	
  In




                                                              ud
                                                   ter



                                                             Cl o
                                                                                                        .COM
                                                      fac




                                        Other                            Micro
                                                         e




                                       Services
                                                                         Clouds




Wednesday, March 28, 12
Cloud Foundry open PaaS - Choice of clouds




                                                                                                         A void
                                                                                                            ck-in
                                Ap




                                                                                   e
                                                                                                         Lo




                                                                                fac
                                                                                          Private	
  
                                   p

                  Data
                                   lica


                 Services




                                                                             ter
                                                                                          Clouds	
  
                                       'o




                                                                           r	
  In
                                        n	
  S




                                                                        ide
                                           erv



                                                                                     Public


                                                                      ov
                              Msg
                                              ice



                            Services



                                                                	
  Pr
                                                                                     Clouds              Partners
                                                 	
  In




                                                              ud
                                                   ter



                                                             Cl o
                                                                                                        .COM
                                                      fac




                                        Other                            Micro
                                                         e




                                       Services
                                                                         Clouds




Wednesday, March 28, 12
Cloud Foundry open PaaS - Choice of clouds

                                                                                              OSS community




                                                                                                         A void
                                                                                                            ck-in
                                Ap




                                                                                   e
                                                                                                         Lo




                                                                                fac
                                                                                          Private	
  
                                   p

                  Data
                                   lica


                 Services




                                                                             ter
                                                                                          Clouds	
  
                                       'o




                                                                           r	
  In
                                        n	
  S




                                                                        ide
                                           erv



                                                                                     Public


                                                                      ov
                              Msg
                                              ice



                            Services



                                                                	
  Pr
                                                                                     Clouds              Partners
                                                 	
  In




                                                              ud
                                                   ter



                                                             Cl o
                                                                                                        .COM
                                                      fac




                                        Other                            Micro
                                                         e




                                       Services
                                                                         Clouds




Wednesday, March 28, 12
Open Source Advantage: it gets better faster!

   § http://code.google.com/p/googleappengine/issues/detail?id=13




   • https://github.com/cloudfoundry/vcap/pull/25




  50


Wednesday, March 28, 12
Cloud Foundry open Platform as a Service

   The PaaS of choice for the Cloud era

   Simple
     • Let’s developers focus on their code and not wiring middleware


   Open
     • Avoid lock-in to specific cloud, frameworks or service
     • Completely open source from day one

   Flexible and Scalable
     • Self service, deploy and scale your applications in seconds
     • Extensible architecture to “digest” future cloud innovation



    51

Wednesday, March 28, 12
Cloud for Developers: the true path is PaaS!




  52


Wednesday, March 28, 12
Node.js on Cloud foundry
                             (Demos and Examples)




    53

Wednesday, March 28, 12
Hello World App on Cloud Foundry

 //Simple http server on localhost                       //Simple http server on Cloud Foundry
 var http = require('http');                             var http = require('http');
 http.createServer(function (req, res) {                 var host = process.env.VCAP_APP_HOST ||
   res.writeHead(200, {'Content-Type': 'text/plain'});   ‘localhost’;
   res.end('Hello Worldn');                             var port = process.env.VCAP_APP_PORT || ‘3000’;
 }).listen(3000, '127.0.0.1');                           http.createServer(function (req, res) {
 console.log('Server running at 127.0.0.1:3000');          res.writeHead(200, {'Content-Type': 'text/plain'});
                                                           res.end('Hello Worldn');
                                                         }).listen(port, host);
                                                         console.log('Server running at ’ + host + “:” + port);


      Things to note:
      1. Cloud Foundry will provide host and port info in process.env
         variable
      2. You can use https to access your app (up to nginx; http w/in CF)
      3. Save your app as app.js or server.js to automatically use that as
         main node.js




    54

Wednesday, March 28, 12
Hello World App using ExpressJS on Cloud Foundry
    var host = process.env.VCAP_APP_HOST || 'localhost';    Things to note:
    var port = process.env.VCAP_APP_PORT || '3000';
                                                            1. ExpressJS is Ruby Sinatra
    var express = require('express');                          inspired web framework
    var app = express.createServer();
                                                            2. It provides support for:
    app.configure('development', function() {                  1.   Dev/Prod Configurations
     app.use(express.errorHandler({ dumpExceptions: true,      2.   Routes
    showStack: true }));
    });                                                        3.   Templating
                                                               4.   Sessions
    app.configure('production', function() {                   5.   Many, many other features
      app.use(express.errorHandler());
    });

    app.get('/user/', function(req, res){
      throw new Error(“call me w/ a user id");
    });

    app.get('/user/:id', function(req, res){
        res.send('user ' + req.params.id);
    });
    app.listen(port, host);




    55

Wednesday, March 28, 12
Hello World App w/ built-in node.js cluster ( > 0.6)

         var cluster = require('cluster');               Things to note:
         var http = require('http');                     1. Node.js started to support Windows servers
         var numCPUs = require('os').cpus().length;
         var port = process.env.VCAP_APP_PORT || 3000;
                                                             • Supposedly runs faster on Windows J
         var host = process.env.VCAP_APP_HOST ||
         'localhost';                                    1. If you are using cluster or need node 0.6 or
                                                            greater, use node06 runtime
         if (cluster.isMaster) { //fork workers               i.e. vmc push myapp --runtime=node06
         for (var i = 0; i < numCPUs; i++) {
             cluster.fork();
           }                                                2. This example spawns 4 node processes per
           cluster.on('death', function(worker) {              instance!
             console.log('worker ' + worker.pid + ' died');      • Watch out, it might exceeds default 64MB
           });                                                      memory.
         } else {
           // Each worker processes have a http server. 3. You may have to implement Redis based-
           http.Server(function(req, res) {                    session store
             res.writeHead(200);
             res.end(host + ":" + port);
           }).listen(port, host);
           console.log("listening on.. " + host + ":" +
         port);
         }




    56

Wednesday, March 28, 12
Agenda – part 3
     1.   About Node.js
          •   Internal working of Node.js
          •   Buzz around Node.js
          •   Who is using it
          •   What kind of apps are being built

     2.   Coding in Node.js
          •   Sync v/s Async coding (Callbacks)
          •   Classes & Modules (CommonJS)
          •   Node.js EventEmitters
          •   npm & package.json

     3.   Node.js & Cloud Foundry (w/ demo)
          •   Cloud Foundry – Open PaaS
          •   Hello World app in Cloud Foundry
          •   Scaling - Using Sticky Sessions
          •   CloudFoundry Module & connecting to Redis, MongoDB etc
          •   Express.js (RESTful) app
          •   Socket.io + Express.js (Real-time) app

     4.   Demo
          •  An sample app that uses concepts & modules talked above



    57

Wednesday, March 28, 12
Cloud Foundry Resources

    Primary Site : cloudfoundry.com
    Open Source Site : cloudfoundry.org


    Twitter : @cloudfoundry , hash tag #cfoundry
    Blog : blog.cloudfoundry.com
    FB : facebook.com/cloudfoundry


    Support : support.cloudfoundry.com
      • Documentation
      • Knowledge Base
      • Q & A / Forums




    58

Wednesday, March 28, 12
Questions




    59

Wednesday, March 28, 12
                          ?
Thank You!
               t @CloudFoundry


               t @chanezon

                   Website   : www.cloudfoundry.com
                   Blog      : blog.cloudfoundry.com
                   Forum     : support.cloudfoundry.com

Wednesday, March 28, 12
Books / Articles


   §   Nick Carr, The Big Switch
   §   Eric Raymond, The Art of Unix Programming
   §   Weinberg, Psychology of Computer Programming
   §   Wes python book
   §   Mark html5 book
   §   Kent Beck XP
   §   Hunt, Thomas, The Pragmatic Programmer
   §   Ade Oshineye, Apprenticeship Patterns
   §   Matt Cutt's Ignite Talk IO 2011, Trying different things
   §   Josh Bloch talk about api design
   §   Larry and Sergey, Anatomy of a Search Engine
   §   Rob Pike, The Practice of Programming

  61


Wednesday, March 28, 12
Papers / Talks


   §   Simon Wardley, Oscon 09 “Cloud - Why IT Matters”
   §   Tim O’Reilly article on internet os
   §   Peter Deutsch’s 8 Fallacies of Distributed Computing
   §   Brewer’s CAP Theorem
   §   Gregor Hohpe’s Starbucks Does Not Use Two-Phase Commit
   §   Herb Sutter, Welcome to the Jungle
        http://herbsutter.com/welcome-to-the-jungle/
   §   Stuff I tag http://www.delicious.com/chanezon/
   §   More specifically http://www.delicious.com/chanezon/cloudfoundry
   §   My previous Talks http://www.slideshare.net/chanezon
   §   My list of favorite books
        http://www.chanezon.com/pat/soft_books.html


  62


Wednesday, March 28, 12
Acknowledgement

   § Drawings from my daughters Eliette
   § Slides from Dave McCrory, Derek Collison, Russell Acton,
       Alexandre Vasseur, Raja Rao
   § Chinese poetry from Wang Wei, Zhu Yunming, Jiao Dao, Li Bai
       from “The Anchor book of Chinese Poetry”, Tony Barnstone and
       Chou Ping




  63


Wednesday, March 28, 12

More Related Content

Viewers also liked

Cloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersCloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersGunnar Hillert
 
Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)
Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)
Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)VMware Tanzu
 
Cloud Foundry Command Line
Cloud Foundry Command LineCloud Foundry Command Line
Cloud Foundry Command LineJulia R Nash
 
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & CloudantBuild Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & CloudantAnimesh Singh
 
Introduction to Cloud Foundry #JJUG
Introduction to Cloud Foundry #JJUGIntroduction to Cloud Foundry #JJUG
Introduction to Cloud Foundry #JJUGToshiaki Maki
 
Cloud foundry Docker Openstack - Leading Open Source Triumvirate
Cloud foundry Docker Openstack - Leading Open Source TriumvirateCloud foundry Docker Openstack - Leading Open Source Triumvirate
Cloud foundry Docker Openstack - Leading Open Source TriumvirateAnimesh Singh
 
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...OpenWhisk
 
Economies of Scaling Software
Economies of Scaling SoftwareEconomies of Scaling Software
Economies of Scaling SoftwareJoshua Long
 
Cloud Foundry Technical Overview
Cloud Foundry Technical OverviewCloud Foundry Technical Overview
Cloud Foundry Technical Overviewcornelia davis
 
Containerized DBs in a Machine Data environment with Crate.io
Containerized DBs in a Machine Data environment with Crate.ioContainerized DBs in a Machine Data environment with Crate.io
Containerized DBs in a Machine Data environment with Crate.ioClaus Matzinger
 

Viewers also liked (12)

Cloud Foundry 101
Cloud Foundry 101Cloud Foundry 101
Cloud Foundry 101
 
What is BOSH? An over-overview
What is BOSH? An over-overviewWhat is BOSH? An over-overview
What is BOSH? An over-overview
 
Cloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersCloud Foundry for Spring Developers
Cloud Foundry for Spring Developers
 
Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)
Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)
Autoscaling Distributed System with BOSH (Cloud Foundry Summit 2014)
 
Cloud Foundry Command Line
Cloud Foundry Command LineCloud Foundry Command Line
Cloud Foundry Command Line
 
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & CloudantBuild Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
 
Introduction to Cloud Foundry #JJUG
Introduction to Cloud Foundry #JJUGIntroduction to Cloud Foundry #JJUG
Introduction to Cloud Foundry #JJUG
 
Cloud foundry Docker Openstack - Leading Open Source Triumvirate
Cloud foundry Docker Openstack - Leading Open Source TriumvirateCloud foundry Docker Openstack - Leading Open Source Triumvirate
Cloud foundry Docker Openstack - Leading Open Source Triumvirate
 
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...
 
Economies of Scaling Software
Economies of Scaling SoftwareEconomies of Scaling Software
Economies of Scaling Software
 
Cloud Foundry Technical Overview
Cloud Foundry Technical OverviewCloud Foundry Technical Overview
Cloud Foundry Technical Overview
 
Containerized DBs in a Machine Data environment with Crate.io
Containerized DBs in a Machine Data environment with Crate.ioContainerized DBs in a Machine Data environment with Crate.io
Containerized DBs in a Machine Data environment with Crate.io
 

Similar to Cloud Foundry Open Tour Beijing: Becoming a Node.js Ninja on
 Cloud Foundry

Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour LondonBecoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour LondonAndy Piper
 
Multi-tiered Node Architectures - JSConf 2011
Multi-tiered Node Architectures - JSConf 2011Multi-tiered Node Architectures - JSConf 2011
Multi-tiered Node Architectures - JSConf 2011Tom Croucher
 
Threading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondThreading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondMind The Firebird
 
CodeCamp Iasi 10 march 2012 - websockets-with-atmosphere
CodeCamp Iasi 10 march 2012 - websockets-with-atmosphereCodeCamp Iasi 10 march 2012 - websockets-with-atmosphere
CodeCamp Iasi 10 march 2012 - websockets-with-atmosphereCodecamp Romania
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spacesluccastera
 
Database Performance With Proxy Architectures
Database  Performance With  Proxy  ArchitecturesDatabase  Performance With  Proxy  Architectures
Database Performance With Proxy ArchitecturesPerconaPerformance
 
PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...
PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...
PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...PROIDEA
 
Network Sampoerna
Network SampoernaNetwork Sampoerna
Network Sampoernavjimmyfg
 
Nimbuzz march2012
Nimbuzz march2012Nimbuzz march2012
Nimbuzz march2012nlwebperf
 
CloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るCloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るsamemoon
 
CloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るCloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るsamemoon
 
networking technologies
networking technologiesnetworking technologies
networking technologiesaibad ahmed
 
Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...
Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...
Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...IBM India Smarter Computing
 
Basics of the Highly Available Distributed Databases - teowaki - javier ramir...
Basics of the Highly Available Distributed Databases - teowaki - javier ramir...Basics of the Highly Available Distributed Databases - teowaki - javier ramir...
Basics of the Highly Available Distributed Databases - teowaki - javier ramir...javier ramirez
 
Everything you always wanted to know about highly available distributed datab...
Everything you always wanted to know about highly available distributed datab...Everything you always wanted to know about highly available distributed datab...
Everything you always wanted to know about highly available distributed datab...Codemotion
 
Prince Building Tech Talk 12102012
Prince Building Tech Talk 12102012Prince Building Tech Talk 12102012
Prince Building Tech Talk 12102012Andy Parsons
 
HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...
HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...
HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...Modern Data Stack France
 
High order bits from cassandra & hadoop
High order bits from cassandra & hadoopHigh order bits from cassandra & hadoop
High order bits from cassandra & hadoopsrisatish ambati
 

Similar to Cloud Foundry Open Tour Beijing: Becoming a Node.js Ninja on
 Cloud Foundry (20)

Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour LondonBecoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
 
Multi-tiered Node Architectures - JSConf 2011
Multi-tiered Node Architectures - JSConf 2011Multi-tiered Node Architectures - JSConf 2011
Multi-tiered Node Architectures - JSConf 2011
 
Threading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondThreading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyond
 
CodeCamp Iasi 10 march 2012 - websockets-with-atmosphere
CodeCamp Iasi 10 march 2012 - websockets-with-atmosphereCodeCamp Iasi 10 march 2012 - websockets-with-atmosphere
CodeCamp Iasi 10 march 2012 - websockets-with-atmosphere
 
Lecture03 H
Lecture03 HLecture03 H
Lecture03 H
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
 
Database Performance With Proxy Architectures
Database  Performance With  Proxy  ArchitecturesDatabase  Performance With  Proxy  Architectures
Database Performance With Proxy Architectures
 
PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...
PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...
PLNOG 17 - Krzysztof Wilczyński - EVPN – zwycięzca w wyścigu standardów budow...
 
Hibernating DDS
Hibernating DDSHibernating DDS
Hibernating DDS
 
Network Sampoerna
Network SampoernaNetwork Sampoerna
Network Sampoerna
 
Nimbuzz march2012
Nimbuzz march2012Nimbuzz march2012
Nimbuzz march2012
 
CloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るCloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫る
 
CloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るCloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫る
 
networking technologies
networking technologiesnetworking technologies
networking technologies
 
Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...
Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...
Towards an Open Data Center with an Interoperable Network (ODIN) : Volume 2: ...
 
Basics of the Highly Available Distributed Databases - teowaki - javier ramir...
Basics of the Highly Available Distributed Databases - teowaki - javier ramir...Basics of the Highly Available Distributed Databases - teowaki - javier ramir...
Basics of the Highly Available Distributed Databases - teowaki - javier ramir...
 
Everything you always wanted to know about highly available distributed datab...
Everything you always wanted to know about highly available distributed datab...Everything you always wanted to know about highly available distributed datab...
Everything you always wanted to know about highly available distributed datab...
 
Prince Building Tech Talk 12102012
Prince Building Tech Talk 12102012Prince Building Tech Talk 12102012
Prince Building Tech Talk 12102012
 
HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...
HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...
HUGFR : Une infrastructure Kafka & Storm pour lutter contre les attaques DDoS...
 
High order bits from cassandra & hadoop
High order bits from cassandra & hadoopHigh order bits from cassandra & hadoop
High order bits from cassandra & hadoop
 

More from Patrick Chanezon

KubeCon 2019 - Scaling your cluster (both ways)
KubeCon 2019 - Scaling your cluster (both ways)KubeCon 2019 - Scaling your cluster (both ways)
KubeCon 2019 - Scaling your cluster (both ways)Patrick Chanezon
 
KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...
KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...
KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...Patrick Chanezon
 
Dockercon 2019 Developing Apps with Containers, Functions and Cloud Services
Dockercon 2019 Developing Apps with Containers, Functions and Cloud ServicesDockercon 2019 Developing Apps with Containers, Functions and Cloud Services
Dockercon 2019 Developing Apps with Containers, Functions and Cloud ServicesPatrick Chanezon
 
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesGIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesPatrick Chanezon
 
Docker Enterprise Workshop - Intro
Docker Enterprise Workshop - IntroDocker Enterprise Workshop - Intro
Docker Enterprise Workshop - IntroPatrick Chanezon
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalPatrick Chanezon
 
The Tao of Docker - ITES 2018
The Tao of Docker - ITES 2018The Tao of Docker - ITES 2018
The Tao of Docker - ITES 2018Patrick Chanezon
 
Microsoft Techsummit Zurich Docker and Microsoft
Microsoft Techsummit Zurich Docker and MicrosoftMicrosoft Techsummit Zurich Docker and Microsoft
Microsoft Techsummit Zurich Docker and MicrosoftPatrick Chanezon
 
Develop and deploy Kubernetes applications with Docker - IBM Index 2018
Develop and deploy Kubernetes  applications with Docker - IBM Index 2018Develop and deploy Kubernetes  applications with Docker - IBM Index 2018
Develop and deploy Kubernetes applications with Docker - IBM Index 2018Patrick Chanezon
 
Docker Meetup Feb 2018 Develop and deploy Kubernetes Apps with Docker
Docker Meetup Feb 2018 Develop and deploy Kubernetes Apps with DockerDocker Meetup Feb 2018 Develop and deploy Kubernetes Apps with Docker
Docker Meetup Feb 2018 Develop and deploy Kubernetes Apps with DockerPatrick Chanezon
 
The Tao of Docker - Devfest Nantes 2017
The Tao of Docker - Devfest Nantes 2017The Tao of Docker - Devfest Nantes 2017
The Tao of Docker - Devfest Nantes 2017Patrick Chanezon
 
Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...
Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...
Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...Patrick Chanezon
 
Moby Open Source Summit North America 2017
Moby Open Source Summit North America 2017Moby Open Source Summit North America 2017
Moby Open Source Summit North America 2017Patrick Chanezon
 
Moby Introduction - June 2017
Moby Introduction - June 2017Moby Introduction - June 2017
Moby Introduction - June 2017Patrick Chanezon
 
Docker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logiciels
Docker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logicielsDocker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logiciels
Docker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logicielsPatrick Chanezon
 
Weave User Group Talk - DockerCon 2017 Recap
Weave User Group Talk - DockerCon 2017 RecapWeave User Group Talk - DockerCon 2017 Recap
Weave User Group Talk - DockerCon 2017 RecapPatrick Chanezon
 
Oscon 2017: Build your own container-based system with the Moby project
Oscon 2017: Build your own container-based system with the Moby projectOscon 2017: Build your own container-based system with the Moby project
Oscon 2017: Build your own container-based system with the Moby projectPatrick Chanezon
 

More from Patrick Chanezon (20)

KubeCon 2019 - Scaling your cluster (both ways)
KubeCon 2019 - Scaling your cluster (both ways)KubeCon 2019 - Scaling your cluster (both ways)
KubeCon 2019 - Scaling your cluster (both ways)
 
KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...
KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...
KubeCon China 2019 - Building Apps with Containers, Functions and Managed Ser...
 
Dockercon 2019 Developing Apps with Containers, Functions and Cloud Services
Dockercon 2019 Developing Apps with Containers, Functions and Cloud ServicesDockercon 2019 Developing Apps with Containers, Functions and Cloud Services
Dockercon 2019 Developing Apps with Containers, Functions and Cloud Services
 
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesGIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
 
Docker Enterprise Workshop - Intro
Docker Enterprise Workshop - IntroDocker Enterprise Workshop - Intro
Docker Enterprise Workshop - Intro
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - Technical
 
The Tao of Docker - ITES 2018
The Tao of Docker - ITES 2018The Tao of Docker - ITES 2018
The Tao of Docker - ITES 2018
 
Moby KubeCon 2017
Moby KubeCon 2017Moby KubeCon 2017
Moby KubeCon 2017
 
Microsoft Techsummit Zurich Docker and Microsoft
Microsoft Techsummit Zurich Docker and MicrosoftMicrosoft Techsummit Zurich Docker and Microsoft
Microsoft Techsummit Zurich Docker and Microsoft
 
Develop and deploy Kubernetes applications with Docker - IBM Index 2018
Develop and deploy Kubernetes  applications with Docker - IBM Index 2018Develop and deploy Kubernetes  applications with Docker - IBM Index 2018
Develop and deploy Kubernetes applications with Docker - IBM Index 2018
 
Docker Meetup Feb 2018 Develop and deploy Kubernetes Apps with Docker
Docker Meetup Feb 2018 Develop and deploy Kubernetes Apps with DockerDocker Meetup Feb 2018 Develop and deploy Kubernetes Apps with Docker
Docker Meetup Feb 2018 Develop and deploy Kubernetes Apps with Docker
 
DockerCon EU 2017 Recap
DockerCon EU 2017 RecapDockerCon EU 2017 Recap
DockerCon EU 2017 Recap
 
Docker Innovation Culture
Docker Innovation CultureDocker Innovation Culture
Docker Innovation Culture
 
The Tao of Docker - Devfest Nantes 2017
The Tao of Docker - Devfest Nantes 2017The Tao of Docker - Devfest Nantes 2017
The Tao of Docker - Devfest Nantes 2017
 
Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...
Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...
Docker 之道 Modernize Traditional Applications with 无为 Create New Cloud Native ...
 
Moby Open Source Summit North America 2017
Moby Open Source Summit North America 2017Moby Open Source Summit North America 2017
Moby Open Source Summit North America 2017
 
Moby Introduction - June 2017
Moby Introduction - June 2017Moby Introduction - June 2017
Moby Introduction - June 2017
 
Docker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logiciels
Docker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logicielsDocker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logiciels
Docker Cap Gemini CloudXperience 2017 - la revolution des conteneurs logiciels
 
Weave User Group Talk - DockerCon 2017 Recap
Weave User Group Talk - DockerCon 2017 RecapWeave User Group Talk - DockerCon 2017 Recap
Weave User Group Talk - DockerCon 2017 Recap
 
Oscon 2017: Build your own container-based system with the Moby project
Oscon 2017: Build your own container-based system with the Moby projectOscon 2017: Build your own container-based system with the Moby project
Oscon 2017: Build your own container-based system with the Moby project
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Cloud Foundry Open Tour Beijing: Becoming a Node.js Ninja on
 Cloud Foundry

  • 1. Becoming a Node.js ninja on Cloud Foundry Patrick Chanezon, Senior Director, Developer Relations chanezonp@vmware.com, @chanezon With slides from Raja Rao DV March 2012 www.cloudfoundry.com © 2009 VMware Inc. All rights reserved Wednesday, March 28, 12
  • 2. P@ in a nutshell • French, based in San Francisco • Senior Director, Developer Relations,VMware • Software Plumber, API guy, mix of Enterprise and Consumer • 18 years writing software, backend guy with a taste for javascript • 2 y Accenture (Notes guru), 3 y Netscape/AOL (Servers, Portals), 5 y Sun (ecommerce, blogs, Portals, feeds, open source) • 6 years at Google, API guy (first hired, helped start the team) • Adwords, Checkout, Social, HTML5, Cloud Wednesday, March 28, 12
  • 3. Sketching Things Slender clouds. On the pavilion a small rain. Noon, but I’m too lazy to open the far cloister. I sit looking at moss so green my clothes are soaked with color. Wang Wei (699-759) 3 Wednesday, March 28, 12
  • 4. Taking a Nap by a Mountain Window Resting my body in a monk’s cloud chamber, my dreams relax. Pine trees and cranes rise between screen and pillow. A beautiful pheasant makes a long song. My hand pushes the window, and the mountain fill my eyes. Zhu Yunming (1461-1527) 4 Wednesday, March 28, 12
  • 5. Looking for the Hermit and Not Finding Him Beneath a pine I question a boy. He says, “Master has gone to gather herbs somewhere on the mountain but who knows where? The clouds are deep.” Jiao Dao (778-841) 5 Wednesday, March 28, 12
  • 6. Looking for the Hermit and Not Finding Him Lu mountain stands beside the Southern Dipper In clouds reaching silken like a nine-panelled screen With its shadows in a crystal lake deepening the green water. The Golden Gate opens into two mountain ranges. Li Bai (701-762) 6 Wednesday, March 28, 12
  • 7. Agenda 1. About Node.js • Internal working of Node.js • Buzz around Node.js • Who is using it • What kind of apps are being built 2. Coding in Node.js • Sync v/s Async coding (Callbacks) • Classes & Modules (CommonJS) • Node.js EventEmitters • npm & package.json 3. Node.js & Cloud Foundry (w/ demo) • Hello World app in Cloud Foundry • Using Sticky Sessions • CloudFoundry Module & connecting to Redis, MongoDB etc. • Express.js (RESTful) app • Socket.io + Express.js (Real-time) app 4. Final demo • An sample app that uses concepts & modules talked above 7 Wednesday, March 28, 12
  • 8. About Node.js Node.js is a non-blocking, event-driven I/O platform that is built on Google Chrome’s v8 engine. - It is ~80% C/C++ & ~20% JS (APIs) - Uses CommonJS module system. - Executes JavaScript on the server - Built by Ryan Dahl - Sponsored by Joyent Ryan Dahl (Node.js creator) 8 Wednesday, March 28, 12
  • 9. What is the biggest advantage of Node.js? Biggest thing Node.js brings to the table (other than JS) is savings in I/O cost 9 Wednesday, March 28, 12
  • 10. The cost of I/O http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/ 10 Wednesday, March 28, 12
  • 11. So how does Node.js save I/O cost? Node.js saves I/O cost by implementing Non-blocking, event driven I/O model 11 Wednesday, March 28, 12
  • 12. Event-driven, non-blocking I/O platform/server What exactly is a event-driven, non-blocking server? How is it different from a multi-threaded server? Multi-threaded blocking server v/s Event-driven, non-blocking server 12 Wednesday, March 28, 12
  • 13. Multi-threaded server - Threads are spawned for every connection DB FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 14. Multi-threaded server - Threads are spawned for every connection User1 DB FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 15. Multi-threaded server - Threads are spawned for every connection User1 i/o request DB FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 16. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 17. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB Blocking FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 18. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 Blocking FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 19. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request Blocking FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 20. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 21. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 Refreshes 2 times FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 22. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 Refreshes 2 times FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 23. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 Refreshes 2 times FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 24. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 Refreshes 2 times FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 25. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 Refreshes 2 times FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 26. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 Refreshes 2 times FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 27. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 T5 Refreshes 2 times FS Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 28. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 T5 Refreshes 2 times User4 FS refreshes 3 times Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 29. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 T5 Refreshes 2 times User4 T6 FS refreshes 3 times Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 30. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 T5 Refreshes 2 times User4 T6 FS refreshes 3 times Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 31. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 T5 Refreshes 2 times User4 T6 FS refreshes 3 times Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 32. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking User3 T3 T4 T5 Refreshes 2 times T6 T7 T8 FS User4 T9 refreshes 3 times Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 33. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking I/O User3 T3 T4 T5 Refreshes 2 times T6 T7 T8 FS User4 T9 refreshes 3 times Multi threaded server T Thread 13 Wednesday, March 28, 12
  • 34. Multi-threaded server - Threads are spawned for every connection User1 i/o request T1 DB User2 i/o request T2 Blocking I/O User3 T3 T4 T5 Refreshes 2 times T6 T7 T8 FS User4 T9 refreshes 3 times Multi threaded server T Thread Because every I/o is blocking, server spawns a thread per connection to support multiple requests 13 Wednesday, March 28, 12
  • 35. Non-blocking & Evented I/O (Node.js server) JS C/C++ T1 DB V8 Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 36. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 37. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 T1 t7 FS V8 T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 38. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 39. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 T1 JS Thread running V8 V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 40. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 41. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves T1 t6 all users V8 t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 42. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 43. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB T1 Event loop V8 (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 44. Non-blocking & Evented I/O (Node.js server) JS C/C++ DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 45. Non-blocking & Evented I/O (Node.js server) JS C/C++ T1 V8 DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 46. Non-blocking & Evented I/O (Node.js server) JS C/C++ T1 User1 i/o request V8 DB Event loop (Libev) t2 t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 47. Non-blocking & Evented I/O (Node.js server) JS C/C++ T1 User1 i/o request V8 DB Event loop (Libev) delegate i/o to Non-blocking t2 I/O libeio t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 48. Non-blocking & Evented I/O (Node.js server) JS C/C++ T1 User1 i/o request V8 DB Event loop User2 i/o request (Libev) delegate i/o to Non-blocking t2 I/O libeio t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 49. Non-blocking & Evented I/O (Node.js server) JS C/C++ User1 i/o request DB Event loop User2 i/o request (Libev) delegate i/o to Non-blocking t2 I/O libeio t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 50. Non-blocking & Evented I/O (Node.js server) JS C/C++ User1 i/o request DB Event loop User2 i/o request (Libev) T1 delegate i/o to Non-blocking t2 I/O V8 libeio t1Libio POSIX Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 51. Non-blocking & Evented I/O (Node.js server) JS C/C++ User1 i/o request DB Event loop User2 i/o request (Libev) T1 delegate i/o to Non-blocking t2 I/O V8 libeio t1Libio User3 POSIX Refreshes 2 times Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 52. Non-blocking & Evented I/O (Node.js server) JS C/C++ User1 i/o request DB Event loop User2 i/o request (Libev) T1 delegate i/o to Non-blocking t2 I/O V8 libeio t1Libio User3 POSIX Refreshes 2 times Single Asynct4 thread t3 Threads serves t6 all users t5 t7 FS i/o result returned 2 EL after x time T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 53. Non-blocking & Evented I/O (Node.js server) JS C/C++ User1 i/o request DB Event loop User2 i/o request (Libev) T1 delegate i/o to Non-blocking t2 I/O V8 libeio t1Libio User3 POSIX Refreshes 2 times Single Asynct4 thread t3 Threads serves t6 all users t5 User4 refreshes 3 times t7 FS i/o result returned 2 EL after x time T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 14 Wednesday, March 28, 12
  • 54. Non-blocking & Evented I/O (Node.js server) JS C/C++ User1 i/o request DB Event loop User2 i/o request (Libev) T1 delegate i/o to Non-blocking t2 I/O V8 libeio t1Libio User3 POSIX Refreshes 2 times Single Asynct4 thread t3 Threads serves t6 all users t5 User4 refreshes 3 times t7 FS i/o result returned 2 EL after x time T1 JS Thread running V8 your code (Single threaded) Node.js t1 POSIX threads doing t2 async I/O (multi-threaded) t3 Everything except your (JS) code is runs in parallel (by libio) 14 Wednesday, March 28, 12
  • 55. Event-driven, non-blocking I/O server Real-world example of the two models? Multi-threaded blocking server (Apache) v/s Event-driven, non-blocking server (Nginx) 15 Wednesday, March 28, 12
  • 56. Apache V/s Nginx: performance Reqs/sec v/s concurrent connections At ~4000 concurrent connections, - Nginx can serve ~9000 reqs/sec - Apache can serve ~3000 reqs/sec Ref: http://blog.webfaction.com/a-little-holiday-present 16 Wednesday, March 28, 12
  • 57. Apache V/s Nginx: Memory usage Memory v/s concurrent connections At ~4000 concurrent connections, - Nginx uses 3MB memory - Apache uses 40MB memory Ref: http://blog.webfaction.com/a-little-holiday-present 17 Wednesday, March 28, 12
  • 58. Saving I/O is great, what else is happening w/ Node.js? Let’s look at community, libraries, buzz around Node.js 18 Wednesday, March 28, 12
  • 59. Other things going on for Node.js 2nd most popular watched on git 19 Wednesday, March 28, 12
  • 60. Other things going on for Node.js 8,000+ libraries/modules/servers High-level library categories Web frameworks Oracle Multiple protocols Command Line Option Parsers NoSQL and Key/Value HTTP Parser Generators Routers Mongo FTP Other Parsers Static file servers Debugging / Console Utilities Hive E-mail Microframeworks Redis XMPP Compression Frameworks Graphics CouchDB Other networking Sound Middleware Other NoSQL implementations RPC Payment Gateways JSGI Miscellaneous and multiple DB Web Sockets & Ajax API clients Connect Templating Message Queues Control flow / Async goodies Other middleware CSS Engines Class systems I18n and L10n modules Content Management Systems Testing / Spec Frameworks Boilerplates Other Build and Deployment Wrappers Continuous Integration Tools Database Package Management Systems Parsers DDD, CQRS, EventSourcing MS SQL Server Module Loader JSON Desktop application related OpenSSL / Crypto / Hashing XML JavaScript threads PostgreSQL Other MySQL SMTP SQLite TCP / IP https://github.com/joyent/node/wiki/modules 20 Wednesday, March 28, 12
  • 61. Other things going on for Node.js Node in Production! • LinkedIn, Yahoo!, Microsoft, eBay, Twitter etc. • >1000 other companies/startups are using it in production All kinds of interesting apps: End-user apps: • Real-time apps • Mobile apps • CRMs, Web sites etc. etc. Platform apps (Servers / Services): • Node-http-proxy - Node.js implementation of reverse proxy like nginx • Ldapjs – - Node.js implementation of LDAP server itself • SMTP – Node.js implementation of SMTP server itself • XMPP, SSH, RPC, many more. 21 Wednesday, March 28, 12
  • 62. Agenda – part 2 1. About Node.js • Internal working of Node.js • Buzz around Node.js • Who is using it • What kind of apps are being built 2. Coding in Node.js • Sync v/s Async coding (Callbacks) • Classes & Modules (CommonJS) • Node.js EventEmitters • npm & package.json 3. Node.js & Cloud Foundry • Hello World app in Cloud Foundry • Using Sticky Sessions • CloudFoundry Module & connecting to Redis, MongoDB etc • Express.js (RESTful) app • Socket.io + Express.js (Real-time) app 4. Demo • An sample app that uses concepts & modules talked above 22 Wednesday, March 28, 12
  • 63. Let’s look at the code.. How does async code differ from sync(regular) code? Synchronous code v/s Asynchronous Code 23 Wednesday, March 28, 12
  • 64. Callbacks – Control flow Use case: Let’s say we have an item’s id and want to get its name from DB and print it //Synchronous & blocking code //Async & non-blocking code function getItemNameById(id) { function getItemNameById(id, callback) { //blocks or waits for DB db.get(id, callback); //step 2 return db.get(id); //step 2 //nothing is returned here } } var name = getItemNameById(100); //step 1 //step 3 Some internal function calls the callback w/ result //print name in step 3 console.log(name); //step 3 //You create a callback helper function function displayHelperCallback(name) { console.log(name); //step 4 } Things to note: //pass callback function to consume the result getItemNameById(100, displayHelperCallback); //step 1 1. Async code doesn’t directly ‘return’ anything 2. Instead, it takes a function(callback) & calls that function when result becomes available 24 Wednesday, March 28, 12
  • 65. Callbacks – Control flow (detailed version in Node.js) //YOUR APP var db = require(‘db’); function getItemNameById(id, callback) { db.get(id, callback); //step 2 } //You create a callback helper function function displayHelperCallback(name) { console.log(name); //step 103 } //pass callback function to consume the result //step 5 getItemNameById(100, displayHelperCallback); //step 1 V8 is free to run other functions in the event- loop. //INTERNALS OF A DB LIBRARY (HIGH LEVEL) //step 5, step 6 ..step 100 function db() { Say v8 notices 95 other things to do (in the this.dbConnection = net.connection(); // connects to DB event loop), it starts executing them one by } one. db.prototype.get = function(id, callback) { var self = this; //step 3 this.dbConnection.write(id, function(result) { //step 4 At some point b/w step 3 and step 100, Step 5 returns result & asks to run self. receiveFromDB(result, callback);//step 101 }); dbConnection.write’s callback. } This event goes to the back of the queue as db.prototype.receiveFromDB = function(result, callback) { step 101 callback(result); //Execute callback step step 102 } 25 Wednesday, March 28, 12
  • 66. Node.js How can I better organize my code? Classes & CommonJS module 26 Wednesday, March 28, 12
  • 67. JavaScript Classes (Prototypical inheritance) //JavaScript prototypical inheritance Node.js also provides handy util.inherits function to inherit. //Super Class - This also provides ‘subclass.super_’ to access function Automobile(license, model) { super class’ functions this.license = license; this.model = model; var require(‘util’); //import util module } //Super Class Automobile.prototype.getModel = function() { function Automobile(license, model) { return model; this.license = license; } this.model = model; } //Sub class function Car(license, model) { Automobile.prototype.getModel = function() { Automobile.call(this, license, model); return model; } } Car.prototype = new Automobile(); //Sub class Car.prototype.constructor = Car; function Car(license, model) { Automobile.call(this, license, model); } util.inherits(Car, Automobile); 27 Wednesday, March 28, 12
  • 68. CommonJS modules //Automobile.js file Things to note: function Automobile(license, model) { 1. Allows keeping JS code in separate this.license = license; files this.model = model; } 2. Use “exports.<name>” to export Automobile.prototype.getModel = function() { something return model; } 1. Use require(‘path/to/module’) to exports.Automobile = Automobile; import it 2. use require(‘module’).<name> to access things inside module //Car.js file var util = require('util'); var module = require('./Automobile'); var Automobile = module.Automobile; function Car(license, model) { Automobile.call(this, license, model); } util.inherits(Car, Automobile); console.log(new Car("1232", "BMW").model); //prints BMW 28 Wednesday, March 28, 12
  • 69. CommonJS modules: Exporting multiple things //myModule.js file Things to note: exports.myFunction = function () { 1. You can directly export function, return ‘hi there’; arrays, variables } exports.myArray = [‘foo’, ‘bar’]; 2. You can export multiple things from exports.myVariable = ‘I’m a variable’; one file using ‘exports’ //app.js file var myModule = require('./myModule'); console.log(myModule.myFunction()); //prints ‘’hi there’ console.log(myModule.myArray[1]); //prints ‘bar’ console.log(myModule.myVariable); //prints I’m a variable’ 29 Wednesday, March 28, 12
  • 70. CommonJS modules: ‘exports’ v/s ‘module.exports’ //myModule.js file Things to note: module.exports = function () { If you want to export only one return ‘hi there’; thing.. so that it can be used } directly by the recepient, you can use.. module.exports = <something>; Warning: If you use both module.exports //app.js file and exports.bla, exports.bla will var myFunction = require('./myModule'); NOT be exported(ignored) console.log(myModule.myFunction()); //prints ‘’hi there’ 30 Wednesday, March 28, 12
  • 71. Node.js EventEmitter (A utility class that allows emitting events) EventEmitter class implements Observer pattern and provides on and emit APIs • It is used when creating(not using) an async library. Node.js EventEmitter 31 Wednesday, March 28, 12
  • 72. Events – Node.js EventEmitter (A node.js utility class that allows emitting events) //Simplified EventEmitter (Observer pattern) function EventEmitter() { //store events and callbacks like {event1: [callback1, callback2] , event2 : [cb3, cb4]…} this.eventNameAndCallbackList = {}; } //Allow others to add a callback(function) for a event name(string) EventEmitter.prototype.on = function(eventName, callback) { //add eventName and callback to eventNameAndCallbackList }; //When an event is emitted, call each callbacks in a loop EventEmitter.prototype.emit = function(eventName) { for(var i =0; i < currentCallbacks.length ; i++) { currentCallbacks[i](); //call each callback } }; exports.EventEmitter = EventEmitter; 32 Wednesday, March 28, 12
  • 73. Events – Node.js EventEmitter (continued) Say you are writing an I/O library & writing readFromDB function but don’t know how to handle async DB result. You can solve it by.. 1. Inheriting your class from EventEmitter 2. Then you can use its ‘emit’ function to an event when data arrives (asynchronously) 3. You ask people who’ll be using your library to implement ‘on’ function //myIOModule.js var util = require('util'); var events = require('events'); //myIOClass is a subclass of events.EventEmitter class var MyIOClass = function () { events.EventEmitter.call(this); }; util.inherits(MyIOClass, events.EventEmitter); MyIOClass.prototype.readFromDB = function(query){ // <--reads data code here --> this.emit('data', "some data"); } exports.MyIOClass = MyIOClass; //export the class 33 Wednesday, March 28, 12
  • 74. Events – Node.js EventEmitter (continued) Say you are an end-user trying to use DB library to read result from DB.. 1. You’ll have to implement ‘on’ function for the given event name (‘data’) and set a callback 2. DB libraries internal function will call your callback when the result comes back //app.js var myIOModule = require('./myIOModule'); var myIOClass = new myIOModule.MyIOClass(); myIOClass.on('data', function (data) { console.log(data); }); myIOClass.readFromDB('select * from users'); 34 Wednesday, March 28, 12
  • 75. Events – A library can emit multiple events I/O libraries usually emit multiple events.. connected, disconnected, error, ready, data, result etc. //So you can listen to all of them.. function myFunction() { db.on(‘error’, function(e) { console.error(e); }); db.on(‘connect’, function() { //db is connected db.query(user); }); db.on(‘disconnect’, function(){ console.log(‘db disconnected’); }); db.connect(‘127.0.0.1’, ‘100’); } 35 Wednesday, March 28, 12
  • 76. Events – Error/Exception handling //Say there was an exception trying to connect to db. Function () { try { db.connect(‘127.0.0.1’, ‘4000’); // failed to connect; connectionException } catch (e) { console.error(e); } } Above try/catch won’t handle it because the act of connection itself is an i/o //Say there was an exception trying to connect to db. Function () { //Typically I/O libraries triggers ‘error’ event. We’ll need to listen to that event db.on(‘error’, function(e) { console.error(e); }); db.connect(‘127.0.0.1’, ‘100’); // failed to connect; connectionException } 36 Wednesday, March 28, 12
  • 77. Installing external modules – npm (Node Package Manager) Use npm (Node Package Manager) to install modules Things to note: npm install <moduleName> 1. npm = Node Package Manager e.x. npm install express 2. It is a CLI to install modules from 3. Using package.json is preferred Modules are copied into ./node_modules folder /myapp /myapp/node_modules/express 1. Need to be careful about versions 2. You need to have all the modules pre-installed (i.e. npm install) //Instead keep ALL dependencies in package.json file in root of your app and run: before uploading your app to npm install Cloud Foundry //package.json { "name": ”MyApp", "description": ”My awesome twitter app", "version": "2.5.8", "author": ”Raja<rajar@vmware.com>", "dependencies": { "express": “2.3.4”, "mime": "", "connect-redis": ">= 0.0.1" } } 37 Wednesday, March 28, 12
  • 78. Installing external modules - npm & package.json Use npm (Node Package Manager) to install modules Things to note: npm install <moduleName> 1. npm = Node Package Manager e.x. npm install express 2. It is a CLI to install modules from 3. Using package.json is preferred Modules are copied into ./node_modules folder /myapp /myapp/node_modules/express 1. Need to be careful about versions 2. You need to have all the modules pre-installed (i.e. npm install) //Instead keep ALL dependencies in package.json file in root of your app and run: before uploading your app to npm install Cloud Foundry //package.json { "name": ”MyApp", "description": ”My awesome twitter app", "version": "2.5.8", "author": ”Raja<rajar@vmware.com>", "dependencies": { "express": “2.3.4”, "mime": "", "connect-redis": ">= 0.0.1" } } 38 Wednesday, March 28, 12
  • 79. Agenda – part 3 1. About Node.js • Internal working of Node.js • Buzz around Node.js • Who is using it • What kind of apps are being built 2. Coding in Node.js • Sync v/s Async coding (Callbacks) • Classes & Modules (CommonJS) • Node.js EventEmitters • npm & package.json 3. Node.js & Cloud Foundry (w/ demo) • Cloud Foundry – Open PaaS • Hello World app in Cloud Foundry • Scaling - Using Sticky Sessions • CloudFoundry Module & connecting to Redis, MongoDB etc • Express.js (RESTful) app • Socket.io + Express.js (Real-time) app 4. Demo • An sample app that uses concepts & modules talked above 39 Wednesday, March 28, 12
  • 80. Cloud Foundry Cloud Foundry – Open Platform as a Service 40 Wednesday, March 28, 12
  • 81. What is Cloud Computing? Cloud According to my daughter Eliette (10 years old) 41 Wednesday, March 28, 12
  • 82. Cloud Stack - Classic Pyramid Software As A Service Platform As A Service Infrastructure As A Service 42 Wednesday, March 28, 12
  • 83. Cloud Stack - By Value Software As A Service Platform As A Service Infrastructure As A Service 43 Wednesday, March 28, 12
  • 84. Agility as a survival skill § Consumer software is becoming like fashion • Phone apps, social apps, short lifetime, fast lifecycles • Ab testing § Clay shirky situational apps § Kent Beck, Usenix 2011 Talk, “Software G-Forces” change in software process when frequency grows § Cloud Platforms enables an Agile culture, driver for innovation • Scalability is built in the platforms • Can iterate faster • Focus on design § Cloud Platforms lets developers focus on driving business value 44 Wednesday, March 28, 12
  • 85. Platforms § Raise the Unit of currency to be application & services instead of infrastructure § Google App Engine, Cloud Foundry, Joyent, Heroku, Stax (Cloudbees), Amazon elastic beanstalk, Microsoft Azure, AppFog § Single or a few languages, services § Start of Multi language Polyglot platforms § Enabler for Agile Developers -> Create Business value faster § Lack of standards: risk, vendor lock-in § Enterprise needs: • Control, customizability • Private/Hybrid Cloud • Avoid lock-in 45 Wednesday, March 28, 12
  • 86. Main Risk: Lock-In Welcome to the hotel california Such a lovely place Such a lovely face Plenty of room at the hotel california Any time of year, you can find it here Last thing I remember, I was Running for the door I had to find the passage back To the place I was before ’relax,’ said the night man, We are programmed to receive. You can checkout any time you like, But you can never leave! 46 Wednesday, March 28, 12
  • 87. Cloud Foundry open PaaS - Choice of frameworks Wednesday, March 28, 12
  • 88. Cloud Foundry open PaaS - Choice of frameworks OSS community Wednesday, March 28, 12
  • 89. Cloud Foundry open PaaS - Choice of application services Ap p Data lica Services 'o n  S erv Msg ice Services  In ter fac Other e Services Wednesday, March 28, 12
  • 90. Cloud Foundry open PaaS - Choice of application services vFabric Postgres Ap p Data lica Services 'o n  S vFabric erv RabbitMQTM Msg ice Services  In ter fac Other e Services Additional partners services … Wednesday, March 28, 12
  • 91. Cloud Foundry open PaaS - Choice of clouds Ap e fac Private   p Data lica Services ter Clouds   'o r  In n  S ide erv Public ov Msg ice Services  Pr Clouds Partners  In ud ter Cl o .COM fac Other Micro e Services Clouds Wednesday, March 28, 12
  • 92. Cloud Foundry open PaaS - Choice of clouds A void ck-in Ap e Lo fac Private   p Data lica Services ter Clouds   'o r  In n  S ide erv Public ov Msg ice Services  Pr Clouds Partners  In ud ter Cl o .COM fac Other Micro e Services Clouds Wednesday, March 28, 12
  • 93. Cloud Foundry open PaaS - Choice of clouds OSS community A void ck-in Ap e Lo fac Private   p Data lica Services ter Clouds   'o r  In n  S ide erv Public ov Msg ice Services  Pr Clouds Partners  In ud ter Cl o .COM fac Other Micro e Services Clouds Wednesday, March 28, 12
  • 94. Open Source Advantage: it gets better faster! § http://code.google.com/p/googleappengine/issues/detail?id=13 • https://github.com/cloudfoundry/vcap/pull/25 50 Wednesday, March 28, 12
  • 95. Cloud Foundry open Platform as a Service The PaaS of choice for the Cloud era Simple • Let’s developers focus on their code and not wiring middleware Open • Avoid lock-in to specific cloud, frameworks or service • Completely open source from day one Flexible and Scalable • Self service, deploy and scale your applications in seconds • Extensible architecture to “digest” future cloud innovation 51 Wednesday, March 28, 12
  • 96. Cloud for Developers: the true path is PaaS! 52 Wednesday, March 28, 12
  • 97. Node.js on Cloud foundry (Demos and Examples) 53 Wednesday, March 28, 12
  • 98. Hello World App on Cloud Foundry //Simple http server on localhost //Simple http server on Cloud Foundry var http = require('http'); var http = require('http'); http.createServer(function (req, res) { var host = process.env.VCAP_APP_HOST || res.writeHead(200, {'Content-Type': 'text/plain'}); ‘localhost’; res.end('Hello Worldn'); var port = process.env.VCAP_APP_PORT || ‘3000’; }).listen(3000, '127.0.0.1'); http.createServer(function (req, res) { console.log('Server running at 127.0.0.1:3000'); res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(port, host); console.log('Server running at ’ + host + “:” + port); Things to note: 1. Cloud Foundry will provide host and port info in process.env variable 2. You can use https to access your app (up to nginx; http w/in CF) 3. Save your app as app.js or server.js to automatically use that as main node.js 54 Wednesday, March 28, 12
  • 99. Hello World App using ExpressJS on Cloud Foundry var host = process.env.VCAP_APP_HOST || 'localhost'; Things to note: var port = process.env.VCAP_APP_PORT || '3000'; 1. ExpressJS is Ruby Sinatra var express = require('express'); inspired web framework var app = express.createServer(); 2. It provides support for: app.configure('development', function() { 1. Dev/Prod Configurations app.use(express.errorHandler({ dumpExceptions: true, 2. Routes showStack: true })); }); 3. Templating 4. Sessions app.configure('production', function() { 5. Many, many other features app.use(express.errorHandler()); }); app.get('/user/', function(req, res){ throw new Error(“call me w/ a user id"); }); app.get('/user/:id', function(req, res){ res.send('user ' + req.params.id); }); app.listen(port, host); 55 Wednesday, March 28, 12
  • 100. Hello World App w/ built-in node.js cluster ( > 0.6) var cluster = require('cluster'); Things to note: var http = require('http'); 1. Node.js started to support Windows servers var numCPUs = require('os').cpus().length; var port = process.env.VCAP_APP_PORT || 3000; • Supposedly runs faster on Windows J var host = process.env.VCAP_APP_HOST || 'localhost'; 1. If you are using cluster or need node 0.6 or greater, use node06 runtime if (cluster.isMaster) { //fork workers i.e. vmc push myapp --runtime=node06 for (var i = 0; i < numCPUs; i++) { cluster.fork(); } 2. This example spawns 4 node processes per cluster.on('death', function(worker) { instance! console.log('worker ' + worker.pid + ' died'); • Watch out, it might exceeds default 64MB }); memory. } else { // Each worker processes have a http server. 3. You may have to implement Redis based- http.Server(function(req, res) { session store res.writeHead(200); res.end(host + ":" + port); }).listen(port, host); console.log("listening on.. " + host + ":" + port); } 56 Wednesday, March 28, 12
  • 101. Agenda – part 3 1. About Node.js • Internal working of Node.js • Buzz around Node.js • Who is using it • What kind of apps are being built 2. Coding in Node.js • Sync v/s Async coding (Callbacks) • Classes & Modules (CommonJS) • Node.js EventEmitters • npm & package.json 3. Node.js & Cloud Foundry (w/ demo) • Cloud Foundry – Open PaaS • Hello World app in Cloud Foundry • Scaling - Using Sticky Sessions • CloudFoundry Module & connecting to Redis, MongoDB etc • Express.js (RESTful) app • Socket.io + Express.js (Real-time) app 4. Demo • An sample app that uses concepts & modules talked above 57 Wednesday, March 28, 12
  • 102. Cloud Foundry Resources Primary Site : cloudfoundry.com Open Source Site : cloudfoundry.org Twitter : @cloudfoundry , hash tag #cfoundry Blog : blog.cloudfoundry.com FB : facebook.com/cloudfoundry Support : support.cloudfoundry.com • Documentation • Knowledge Base • Q & A / Forums 58 Wednesday, March 28, 12
  • 103. Questions 59 Wednesday, March 28, 12 ?
  • 104. Thank You! t @CloudFoundry t @chanezon Website : www.cloudfoundry.com Blog : blog.cloudfoundry.com Forum : support.cloudfoundry.com Wednesday, March 28, 12
  • 105. Books / Articles § Nick Carr, The Big Switch § Eric Raymond, The Art of Unix Programming § Weinberg, Psychology of Computer Programming § Wes python book § Mark html5 book § Kent Beck XP § Hunt, Thomas, The Pragmatic Programmer § Ade Oshineye, Apprenticeship Patterns § Matt Cutt's Ignite Talk IO 2011, Trying different things § Josh Bloch talk about api design § Larry and Sergey, Anatomy of a Search Engine § Rob Pike, The Practice of Programming 61 Wednesday, March 28, 12
  • 106. Papers / Talks § Simon Wardley, Oscon 09 “Cloud - Why IT Matters” § Tim O’Reilly article on internet os § Peter Deutsch’s 8 Fallacies of Distributed Computing § Brewer’s CAP Theorem § Gregor Hohpe’s Starbucks Does Not Use Two-Phase Commit § Herb Sutter, Welcome to the Jungle http://herbsutter.com/welcome-to-the-jungle/ § Stuff I tag http://www.delicious.com/chanezon/ § More specifically http://www.delicious.com/chanezon/cloudfoundry § My previous Talks http://www.slideshare.net/chanezon § My list of favorite books http://www.chanezon.com/pat/soft_books.html 62 Wednesday, March 28, 12
  • 107. Acknowledgement § Drawings from my daughters Eliette § Slides from Dave McCrory, Derek Collison, Russell Acton, Alexandre Vasseur, Raja Rao § Chinese poetry from Wang Wei, Zhu Yunming, Jiao Dao, Li Bai from “The Anchor book of Chinese Poetry”, Tony Barnstone and Chou Ping 63 Wednesday, March 28, 12