Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Toronto node js_meetup

1,174 views

Published on

Develop, Deploy, monitor and Scale APIs in Node.js for meeting the mobile and IoT demands.

Published in: Software
  • Be the first to comment

Toronto node js_meetup

  1. 1. Enterprise Node.js to Power the API Economy Shubhra Kar | Products & Education twitter:@shubhrakar mail:skar@strongloop.com
  2. 2. Wake up to the API economy Explosion of channels (browsers, mobile, sensors, wearable, real-time communication) u Sheer number of clients has increased u Clients are increasingly sophisticated u Node.js is the platform of choice for these API StrongLoop Confidential and Proprietary Information – © 2015
  3. 3. Latency demands are uncompromising 10 25 50 100100 50 10 15 40 100 25 Web SaaS Mobile IoT The new curve Concurrent Users Latency Adoption StrongLoop Confidential and Proprietary Information – © 2015
  4. 4. Not all APIs are built equal The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again. Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one) Laptop ( not requested but useful) Connections Tablet Phone IoT SDK API SERVER Items for ACL Quick Example of Use App Server Add On App Server Relational Database Clustered Database Security Gateway Cl Laptop ( not requested but useful) Connections Tablet Phone IoT SDK AP Quick Examp App Server X – Backend ? X - Channel X - Platform API Neutrality Mainframe to Mobile ? StrongLoop Confidential and Proprietary Information – © 2014
  5. 5. API “Re-Composition” is good…but not good enough Relational Database Clustered Database Security Gateway Cloud Laptop ( not requested but useful) Connections Tablet Phone IoT SDK API SERVER Quick Example of Use App Server Relational Database Clustered Database Security Gateway Laptop ( not requested but useful) Connections Tablet Phone IoT SDK Quick E App Server Auth Routing Rate-Limit Proxy Mediation Orchestration Analytics StrongLoop Confidential and Proprietary Information – © 2014
  6. 6. The need is “DE-COMPOSITION” SaaS Mobile IoTWeb App Server API Server HTML JSON {JSON} {JSON} {JSON}<SOAP/XML> <TABLE> StrongLoop Confidential and Proprietary Information – © 2014
  7. 7. Micro-services has arrived StrongLoop Confidential and Proprietary Information – © 2014
  8. 8. Now I know !!!
  9. 9. So who is propelling this transformation ?
  10. 10. Why Node? 10 Node is FAST…er Node is perfect for APIs Node is JavaScript & JSON …and highly concurrent! StrongLoop Confidential and Proprietary Information – © 2015 Node is much lighter
  11. 11.   LinkedIn moved from Rails to Node.js –  Cut down servers by 90% (30 à 3) –  Lower memory overhead and up to 20X faster   PayPal migrated to Node.js from Java: –  Reduce development time by >50% –  2X speed of delivery with less than existing resources –  33% lesser lines of code –  40% fewer files   Groupon displaced Ruby and Java with Node.js across the board: –  50% improvement in page response times –  Agile builds and deploys Any use-cases ?
  12. 12. Behind the Curtain Node Bindings C/C++ (socket, http, etc.) V8 Libuv Libeio (thread pool) Libev (event loop) IOCP (IO completion ports) Node Standard Library (JavaScript) epoll/kqueue/poll (event ports) Linux Kernel Windows Kernel Yes, it’s C back there StrongLoop Confidential and Proprietary Information – © 2015
  13. 13. {“..”} JSON is the new first class citizen StrongLoop Confidential and Proprietary Information – © 2014
  14. 14. Full Stack JavaScript is powering mobility Angular Bootstrap Ionic Cordova Gartner predicts by 2016 more than 50% of the apps deployed will be Hybrid apps. LoopBack API Server Node.js StrongLoop Confidential and Proprietary Information – © 2014
  15. 15. Nodies are not just Silicon Valley hipsters ! StrongLoop Confidential and Proprietary Information – © 2014
  16. 16. s Node is de-facto for the backend API now •  67K Developers •  Fastest Growing (120K+ > Java, Ruby, PHP…) StrongLoop Confidential and Proprietary Information – © 2014
  17. 17. Really, But isn’t it the wild west ?
  18. 18. These guys sent me ! Bert Belder Ben Noordhuis Node Core Raymond Feng Ritchie Martori LoopBack / Express Core Sam Roberts Miroslav Bajtos Ryan Graham Plus 15 other full-time open source developers working on Node.js core, modules and tools. Contributing to over 100 open source modules. Supporting banks, retail, IoT companies, startups and internet companies on Node.js
  19. 19. The only product company dedicated only to Node Jason Pressman Kiran Prasad Neil Day Nick Sturiale Paul Ambrose Marten Mickos StrongLoop Confidential and Proprietary Information – © 2014
  20. 20. StrongLoop iPaaS for APIs Compose Integrate Test & Build Deploy & Scale Secure & Manage Monitor & Analyze •  Loopback •  Express •  Node Code Generators •  Data Connectors •  Service Connectors •  Client/Mobile SDKs •  Mobile Services •  Debugger •  Build Utilities •  Private Registry •  Bootstrap deployer •  Runtime manager •  Clustering, HA, Hot Deploy •  API Gateway •  Distributed Routing. •  Performance Monitoring •  Analytics •  Metering StrongLoop API Platform StrongLoop Confidential and Proprietary Information – © 2015
  21. 21. Popular Frameworks
  22. 22. Sample Code (Router using express 4.x)
  23. 23. Pros Great starting point Low learning curve Nearly a standard for Node.js web middleware Fully customizable Targeted at browser, hence templating and rendering OOB Cons All endpoints need to be created manually Developers may end up creating their own non-optimized libraries Every end point needs to be tested Refactoring is painful, update everything everywhere No standards or prescription, DIY 26 Express
  24. 24. Sample Code (Router using restify)
  25. 25. Pros Very stable and actively developed. Automatic DTrace support for all handlers on enabled platforms Built in throttling SPDY support Borrows from express but without unnecessary templating/rendering Strict API with full control over HTTP interactions Visibility into latency and app characteristics Cons All endpoints need to be created manually Developers may end up creating their own non-optimized libraries Every end point needs to be tested Refactoring is painful, update everything everywhere No standards or prescription, DIY Less documentation Restify
  26. 26. Sample Code (Router using hapi)
  27. 27. Sample Code (Router using hapi)
  28. 28. Pros Supported by Walmart labs. Less known but getting momentum Very granular control over request handling Detailed API reference with support for document generation Significantly more functionality for building web servers Pseudo prescriptive with configuration centric approach Caching, Authentication and input validation available Plugin based architecture for scaling Cons Good construction blocks but left to your own devices to figure out design patterns Binds you to specific modules and tool chains (catbox, joi, tv, boom, good, travelogue, yar) All endpoints need to be created manually Developers may end up creating their own non-optimized libraries Every end point needs to be tested Refactoring is painful, update everything everywhere 33
  29. 29. Sample Code (Router using Loopback) Code needed Endpoints automatically created
  30. 30. Sample Code (API explorer and test) Code needed API explorer automatically created
  31. 31. Sample Code (RPC) Code needed Remotable calls
  32. 32. Pros Very quick RESTful API development Convention over configuration (extends express) Built in models ready to use (ORM) RPC support, Web and Mobile SDKs Data Connectors Fully configurable when needed Extensive documentation Commercial support and full time team working on project (Loopback) Mobile Services (Push, Geo, Storage, Sync, Offline, File, Device, User) - Loopback Authentication, validation and Authorization Cons Higher learning curve Opinionated
  33. 33. REST API PUSH GEO OFF SYNC DEVICE USER FILE Relational Database Clustered Database Security Gateway Cloud Laptop ( not requested but useful) Connections Tablet Phone IoT SDK API SERVER Quick Example of Use App S Add App Server Storage Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one) Laptop ( not requested but useful) Connections Tablet Phone IoT SDK API SERVER Items for ACL Quick Example of Use App Server Add On App Server REST API GATEWAY Channel SDKs API ENGINE C O N N E C T O R s A P I S D K s Loopback framework – ORM and Mobile connect in Node.js REST API atabase Security Gateway Cloud Firewall SOA Bus ( not sure on this one) Phone IoT SDK API SERVER Items for ACL Quick Example of Use App Server Add On App Server API Explorer
  34. 34. Magical Features u  Discovery u  Migration / Replication u  Relationship Mapping u  Mixins - Aggregation u  Access Control u  User Management u  Isomorphic JS / Remoting u  Routing StrongLoop Confidential and Proprietary Information – © 2014
  35. 35. Data & Services Integration Services Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( no Laptop ( not requested but useful) Connections Tablet Phone IoT SDK API SERVER Items for A Quick Example of Use App Server Add On App Server Storage y Cloud Firewall SOA Bus ( not sure on this one) API SERVER Items for ACL Quick Example of Use App Server Add On REST Messaging Database NoSQL Marquee - Discovery & Migration ! StrongLoop Confidential and Proprietary Information – © 2014
  36. 36. User Experience   Arc UI – architect view –  Widget driven –  Visual composition, management & operations –  Marquee featured, evolving platform   StrongLoop Console (slc) - developer view –  Command Line Interface –  Full featured –  Greater customization support StrongLoop Confidential and Proprietary Information – © 2014
  37. 37. API Explorer (Swagger) – Iterative build and test w/o frontend StrongLoop Confidential and Proprietary Information – © 2014
  38. 38. API Gateway * Security & Social Logins * Evolving. Please do not share without written consent from StrongLoop Marquee – Auth, Routing, Throttling, Proxy, Mediation, Aggregation, Virtualization StrongLoop Confidential and Proprietary Information – © 2014
  39. 39. API Gateway* u  Security (AAA) u  Mediation and Transformation u  Infrastructure QoS (pagination, throttling, caching, delivery guarantee, firewall) u  Analytics and health monitoring u  Aggregation and Microservices Routing u  Virtualization and Reverse Proxy StrongLoop Confidential and Proprietary Information – © 2014 * Evolving. Please do not share without written consent from StrongLoop
  40. 40. Node vs Java for REST routing * 46 StrongLoop Confidential and Proprietary Information – © 2014 * Highly Confidential. Please do not share without written consent from StrongLoop
  41. 41. Some Numbers – Top 3 US Bank * StrongLoop Confidential and Proprietary Information – © 2014 * Highly Confidential. Please do not share without written consent from StrongLoop
  42. 42. Developer SDKs Omni-channel Client SDKs JS client JS Server Remoting JS client Marquee – Isomorphic JS, Mobile Integration StrongLoop Confidential and Proprietary Information – © 2014
  43. 43. Mobile Services mBaaS Capabilities Marquee – Push, Geo, Offline Sync, Storage StrongLoop Confidential and Proprietary Information – © 2014
  44. 44. Push Notification StrongLoop Confidential and Proprietary Information – © 2014
  45. 45. GeoLocation
  46. 46. Storage Service 52 StrongLoop Confidential and Proprietary Information – © 2014
  47. 47. Offline Sync StrongLoop Confidential and Proprietary Information – © 2014
  48. 48. Platform support & DevOps Tool-chains
  49. 49. Node.js support (Sample modules set) 55 Node.js Core strong- module-loader strong-cluster- connect-store strong-cluster- control SL-Config Loopback Strong-mq strong-task- emitter Engine.io Mongoose Strong-agent strong-cluster- socket.io-store strong-config- loader Request Node- heapdump Asynch node- inspector Passport Strong- remoting Q EJS Express Connect Socket.IO Reggie Postgres Connector Oracle Connector SQL Server Connector MongoDB Connector REST Connector In-Memory connector LIBUV V8 Profiler ①  Multi-platform (Windows, Unix, Solaris, Mac) support ②  On-premises, private or public cloud support ③  Certified Node.js curated modules and ecosystem ④  Commercial Enterprise supported, security updates StrongLoop Confidential and Proprietary Information – © 2014
  50. 50. Private Registry
  51. 51. Debugging Marquee – Chrome Dev Tools, Remote StrongLoop Confidential and Proprietary Information – © 2014
  52. 52. Debugging server side clustered apps slc debug app.js Debugging single process slc debug app.js http://localhost:8080/debug?port=<5858+ID-of-process> Debugging clustered process in V11 %node debug –p <PID> connecting…ok … debug>quit %node-inspector http://127.0.0.1:8080/debug?port =5858 Or process._debugPort = 5858 + cluster.worker.id Debugging clustered process in V10
  53. 53. Profilers StrongLoop Confidential and Proprietary Information – © 2014
  54. 54. Does Node have memory leaks ? StrongLoop OSS - HeapSnapshots slc runctl heap-snapshot ID
  55. 55. Sudden leaks
  56. 56. heapdump for V8 snapshots npm install heapdump   Add to app : var heapdump = require(‘heapdump’)   Method 1 : writeSnapshot   Method 2 : SIGUSR2 (Unix only)   Make sure your directory is writable var heapdump = require('heapdump') ... heapdump.writeSnapshot() kill –USR2 <pid> process.chdir('/path/to/writeable/dir’)
  57. 57. Heap Snapshot strategies   Programmatic heap snapshots (timer based)   Programmatic heap snapshots (threshold based) var heapdump = require('heapdump') ... setInterval(function () { heapdump.writeSnapshot() }, 6000 * 30) <strong>(1)</strong> var heapdump = require('heapdump') var nextMBThreshold = 0 <strong>(1)</strong> setInterval(function () { var memMB = process.memoryUsage().rss / 1048576 <strong>(2)</ strong> if (memMB &gt; nextMBThreshold) { <strong>(3)</strong> heapdump.writeSnapshot() nextMBThreshold += 100 } }, 6000 * 2) <strong>(4)</strong>
  58. 58. How we fixed a real production problem
  59. 59. Don’t Block the EventLoop StrongLoop Confidential and Proprietary Information – © 2015
  60. 60. Blocked event loop in Meteor atmosphere   node-fibers implements co-routines. Meteor uses this to hack local thread storage allowing V8 to run multiple execution contexts each mapped to a co-routine. FindOrAllocatePerThreadDataForThisThread() used in switching context between co- routines   Co-routines are cooperative; the current coroutine has to yield control before another one can run and that is what Meteor does in its process.nextTick() callback; it essentially builds concurrent (but not parallel) green threads on a round-robin scheduler   Too many tiny tasks and not one long running one was blocking the event loop process.nextTick() has a failsafe mechanism where it will process “x” tick callbacks before deferring the remaining ones to the next event loop tick.   Native MongoDB driver disabled the failsafe to silence a warning message in node v0.10 about maxtickDepth being reached ticks parent name 2274 7.3% v8::internal::Isolate::FindOrAllocatePerThreadDataForThisThread() 1325 58.3% LazyCompile: ~<anonymous> packages/meteor.js:683 1325 100.0% LazyCompile: _tickCallback node.js:399
  61. 61. The solution   The workaround: switch fromprocess.nextTick() to setImmediate()
  62. 62. Performance Monitoring
  63. 63. Production Monitoring & 3rd Party integration •  Local / Hosted •  Graphite •  Splunk •  Datadog •  CA Introscope StrongLoop Confidential and Proprietary Information – © 2014
  64. 64. Dynamic Instrumentation Agent App Monkey Patching Agent App Dynamic Instrument •  Live Edit •  Line Level Instrumentation •  Any package, any framework, any code •  Custom logic •  Counters, Gauges and Timers •  HA rollback StrongLoop Confidential and Proprietary Information – © 2015
  65. 65. Can Errors be stitched into a trace and recovered ? Enter StrongLoop / Zones
  66. 66. Long error traces
  67. 67. Runtime Mgmt. & Scaling
  68. 68. Build & Deploy StrongLoop Confidential and Proprietary Information – © 2014
  69. 69. Cluster and runtime scaling Marquee – HA, Auto-scale, Hot Deploy StrongLoop Confidential and Proprietary Information – © 2014
  70. 70. MESH – Micro-services Deploy on Scale StrongLoop Confidential and Proprietary Information – © 2014
  71. 71. First there was Node Thank you! JUST WIN, BABY!

×