SlideShare une entreprise Scribd logo
1  sur  71
Télécharger pour lire hors ligne
Node.js:
JavaScript from Client to Server and Beyond!


              Robert McCarthy –CEO
       Gary Ratclliffe – Development Manager
Agenda




1.   The best new technology in the world
2.   The exciting future
3.   The real world
4.   If still alive
           Goto 1




                                            2
Introduction to GOSS



Robert McCarthy – GOSS CEO
  Gary Ratclliffe – Technical
Who we work with




                   4
Server-side Javascript




                         5
How many of you use JavaScript?
        Put your hands UP if YES


 Is the majority of your JavaScript jQuery?
       Put your hands DOWN if YES



Are you using any server-side JavaScript?
   Put yours hands DOWN if NO




                                              6
Why?




       7
The Problem?




               9
Form validation for websites

     User needs simple validation




                                    10
On the browser

/^[A-D][0-9]{4}$/i.test(v)




                             11
On the server

          CF: ReFindNoCase("^[A-D][0-9]{4}$", v) GT 0

        Java: Pattern.matches("(?i)^[A-D][0-9]{4}$", v)

.NET Regex.Match(v, "^[A-D][0-9]{4}$", RegexOptions.IgnoreCase)




                                                              12
4 different implementations!!
  More work, more maintenance, more risk




                                           13
The Solution?

Server Side javascript = One language

Less work, less maintenance, less risk




                                         14
The Implementation
                                       Java    Mozilla Rhino
                                       Site


Browser
                                       CF
                                       Site



          /^[A-D][0-9]{4}$/i.test(v)   .NET
                                        Site
                                               MS Jscript

                                                               15
What Next?

Like the idea of common language on all platforms

(But Clients still expect .NET sites to be .NET like & Java sites to be Java like)




                                                                                 16
Entire Forms engine?

                Complex
      Benefits from implementing once


    Needs to be extensible
      There is always a new requirements
   Clients could create their own extensions




                                               17
So we did it!
Forms generated using a simple template* containing JavaScript


<%
if ( Props["FIELDPROPERTIES"]["MAXLENGTH"] !== "") {
    maxLength="maxlength='" + Props["FIELDPROPERTIES"]["MAXLENGTH"] + "'";
}
%>
<label for='<%=Props["FIELDID"]%>'><%=Processor.htmlEsc(Props["FIELDPROPERTIES"]["LABEL"])%></label>
<input type="text" name="<%=Props["FIELDID"]%>" id="<%=Props["FIELDID"]%>" <%=maxLength%>/>




                                                                                                       18
Snag
We really needed a good, fast JavaScript engine on all platforms.

                      JScript was problem




                                                                    19
V8 Arrives!
    Created by Google for Chrome

Also designed to be used in other apps




                                         20
V8 is FAST!!
Clever optimisations and compiling to native code.

Not quite as dramatic now as when it first appeared




                                                      21
V8 is Single Threaded!!
Only one thread can execute JavaScript at a time

V8 Locking can help synchronize multiple threads

            One of reasons it’s fast

  Multi-threading can get complex…and slow




                                                   22
V8.net wrapper
Replaced JScript with JavaScript .NET from Noesis
    Proved reliable in production deployment
                 Real JavaScript

            Much faster than Jscript!!




                                                    23
V8 is Single Threaded!!
 A problem for traditional server-side scalability

How do you handle multiple concurrent requests?




                                                     24
V8.net wrapper
              Limited by single threading
       Resorted to a global lock around execution

But an evolutionary dead-end while V8 is single threaded




                                                           25
Along came Node.JS




                     26
Along came Node.JS




                     27
Non blocking vs Threads
   Threads use a lot of memory and are limited
Use asynchronous IO and an event loop like NGINX




                                                   28
Weakness now a strength
Ryan Dahl, creator of Node.JS used these concepts in Node.JS
  The single threaded nature of V8 was no longer a problem




                                                               29
You’ve gotta love it




                       30
Node.JS
What can Node.js do?
    Simple http hello world




                              32
Simple web server
                        Continuations break processing into steps



        Function called on each request



Function called when file contents available




                                                                    33
Node.JS
          Lots of additional modules

Really learn JavaScript the language not just jQuery

             Google ‘Douglas Crockford’

       Look at source code of real projects

  Combine it with MongoDB for end-to-end JSON




                                                       34
Node.JS
Think carefully if your application needs it

              Highly interactive?

             Loads of AJAX?

     Very high number of requests?

          Not just because you can!




                                               35
1000’s of concurrent requests

  All server-side JavaScript
Writing continuations for
      everything is hard

