Presentation is loading. Please wait.

Presentation is loading. Please wait.

Page 1 Node.js - What? EMEA PUG Challenge, November 2015, Copenhagen 6-Nov-15 Node.js - What?

Similar presentations


Presentation on theme: "Page 1 Node.js - What? EMEA PUG Challenge, November 2015, Copenhagen 6-Nov-15 Node.js - What?"— Presentation transcript:

1 Page 1 Node.js - What? EMEA PUG Challenge, November 2015, Copenhagen 6-Nov-15 Node.js - What?

2 Page 2 Agenda  Introduction  Node.js –What is it?  Browsers  Important modules  Progress Node.js 6-Nov-15 Node.js - What?

3 Page 3 Introduction  Robert Prediger  20 years experience in PROGRESS  15 years experience in web development  5 years experience in Node.js  robert.prediger@web4biz.de 6-Nov-15 Node.js - What?

4 Page 4 Node.js  Javascript is everywhere: –Browsers –Webservers –Databases –Mobile Devices  Adobe, Google, Apple and Microsoft are spending a huge amount of money!  JavaScript seems to be the worlds most used programming language. 6-Nov-15 Node.js - What?

5 Page 5 Node.js  What is Node.js –Server side Javascript –Built on Chrome V8 Engine –Event-driven, non blocking I/O model  What is it for? –Easily building fast, scalable network applications –Perfect for data-intensive real-time application that run across distributed devices 6-Nov-15 Node.js - What?

6 Page 6 Browser http://html5test.com/ 6-Nov-15 Node.js - What?

7 Page 7 Browser 6-Nov-15 Node.js - What?

8 Page 8 Node.js  What is Node.js –Server side Javascript –Built on Chrome V8 Engine –Event-driven, non blocking I/O model  What is it for? –Easily building fast, scalable network applications –Perfect for data-intensive real-time application that run across distributed devices 6-Nov-15 Node.js - What?

9 Page 9 Node.js Blocking I/O  database, filesystem – disk  S3, external APIs – networking 6-Nov-15 Node.js - What?

10 Page 10 Node.js 6-Nov-15 Node.js - What?

11 Page 11 Node.js  Request (other languages, incl. Progress): 6-Nov-15 Node.js - What? Finished request Start 2nd request Green is executing thread Red is waiting on I/O

12 Page 12 Node.js  F-18 Hornet –Max speed of 1,190 mph  RAM  Banana slug –Max speed of 0.007 mph  Hard disk 6-Nov-15 Node.js - What? Quelle: http://blog.scoutapp.com/articles/2011/02/10/understanding-disk-i-o-when-should-you-be-worried

13 Page 13 Node.js 6-Nov-15 Node.js - What?

14 Page 14 Nginx 6-Nov-15 Node.js - What? Quelle: http://www.theorganicagency.com/apache-vs-nginx-performance-comparison/

15 Page 15 Nginx 6-Nov-15 Node.js - What? Quelle: http://blog.webfaction.com/2008/12/a-little-holiday-present-10000-reqssec-with-nginx-2/

16 Page 16 Node.js 6-Nov-15 Node.js - What?

17 Page 17 Node.js 6-Nov-15 Node.js - What? Q: How is it possible to handle parallel I/O with one thread of execution? A: There is (usually) no such thing as parallel I/O

18 Page 18 Node.js  Parallel I/O: how we see it 6-Nov-15 Node.js - What?

19 Page 19 Node.js  Parallel I/O: what actually happen at low level 6-Nov-15 Node.js - What?

20 Page 20 Node.js 6-Nov-15 Node.js - What? OS does a good job of abstracting sequential stream of raw data into logical streams: tcp sockets, http connections

21 Page 21 Node.js 6-Nov-15 Node.js - What? „everything runs in parallel...... except your code“ - it seems that a lot of people are confused by this phrase which tries to explain node.js asynchronous nature

22 Page 22 Node.js 6-Nov-15 Node.js - What? “everything” = I/O Since I/O is external to the code, I’d prefer to say “In node, code is organised to wait for as much as possible in parallel”

23 Page 23 Node.js 6-Nov-15 Node.js - What? We are not “running” functions in parallel. We are waiting for data “in parallel”. One World One WAIT-FOR

