MUMPS is dead? Rob Tweed M/Gateway Developments Ltd http://www.mgateway.com Twitter: @rtweed
What is Node.js?
What is Node.js?
What is Node.js? … so what does that mean?
What is Node.js?
What is Node.js? <ul><li>Node.js is a server-side JavaScript environment. </li></ul>
What is Node.js? <ul><li>Node.js is a server-side JavaScript environment. </li></ul><ul><li>Node.js is a server-side JavaS...
Just Javascript Browsers Node.js server process Javascript Javascript Database
So instead of this: http/ https Persistent connections Browser Browser Browser Web Server (Apache/ IIS) CSP Caché CSP inte...
You'd have something like this: Browser Browser Browser Cach é http/ https WebLink interface Cach é CSP interface Child_pr...
What is Node.js?
V8 <ul><li>Node.js uses the Google V8 engine to provide the Javascript environment </li></ul><ul><li>V8 is the engine in t...
What is Node.js?
What is Node.js? <ul><li>Node.js is a server-side JavaScript environment   that uses an asynchronous event-driven model . ...
What is Node.js? <ul><li>Node.js is a server-side JavaScript environment   that uses an asynchronous event-driven model . ...
Asynchronous I/O & Javascript <ul><li>Javascript is an ideal language for this </li></ul><ul><li>No I/O in a browser </li>...
Asynchronous I/O & Javascript <ul><li>On the server, in Node.js: </li></ul><ul><ul><li>Make a request for I/O (file/ datab...
Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = &quot;mydata.txt&quot; open file:&quot;r&q...
Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = &quot;mydata.txt&quot; open file:&quot;r&q...
Asynchronous I/O & Javascript The Asynchronous way in Javascript: var fs = require('fs'); fs.readFile('mydata.txt', functi...
What is Node.js?
Node.js Evented I/O <ul><li>Node.js is a single process running an event loop </li></ul><ul><li>When an event occurs, fire...
Node.js process <ul><li>A Node.js process can handle many thousands of clients </li></ul><ul><ul><li>Provided none of them...
Node.js / Javascript: popularity <ul><li>Node.js is now the most followed project on Github, exceeding Ruby on Rails </li>...
Significance for GT.M & Cach é <ul><li>Opportunity to use Javascript as a primary scripting language </li></ul><ul><ul><li...
Why Javascript? <ul><li>The world's most popular language </li></ul><ul><li>The world's sexiest, coolest server-side envir...
Why not MUMPS? <ul><li>Rightly or wrongly, the perception in the mainstream is that the MUMPS language is old-fashioned an...
Making Global Storage Attractive <ul><li>Make it accessible via the coolest, sexiest, most popular language on the planet ...
Downside of Node.js <ul><li>Asynchronous programming </li></ul><ul><ul><li>Callback hell! </li></ul></ul><ul><ul><ul><li>D...
Dependent callbacks myFunc1(inputs, function(error, results) { var value = results.value; // myFunc2 can't run until myFun...
Concurrent callbacks var count = 0; myFunc1(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); ...
Closures <ul><li>Inner functions have access to the outer function's variables, even after the outer function has complete...
Closures <ul><li>Inner functions have access to the outer function's variables, even after the outer function has complete...
Closures <ul><li>Inner functions have access to the outer function's variables, even after the outer function has complete...
Closures <ul><li>Could be rewritten to use a self-executing function as follows  </li></ul>var digit_name = function() {  ...
Downside of Node.js <ul><li>Asynchronous programming </li></ul><ul><ul><li>Database access functions can't return a value ...
Accessing globals from Node.js <ul><li>Cache & GT.M: </li></ul><ul><ul><li>https://github.com/robtweed/ewdGateway </li></u...
Upcoming SlideShare
Loading in …5
×

Node.js: CAMTA Presentation

3,410 views

Published on

Presentation given at the CAMTA meeting, 1st December 2011

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,410
On SlideShare
0
From Embeds
0
Number of Embeds
89
Actions
Shares
0
Downloads
45
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Node.js: CAMTA Presentation

  1. 1. MUMPS is dead? Rob Tweed M/Gateway Developments Ltd http://www.mgateway.com Twitter: @rtweed
  2. 2. What is Node.js?
  3. 3. What is Node.js?
  4. 4. What is Node.js? … so what does that mean?
  5. 5. What is Node.js?
  6. 6. What is Node.js? <ul><li>Node.js is a server-side JavaScript environment. </li></ul>
  7. 7. What is Node.js? <ul><li>Node.js is a server-side JavaScript environment. </li></ul><ul><li>Node.js is a server-side JavaScript interpreter that allows us to handle and make requests via JavaScript: </li></ul><ul><ul><li>In a web or networked environment </li></ul></ul>
  8. 8. Just Javascript Browsers Node.js server process Javascript Javascript Database
  9. 9. So instead of this: http/ https Persistent connections Browser Browser Browser Web Server (Apache/ IIS) CSP Caché CSP interface Caché CSP interface Your scripts Your data EWD CSP pages
  10. 10. You'd have something like this: Browser Browser Browser Cach é http/ https WebLink interface Cach é CSP interface Child_process connections EWD Runtime Your scripts Your data EWD routines Node.js process Javascript Web server & request/response Handling logic stdin/stdout GT.M or Cach é
  11. 11. What is Node.js?
  12. 12. V8 <ul><li>Node.js uses the Google V8 engine to provide the Javascript environment </li></ul><ul><li>V8 is the engine in the Chrome browser </li></ul><ul><li>V8 is very fast! </li></ul>
  13. 13. What is Node.js?
  14. 14. What is Node.js? <ul><li>Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model . </li></ul>
  15. 15. What is Node.js? <ul><li>Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model . </li></ul><ul><li>No threads </li></ul><ul><ul><li>Node.js runs in a single process, handling all client requests </li></ul></ul><ul><li>Non-blocking I/O </li></ul><ul><ul><li>Can't wait for slow resources to respond </li></ul></ul><ul><ul><ul><li>Files, databases, etc </li></ul></ul></ul><ul><ul><li>Must not block the process or everyone waits </li></ul></ul>
  16. 16. Asynchronous I/O & Javascript <ul><li>Javascript is an ideal language for this </li></ul><ul><li>No I/O in a browser </li></ul><ul><li>Access to remote resources is asynchronous </li></ul><ul><ul><li>The A in Ajax! </li></ul></ul><ul><li>Send a request for a resource and define a handler to deal with it when it arrives </li></ul><ul><ul><li>&quot;Call-back function&quot; </li></ul></ul>
  17. 17. Asynchronous I/O & Javascript <ul><li>On the server, in Node.js: </li></ul><ul><ul><li>Make a request for I/O (file/ database) </li></ul></ul><ul><ul><li>Define a call-back function </li></ul></ul><ul><ul><li>Move on immediately </li></ul></ul><ul><ul><li>When the I/O is complete: </li></ul></ul><ul><ul><ul><li>Call-back function is fired to handle it </li></ul></ul></ul>
  18. 18. Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = &quot;mydata.txt&quot; open file:&quot;r&quot; use file read buffer // do something with the buffer contents … . // then move on to the next task
  19. 19. Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = &quot;mydata.txt&quot; open file:&quot;r&quot; use file read buffer // do something with the buffer contents … .// at this point the thread is blocked … .// until the buffer contents are read from the file // then move on to the next task
  20. 20. Asynchronous I/O & Javascript The Asynchronous way in Javascript: var fs = require('fs'); fs.readFile('mydata.txt', function (err, buffer) { // Do something with the data in the buffer }); // Immediately execute the next statements // while it waits for I/O
  21. 21. What is Node.js?
  22. 22. Node.js Evented I/O <ul><li>Node.js is a single process running an event loop </li></ul><ul><li>When an event occurs, fire a call-back function to handle it </li></ul><ul><li>When no events are coming in, the Node.js process sits in a dormant state </li></ul>
  23. 23. Node.js process <ul><li>A Node.js process can handle many thousands of clients </li></ul><ul><ul><li>Provided none of them block </li></ul></ul><ul><ul><li>Provided none of them do CPU-intensive processing </li></ul></ul>
  24. 24. Node.js / Javascript: popularity <ul><li>Node.js is now the most followed project on Github, exceeding Ruby on Rails </li></ul><ul><li>Javascript is now the most popular language in the world, based on a number of measures including number of Github projects </li></ul>
  25. 25. Significance for GT.M & Cach é <ul><li>Opportunity to use Javascript as a primary scripting language </li></ul><ul><ul><li>Global storage for Javascript </li></ul></ul><ul><ul><li>JSON / Global mapping </li></ul></ul>
  26. 26. Why Javascript? <ul><li>The world's most popular language </li></ul><ul><li>The world's sexiest, coolest server-side environment </li></ul><ul><li>Javascript's dynamic interpreted nature has many similarities to MUMPS </li></ul>
  27. 27. Why not MUMPS? <ul><li>Rightly or wrongly, the perception in the mainstream is that the MUMPS language is old-fashioned and inherently broken </li></ul><ul><ul><li>Daily WTF article: </li></ul></ul><ul><ul><ul><li>http://thedailywtf.com/Articles/A_Case_of_the_MUMPS.aspx </li></ul></ul></ul><ul><li>Yet global storage has a great deal to offer as a NoSQL database technology </li></ul><ul><li>Result: the benefits and advantages of global storage are ignored because modern developers will refuse to learn the language </li></ul>
  28. 28. Making Global Storage Attractive <ul><li>Make it accessible via the coolest, sexiest, most popular language on the planet </li></ul><ul><li>Demonstrate that global storage is a great NoSQL technology </li></ul><ul><ul><li>&quot;Universal NoSQL Engine&quot; </li></ul></ul><ul><ul><li>http://www.mgateway.com/docs/universalNoSQL.pdf </li></ul></ul>
  29. 29. Downside of Node.js <ul><li>Asynchronous programming </li></ul><ul><ul><li>Callback hell! </li></ul></ul><ul><ul><ul><li>Deeply nested call-backs </li></ul></ul></ul><ul><ul><li>Complexity of logic </li></ul></ul><ul><ul><ul><li>Essential to understand closures </li></ul></ul></ul><ul><ul><ul><li>2 main types: </li></ul></ul></ul><ul><ul><ul><ul><li>Dependent </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Concurrent </li></ul></ul></ul></ul><ul><ul><ul><li>Care needed when using for loops to invoke logic that includes callbacks </li></ul></ul></ul>
  30. 30. Dependent callbacks myFunc1(inputs, function(error, results) { var value = results.value; // myFunc2 can't run until myFunc1 returns its results myFunc2(value, function(error, results) { var myResult = results.value; }); });
  31. 31. Concurrent callbacks var count = 0; myFunc1(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); myFunc2(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); myFunc3(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); // myFunc isn't invoked until all 3 functions are complete // Uses the properties of closures to allow count to be incremented by // the callbacks in the three functions
  32. 32. Closures <ul><li>Inner functions have access to the outer function's variables, even after the outer function has completed </li></ul>
  33. 33. Closures <ul><li>Inner functions have access to the outer function's variables, even after the outer function has completed </li></ul>var digit_name = function() { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function(n) { return names[n]; }; }; var test = digit_name(); // test is a function that takes a value var text = test(3); console.log(&quot;text = &quot; + text);
  34. 34. Closures <ul><li>Inner functions have access to the outer function's variables, even after the outer function has completed </li></ul>var digit_name = function() { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function(n) { return names[n]; }; }; var test = digit_name(); // test is a function that takes a value var text = test(3); console.log(&quot;text = &quot; + text);
  35. 35. Closures <ul><li>Could be rewritten to use a self-executing function as follows </li></ul>var digit_name = function() {  var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight', 'nine'];  return function(n) {    return names[n];  }; } () ; // digit_name is the result of running the outer function, // so it's a function that takes a value var name = digit_name(3); // name will be 'three'
  36. 36. Downside of Node.js <ul><li>Asynchronous programming </li></ul><ul><ul><li>Database access functions can't return a value </li></ul></ul><ul><ul><ul><li>Value is embedded inside the callback </li></ul></ul></ul><ul><ul><ul><li>Can't chain database functions as objects: </li></ul></ul></ul><ul><ul><ul><ul><li>document.getElementById('x').parent.firstChild.tagName </li></ul></ul></ul></ul>
  37. 37. Accessing globals from Node.js <ul><li>Cache & GT.M: </li></ul><ul><ul><li>https://github.com/robtweed/ewdGateway </li></ul></ul><ul><ul><li>Complete webserver + gateway for EWD </li></ul></ul><ul><ul><li>Also includes global access functions, eg: </li></ul></ul><ul><ul><ul><li>get </li></ul></ul></ul><ul><ul><ul><li>set </li></ul></ul></ul><ul><ul><ul><li>getJSON </li></ul></ul></ul><ul><ul><ul><li>mFunction </li></ul></ul></ul>

×