Sooner or later something has
       to do something
Writing continuations for
    everything is hard




                            38
Real world code is hard

  How many developers
  really understand it?

  Many can tweak, but
 starting from scratch…

Debugging can be difficult

 Node-inspector worth a
         look

                          39
Our Solution
Lets call it pragmatic




                         40
IcedCoffeeScript?
         Not a drink but derived from coffeesript

CoffeeScript = Cool, elegant syntax, JavaScript without the Bad Bits




                                                                       41
IcedCoffeeScript?
What happen to the 1 language

     It makes you think different.




                                     42
await and defer used to
  express callbacks


Cleaner code layout but
 you do have to learn
     CoffeeScript


  Extra build step to
 generate JavaScript



                     43
And that other issue?




                        44
Sooner or later something has to
          do something

       For many things this is not a problem
                        eg
     Database modules written to be asynchronous




                                                   45
Non blocking?
           This example is computationally
           intensive. It results in high CPU
                 use on any system.

              On Node.JS it would only
            process one request at a time.

                 n=40 takes about 5s

                3 concurrent requests:
                      1 client will wait 15s




                                          46
V8 is single threaded!
A badly written extension and Bye Bye server…




                                                47
Use Node.JS for it’s strengths




                                 48
Multiple workers processes

                               JavaScript Worker
                                JavaScript Worker
                                 JavaScript Worker
                                    TeaJS
                                     TeaJS
                                      TeaJS




              Worker Manager
                 Node.JS         Java Worker
   Requests                       Java Worker
                                   Java Worker
                                   Java VM
                                    Java VM
                Management           Java VM
                  Security




                               Node.JS Worker
                                Node.JS Worker
                                 Node.JS Worker
                                  Node.JS
                                   Node.JS
                                    Node.JS


                                                     49
Best of all worlds
   Requests delegated to a suitable worker or queued if worker busy

A CGI style wrapper round the V8 engine allowing use of traditional linear
      JavaScript. It’s a good match for our approach to forms rendering




                                                                      50
Where Next?
           Does the industry need Node.JS?

Other web servers can/will achieve similar performance

         So its really all about the language?




                                                         51
Is 1 Language an ideal?
   Same developers for UI and Backend?

          Common in start-ups

        Less so in the ‘enterprise’

    Jack of all trades master of none?




                                         52
So will it survive?




                      53
Today most sites..




                     54
Multiple Dev Languages




                         55
Client is a dumb browser




                           56
Clients are isolated from one
            another




                                57
Anything more interactive tends
         to be bespoke




                              58
Imagine




          60
Imagine

One server-side infrastructure




                                 61
Imagine

One Language




               62
Imagine

One Data Format: JSON?




                         63
Imagine

Transfer Data not UI




                       64
Imagine

Collaborate & Distribute




                           65
66
So is it just a dream?




                         67
68
But that’s for the next talk?




                                69
Final Thoughts….
                 The web is changing at pace.

                There will be lots of shiny toys

                They might not lead to nirvana

but they will often give you a glimpse of a very exciting future!!



                         Stay Excited…


                                                                     70
Any questions?


   Thank you!!

PS. We are hiring!

Contenu connexe

Tendances

Nuxeo World Session: Scaling Nuxeo Applications
Nuxeo World Session: Scaling Nuxeo ApplicationsNuxeo World Session: Scaling Nuxeo Applications
Nuxeo World Session: Scaling Nuxeo ApplicationsNuxeo
 
Why we (Day) open source most of our code
Why we (Day) open source most of our codeWhy we (Day) open source most of our code
Why we (Day) open source most of our codeBertrand Delacretaz
 
Introducing Apricot, The Eclipse Content Management Platform
Introducing Apricot, The Eclipse Content Management PlatformIntroducing Apricot, The Eclipse Content Management Platform
Introducing Apricot, The Eclipse Content Management PlatformNuxeo
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...Ivan Loire
 
Groovy Tutorial
Groovy TutorialGroovy Tutorial
Groovy TutorialPaul King
 
Fake it 'til you make it
Fake it 'til you make itFake it 'til you make it
Fake it 'til you make itJonathan Snook
 
Tricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly FrameworkTricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly Frameworkelliando dias
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
Scaling MongoDB with Docker and cgroups
Scaling MongoDB with Docker and cgroupsScaling MongoDB with Docker and cgroups
Scaling MongoDB with Docker and cgroupsmarcoita
 
Javantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornJavantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornMiroslav Resetar
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaNurul Ferdous
 
Dynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishDynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishIndicThreads
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsGanesh Iyer
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Devang Garach
 