24 Page 24 Node.js  Request with WebSpeed: 6-Nov-15 Node.js - What? Finished request Start 2nd request Green is executing thread Red is waiting on I/O

25 Page 25 Node.js 6-Nov-15 Node.js - What?  Request with Node: Green is executing thread Red is waiting on I/O Event Loop Request

26 Page 26 Node.js 6-Nov-15 Node.js - What?

27 Page 27 Node.js Can handle thousands of concurrent connections with minimal overhead (CPU/Memory) on a single Process! 6-Nov-15 Node.js - What?

28 Page 28 Node.js Summary  Extremely efficient networking applications  Fast javascript runtime (V8)  Rapid growth in both, packages and community 6-Nov-15 Node.js - What?

29 Page 29 Module 6-Nov-15 Node.js - What?

30 Page 30 Modules  Number of Node.js modules exceeded 200.000!  Modules for nearly every problem: –pm2 –cluster –express –socket.io –restify –async –q (promises) –debug –winston 6-Nov-15 Node.js - What?

31 Page 31 PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. http://pm2.keymetrics.io/ Node.js - What? pm2 6-Nov-15

32 Page 32 cluster 6-Nov-15 Node.js - What? var cluster = require('cluster'), http = require('http‘); if (cluster.isMaster) { // Fork workers. for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('exit', function(worker, code, signal) { console.log('worker ' + worker.process.pid + ' died'); }); } else { // Workers can share any TCP connection // In this case its a HTTP server http.createServer(function(req, res) { res.writeHead(200); res.end("hello world\n"); }).listen(8000); }

33 Page 33 express  http://expressjs.com/ 6-Nov-15 Node.js - What? var express = require('express'), app = express(); app.configure(function(){ app.use( express.favicon() ); app.use( express.bodyParser() ); app.use( express.static( './public') ); }); app.get( '/login‘, route.get ); app.listen( 8081 );

34 Page 34 socket.io Protocol for having a bidirectional communication with client. 6-Nov-15 Node.js - What?

35 Page 35 socket.io  http://socket.io/ 6-Nov-15 Node.js - What? var io = require('socket.io').listen( 80 ); io.sockets.on('connection', function (socket) { socket.emit( 'message', { text: 'Hello World' }); // broadcast message to all subscribed sockets socket.broadcast.emit("chat", { name: socket.nickname, msg: msg });

36 Page 36 socket.io Demo 6-Nov-15 Node.js - What?

37 Page 37 restify - Client  https://github.com/mcavage/node-restify 6-Nov-15 Node.js - What? var client = restify.createJsonClient({ url: 'https://api.us-west-1.joyentcloud.com', version: '*‘ }); client.post('/foo', { hello: 'world' }, function(err, req, res, obj) { assert.ifError(err); console.log( res.statusCode, '->', res.headers ); console.log( obj ); });

38 Page 38 restify - Server  https://github.com/mcavage/node-restify 6-Nov-15 Node.js - What? var restify= require('restify‘), server= restify.createServer({ name: 'myapp', version: '1.0.0' }); server.use(restify.acceptParser(server.acceptable)); server.use(restify.queryParser()); server.use(restify.bodyParser()); server.get('/echo/:name', function (req, res, next ) { res.send(req.params); return next(); }); server.listen( 8080, function () { console.log('%s listening at %s', server.name, server.url); });

39 Page 39 async  https://github.com/caolan/async 6-Nov-15 Node.js - What? // an example using an object instead of an array async.parallel({ one: function(callback){ setTimeout(function(){ callback(null, 1); }, 200); }, two: function(callback){ setTimeout(function(){ callback(null, 2); }, 100); } }, function(err, results) { // results is now equals to: {one: 1, two: 2} } );

40 Page 40 debug  https://github.com/visionmedia/debug 6-Nov-15 Node.js - What? var debug= require("debug"), log= debug("demo:socket"); function login ( name ) { log( "login", name ); client.nickname = name; }

41 Page 41 winston  https://github.com/flatiron/winston 6-Nov-15 Node.js - What? var winston = require('winston'); var logger = new (winston.Logger)( { transports: [ new (winston.transports.Console)( { level: 'warn' } ), new (winston.transports.File)( { filename: 'somefile.log', level: 'error‘ } ) ] }); logger.debug( "Will not be logged in either transport!" ); logger.transports.console.level = 'debug'; logger.transports.file.level = 'verbose'; logger.verbose("Will be logged in both transports!");

42 Page 42 Progress - WebSpeed  REST: Node.js -> Progress WebSpeed –pro Easy to maintain –con Overhead with HTTP Messenger 6-Nov-15 Node.js - What?

43 Page 43 Progress - WebSpeed 6-Nov-15 Node.js - What? {src/web/method/cgidefs.i} output-content-type("application/json":U). IF NOT WEB-CONTEXT:IS-JSON THEN DO: LOG-MANAGER:WRITE-MESSAGE( "No JSON request" ). RETURN. END. /* read json */ oParse = NEW ObjectModelParser(). jData = CAST( oParse:Parse( WEB-CONTEXT:HANDLE ), JsonObject ).

44 Page 44 Progress - WebSpeed 6-Nov-15 Node.js - What?... hDataSet:FILL(). jResult = NEW JsonObject(). jDataSet = NEW JsonObject(). jDataSet:READ( hDataSet ). jResult:Add( "data", jDataSet ). jResult:WriteStream( "Webstream" ).

45 Page 45 Progress - AppServer  REST: Node.js -> Progress AppServer –pro Webservice –con Overhead with Tomcat Deployment with ProxyGen 6-Nov-15 Node.js - What?

46 Page 46 Progress – node4progress  node4progress –https://github.com/FrankHilhorst/node4progresshttps://github.com/FrankHilhorst/node4progress –pro very fast Structured API –con Overhead with java engine between 6-Nov-15 Node.js - What?

47 Page 47 Progress – node4progress 6-Nov-15 Node.js - What? var conf = require("./config.json"); var n4p= require("node4progress")(conf); n4p.setAppsvrProc("CustomerHandler.p","",false,true); n4p.setParameter("InputPars","longchar","input","batchNum=2",""); n4p.setParameter("OutputPars","character","output","",""); n4p.setParameter("dsCustomer","dataset-handle","output","",""); n4p.setParameter("ErrMsg","character","output","",""); n4p.appProc().execute(function(err,result){ if(err){ console.log("ERROR->"+err); }else{ result=JSON.parse(result); } });

48 Page 48 Progress – node4progress 6-Nov-15 Node.js - What? var conf = require('config.json'), n4p = require('node4progressHttp')conf.prgs); var handler = "handlers/CustomerHandler.p", inputPars = "NumCustomersToPull=2"; n4p.callHandler( handler, inputPars, function(result){ console.log(result); });