ngGoBuilder and collaborative development between San Francisco and Tokyo
ngGoBuilder and collaborative development between San Francisco and TokyongGoBuilder and collaborative development between San Francisco and Tokyo
ngGoBuilder and collaborative development between San Francisco and Tokyonotolab
 

Tendances (20)

Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Nuxeo World Session: Scaling Nuxeo Applications
Nuxeo World Session: Scaling Nuxeo ApplicationsNuxeo World Session: Scaling Nuxeo Applications
Nuxeo World Session: Scaling Nuxeo Applications
 
Why we (Day) open source most of our code
Why we (Day) open source most of our codeWhy we (Day) open source most of our code
Why we (Day) open source most of our code
 
Introducing Apricot, The Eclipse Content Management Platform
Introducing Apricot, The Eclipse Content Management PlatformIntroducing Apricot, The Eclipse Content Management Platform
Introducing Apricot, The Eclipse Content Management Platform
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
 
Groovy Tutorial
Groovy TutorialGroovy Tutorial
Groovy Tutorial
 
Fake it 'til you make it
Fake it 'til you make itFake it 'til you make it
Fake it 'til you make it
 
Mini-Training: Node.js
Mini-Training: Node.jsMini-Training: Node.js
Mini-Training: Node.js
 
Tricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly FrameworkTricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly Framework
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Scaling MongoDB with Docker and cgroups
Scaling MongoDB with Docker and cgroupsScaling MongoDB with Docker and cgroups
Scaling MongoDB with Docker and cgroups
 
Javantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornJavantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript Nashorn
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
 
Dynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishDynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFish
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
ngGoBuilder and collaborative development between San Francisco and Tokyo
ngGoBuilder and collaborative development between San Francisco and TokyongGoBuilder and collaborative development between San Francisco and Tokyo
ngGoBuilder and collaborative development between San Francisco and Tokyo
 

En vedette

Switching website hosting for improved performance case study
Switching website hosting for improved performance case studySwitching website hosting for improved performance case study
Switching website hosting for improved performance case studyGOSS Interactive
 
Public Sector Customer Services Goes Social
Public Sector Customer Services Goes SocialPublic Sector Customer Services Goes Social
Public Sector Customer Services Goes SocialGOSS Interactive
 
Channel Shift Understanding Your Customers #channelshiftcamp
Channel Shift Understanding Your Customers #channelshiftcampChannel Shift Understanding Your Customers #channelshiftcamp
Channel Shift Understanding Your Customers #channelshiftcampGOSS Interactive
 
Channel Shift Understanding Your Channels #channelshiftcamp
Channel Shift Understanding Your Channels #channelshiftcamp Channel Shift Understanding Your Channels #channelshiftcamp
Channel Shift Understanding Your Channels #channelshiftcamp GOSS Interactive
 
GOSS Interactive Client Case Studies
GOSS Interactive Client Case StudiesGOSS Interactive Client Case Studies
GOSS Interactive Client Case StudiesGOSS Interactive
 
Nottingham City Council website success
Nottingham City Council website successNottingham City Council website success
Nottingham City Council website successGOSS Interactive
 
Channel shift and online efficiency event
Channel shift and online efficiency eventChannel shift and online efficiency event
Channel shift and online efficiency eventGOSS Interactive
 
Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...
Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...
Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...GOSS Interactive
 
Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...
Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...
Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...GOSS Interactive
 
How social media management is driving channel shift
How social media management is driving channel shiftHow social media management is driving channel shift
How social media management is driving channel shiftGOSS Interactive
 
Managing a website by Sue Roberts
Managing a website by Sue RobertsManaging a website by Sue Roberts
Managing a website by Sue RobertsGOSS Interactive
 

En vedette (12)

Switching website hosting for improved performance case study
Switching website hosting for improved performance case studySwitching website hosting for improved performance case study
Switching website hosting for improved performance case study
 
Public Sector Customer Services Goes Social
Public Sector Customer Services Goes SocialPublic Sector Customer Services Goes Social
Public Sector Customer Services Goes Social
 
Channel Shift Understanding Your Customers #channelshiftcamp
Channel Shift Understanding Your Customers #channelshiftcampChannel Shift Understanding Your Customers #channelshiftcamp
Channel Shift Understanding Your Customers #channelshiftcamp
 
Channel Shift Understanding Your Channels #channelshiftcamp
Channel Shift Understanding Your Channels #channelshiftcamp Channel Shift Understanding Your Channels #channelshiftcamp
Channel Shift Understanding Your Channels #channelshiftcamp
 
GOSS Interactive Client Case Studies
GOSS Interactive Client Case StudiesGOSS Interactive Client Case Studies
GOSS Interactive Client Case Studies
 
Nottingham City Council website success
Nottingham City Council website successNottingham City Council website success
Nottingham City Council website success
 
Channel shift and online efficiency event
Channel shift and online efficiency eventChannel shift and online efficiency event
Channel shift and online efficiency event
 
Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...
Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...
Socitm Building Perfect Council Websites 2012 GOSS Interactive Channel Shift ...
 
Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...
Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...
Capita Channel Shift in the Public Sector - GOSS six step strategy for channe...
 
How social media management is driving channel shift
How social media management is driving channel shiftHow social media management is driving channel shift
How social media management is driving channel shift
 
Managing a website by Sue Roberts
Managing a website by Sue RobertsManaging a website by Sue Roberts
Managing a website by Sue Roberts
 
Click here to donate
Click here to donateClick here to donate
Click here to donate
 

Similaire à Node.js #digpen presentation

Isomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornIsomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornMaxime Najim
 
Difference between Node.js vs Java script
Difference between Node.js vs Java scriptDifference between Node.js vs Java script
Difference between Node.js vs Java scriptGhulamHussain799241
 
SSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJSSSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJSEugene Lazutkin
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS drupalcampest
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?Balajihope
 
Node.js for .NET Developers
Node.js for .NET DevelopersNode.js for .NET Developers
Node.js for .NET DevelopersDavid Neal
 
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebAppsIBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebAppsChris Bailey
 
Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019Jamie Coleman
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?jbandi
 
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...Techahead Software
 

Similaire à Node.js #digpen presentation (20)

Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
node.js
node.jsnode.js
node.js
 
Isomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornIsomorphic JavaScript with Nashorn
Isomorphic JavaScript with Nashorn
 
Node js
Node jsNode js
Node js
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
Nodejs
NodejsNodejs
Nodejs
 
Difference between Node.js vs Java script
Difference between Node.js vs Java scriptDifference between Node.js vs Java script
Difference between Node.js vs Java script
 
NodeJS and what is actually does
NodeJS and what is actually doesNodeJS and what is actually does
NodeJS and what is actually does
 
SSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJSSSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJS
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
Using Node.pdf
Using Node.pdfUsing Node.pdf
Using Node.pdf
 
Node.js for .NET Developers
Node.js for .NET DevelopersNode.js for .NET Developers
Node.js for .NET Developers
 
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebAppsIBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
 
Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
 
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
Don’t Let Your Businesses Get Hampered By Large Volume Codes: Nodejs Is Your ...
 