49 Page 49 Progress – JSDO  JSDO –https://github.com/CloudDataObject/JSDOhttps://github.com/CloudDataObject/JSDO –https://documentation.progress.com/output/pdo/https://documentation.progress.com/output/pdo/ –pro very fast Structured API –con Infrastructure (beginning with OE 11.5) 6-Nov-15 Node.js - What?

50 Page 50 Progress – JSDO 6-Nov-15 Node.js - What? XMLHttpRequest = require("./XMLHttpRequest.js").XMLHttpRequest; Require("./progress.js"); Require("./progress.session.js"); // get connection to progress and get catalog var session = new progress.data.Session(); session.login( conf.serviceURI, "", ""); session.addCatalog( conf.catalogURI );

51 Page 51 Progress – JSDO 6-Nov-15 Node.js - What? // create jsdo var jsdo = new progress.data.JSDO( { name: 'dsCustomer' } ); jsdo.subscribe( 'AfterFill', onAfterFillCustomers, this); jsdo.fill(); // fills the locally initialized jsdo from the catalog function onAfterFillCustomers( jsdo, success, request ) { var result = []; jsdo.eCustomer.foreach( function( cust ) { result.push( cust.data ); }); callback( null, result ); }

52 Page 52 End Questions? robert.prediger@web4biz.de 6-Nov-15 Node.js - What?


Download ppt "Page 1 Node.js - What? EMEA PUG Challenge, November 2015, Copenhagen 6-Nov-15 Node.js - What?"

Similar presentations


Ads by Google