Node.js #digpen presentation

  • 1. Node.js: JavaScript from Client to Server and Beyond! Robert McCarthy –CEO Gary Ratclliffe – Development Manager
  • 2. Agenda 1. The best new technology in the world 2. The exciting future 3. The real world 4. If still alive Goto 1 2
  • 3. Introduction to GOSS Robert McCarthy – GOSS CEO Gary Ratclliffe – Technical
  • 4. Who we work with 4
  • 6. How many of you use JavaScript? Put your hands UP if YES Is the majority of your JavaScript jQuery? Put your hands DOWN if YES Are you using any server-side JavaScript? Put yours hands DOWN if NO 6
  • 7. Why? 7
  • 8.
  • 10. Form validation for websites User needs simple validation 10
  • 12. On the server CF: ReFindNoCase("^[A-D][0-9]{4}$", v) GT 0 Java: Pattern.matches("(?i)^[A-D][0-9]{4}$", v) .NET Regex.Match(v, "^[A-D][0-9]{4}$", RegexOptions.IgnoreCase) 12
  • 13. 4 different implementations!! More work, more maintenance, more risk 13
  • 14. The Solution? Server Side javascript = One language Less work, less maintenance, less risk 14
  • 15. The Implementation Java Mozilla Rhino Site Browser CF Site /^[A-D][0-9]{4}$/i.test(v) .NET Site MS Jscript 15
  • 16. What Next? Like the idea of common language on all platforms (But Clients still expect .NET sites to be .NET like & Java sites to be Java like) 16
  • 17. Entire Forms engine? Complex Benefits from implementing once Needs to be extensible There is always a new requirements Clients could create their own extensions 17
  • 18. So we did it! Forms generated using a simple template* containing JavaScript <% if ( Props["FIELDPROPERTIES"]["MAXLENGTH"] !== "") { maxLength="maxlength='" + Props["FIELDPROPERTIES"]["MAXLENGTH"] + "'"; } %> <label for='<%=Props["FIELDID"]%>'><%=Processor.htmlEsc(Props["FIELDPROPERTIES"]["LABEL"])%></label> <input type="text" name="<%=Props["FIELDID"]%>" id="<%=Props["FIELDID"]%>" <%=maxLength%>/> 18
  • 19. Snag We really needed a good, fast JavaScript engine on all platforms. JScript was problem 19
  • 20. V8 Arrives! Created by Google for Chrome Also designed to be used in other apps 20
  • 21. V8 is FAST!! Clever optimisations and compiling to native code. Not quite as dramatic now as when it first appeared 21
  • 22. V8 is Single Threaded!! Only one thread can execute JavaScript at a time V8 Locking can help synchronize multiple threads One of reasons it’s fast Multi-threading can get complex…and slow 22
  • 23. V8.net wrapper Replaced JScript with JavaScript .NET from Noesis Proved reliable in production deployment Real JavaScript Much faster than Jscript!! 23
  • 24. V8 is Single Threaded!! A problem for traditional server-side scalability How do you handle multiple concurrent requests? 24
  • 25. V8.net wrapper Limited by single threading Resorted to a global lock around execution But an evolutionary dead-end while V8 is single threaded 25
  • 28. Non blocking vs Threads Threads use a lot of memory and are limited Use asynchronous IO and an event loop like NGINX 28
  • 29. Weakness now a strength Ryan Dahl, creator of Node.JS used these concepts in Node.JS The single threaded nature of V8 was no longer a problem 29
  • 32. What can Node.js do? Simple http hello world 32
  • 33. Simple web server Continuations break processing into steps Function called on each request Function called when file contents available 33
  • 34. Node.JS Lots of additional modules Really learn JavaScript the language not just jQuery Google ‘Douglas Crockford’ Look at source code of real projects Combine it with MongoDB for end-to-end JSON 34
  • 35. Node.JS Think carefully if your application needs it Highly interactive? Loads of AJAX? Very high number of requests? Not just because you can! 35
  • 36. 1000’s of concurrent requests All server-side JavaScript
  • 37. Writing continuations for everything is hard Sooner or later something has to do something
  • 38. Writing continuations for everything is hard 38
  • 39. Real world code is hard How many developers really understand it? Many can tweak, but starting from scratch… Debugging can be difficult Node-inspector worth a look 39
  • 40. Our Solution Lets call it pragmatic 40
  • 41. IcedCoffeeScript? Not a drink but derived from coffeesript CoffeeScript = Cool, elegant syntax, JavaScript without the Bad Bits 41
  • 42. IcedCoffeeScript? What happen to the 1 language It makes you think different. 42
  • 43. await and defer used to express callbacks Cleaner code layout but you do have to learn CoffeeScript Extra build step to generate JavaScript 43
  • 44. And that other issue? 44
  • 45. Sooner or later something has to do something For many things this is not a problem eg Database modules written to be asynchronous 45
  • 46. Non blocking? This example is computationally intensive. It results in high CPU use on any system. On Node.JS it would only process one request at a time. n=40 takes about 5s 3 concurrent requests: 1 client will wait 15s 46
  • 47. V8 is single threaded! A badly written extension and Bye Bye server… 47
  • 48. Use Node.JS for it’s strengths 48
  • 49. Multiple workers processes JavaScript Worker JavaScript Worker JavaScript Worker TeaJS TeaJS TeaJS Worker Manager Node.JS Java Worker Requests Java Worker Java Worker Java VM Java VM Management Java VM Security Node.JS Worker Node.JS Worker Node.JS Worker Node.JS Node.JS Node.JS 49
  • 50. Best of all worlds Requests delegated to a suitable worker or queued if worker busy A CGI style wrapper round the V8 engine allowing use of traditional linear JavaScript. It’s a good match for our approach to forms rendering 50
  • 51. Where Next? Does the industry need Node.JS? Other web servers can/will achieve similar performance So its really all about the language? 51
  • 52. Is 1 Language an ideal? Same developers for UI and Backend? Common in start-ups Less so in the ‘enterprise’ Jack of all trades master of none? 52
  • 53. So will it survive? 53
  • 56. Client is a dumb browser 56
  • 57. Clients are isolated from one another 57
  • 58. Anything more interactive tends to be bespoke 58
  • 59.
  • 60. Imagine 60
  • 66. 66
  • 67. So is it just a dream? 67
  • 68. 68
  • 69. But that’s for the next talk? 69
  • 70. Final Thoughts…. The web is changing at pace. There will be lots of shiny toys They might not lead to nirvana but they will often give you a glimpse of a very exciting future!! Stay Excited… 70
  • 71. Any questions? Thank you!! PS. We are hiring!