3rd Generation Web Application Platforms

8,687 views

Published on

3rd Generation Web Application Platforms- Node.js

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

No Downloads
Views
Total views
8,687
On SlideShare
0
From Embeds
0
Number of Embeds
334
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

3rd Generation Web Application Platforms

  1. 1. rd 3 Generation Web Application Platforms Naresh Chintalcheru
  2. 2. st 1 Generation
  3. 3. CGI : Common Gateway Interface
  4. 4. CGI Scripting languages ▪CGI C ▪CGI Perl ▪CGI TCL ▪CGI Basic
  5. 5. One Process per User Request [Operating System Processes, Threads, Semaphores, Mutexes and Barriers, are the scheduling mechanisms to acquire the time slices of the CPU. The Processes are expensive and consume more resources than Threads]
  6. 6. Drawbacks: ▪ The CGI script interpretation (compile + execution) happens at the request processing time. ▪ One user request spawns one Process, locking all the allocated resources even though request processing might not need it. ▪ The CGI spawned Process is outside the Web Server control.
  7. 7. nd 2 Generation
  8. 8. ISAPI Engines ISAPI : Internet Server Application Programming Interface
  9. 9. 2 nd Generation Platforms ▪ J2EE ▪ .Net ▪ LAMP ▪ Ruby on Rails ▪ Groovy on Grails
  10. 10. What is common in the 2 nd generation platforms ?
  11. 11. Multi-Threaded Runtime
  12. 12. One Thread per User Request
  13. 13. Image Source
  14. 14. JEE Request-To-Thread Request 1 Application Server Thread 1 Spring DispatcherServlet Thread 2 Request 2 JSF FacesServlet Struts ActionServlet Thread .. n Request .. n One Servlet instance on the App Server spawns a new thread for each user request
  15. 15. Drawbacks: ▪ One thread per user request locks the resources allocated to the thread at the time (wait) of I/O operations. ▪ Context-switching between threads are expensive.
  16. 16. rd 3 Generation
  17. 17. Single Thread Runtime
  18. 18. One Thread for [many] Users Request
  19. 19. Image Source
  20. 20. How it is possible one Thread can serve multiple users ?
  21. 21. ▪Lets see how many cycles it takes for a Disk I/O
  22. 22. Image Source
  23. 23. ▪It takes around 41 million cycles to do a disk I/O. ▪For a network call 240 million cycles …. “Understanding Node Event-Loop” – Must read excellent blog post from Mixu.
  24. 24. ▪Swim into the micro millisecond world. ▪Everything in the multi-threaded server is …..
  25. 25. Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting … Waiting . Waiting … Waiting … Waiting … Wait Waiting…Waiting…Waiting…Wait Waiting … Waiting …Wait
  26. 26. ▪While the user request is waiting for an I/O operation, the 3rd generation platforms use Non-Blocking I/O based call-backs managed by an Event-Loop and the Thread will move on to the next request. ▪The whole thing happens so fast that one Thread will be able to respond to multiple user requests.
  27. 27. 3rd generation platforms ▪Node.js for JavaScript ▪Vert.x for Java ▪Libevent for C ▪Twisted for Python ▪EventMachine for Ruby
  28. 28. 3rd generation platforms The rest of the presentation will focus on Node.js
  29. 29. Unbelievable Concurrency ? ▪ Assuming each thread has 2 MB of memory running on 8 GB of RAM puts it at a theoretical maximum of 4000 concurrent connections, plus the cost of context-switching between threads. ▪ That’s the scenario you typically deal with in traditional web-serving techniques. By avoiding all that, Node.js achieves scalability levels of over 1Million concurrent connections (as a proof-of-concept).
  30. 30. The 3rd generation platforms use the combination below to efficiently utilize the OS resources. Single Thread Non-Blocking I/O Event Loop
  31. 31. Node.js ▪ Platform based Server-side JavaScript ▪ Event-Driven Concurrency Model ▪ Use single thread and non-blocking I/O ▪ JSON and JavaScript are practically siblings that translate to Nodes ▪ JavaScript is a dynamically typed language ▪ Real-time web applications employing server-side push and two-way connections where server and client can initiate communication ▪ I/O Operations executed in parallel but not the code
  32. 32. ▪So throw-out JEE/.Net applications and rewrite in node.js ?
  33. 33. Node.js makes it an excellent choice for I/O based Applications. What are I/O based Applications? Applications which connect to databases, make web service calls, use files for logging and make connections to MQ, Mail & LDAP servers.
  34. 34. Node.js is not a good choice for CPU intensive Applications. (Node pundits argue that CPU intensive components should be evented and passed onto another thread) What are CPU intensive Applications? Applications which does lot of data processing on the App server and complex calculations which need more CPU time.
  35. 35. Node.js itself is not Non-Blocking function getAge(user_id) { sql = 'SELECT age FROM users WHERE id = ' + user_id; connection.query(sql, function(err, rows, fields) { if (err) throw err; return rows[0].age; }); return 0; } [The above database call code will starve the thread and node will not respond to other users]
  36. 36. Below Node.js code will unblock I/O and respond to other users function getAge(user_id, callback) { sql = 'SELECT age FROM users WHERE id = ' + user_id; connection.query(sql, function(err, rows, fields) { if (err) throw err; var age = rows[0].age; callback(age); }); } [The above database call code uses callbacks and unblock the I/O]
  37. 37. Programming for Node.js requires clear understanding of: ▪Asynchronous code ▪Event-Driven ▪Non-Blocking I/O ▪Callbacks and Promises
  38. 38. Who is using Node.js ? Paypal, LinkedIn, eBay, Yahoo, Walmart …………… http://nodejs.org/industry/
  39. 39. Node.js does not frameworks ? Ever growing list of presentation, data persistence and many more frameworks …………… http://nodeframework.com/
  40. 40. With the ever growing cost of hardware, power to cool them and long maintenance cycles …. How long will enterprises withstand the temptation of rd 3 Generation Platform ?
  41. 41. Disclaimer: The views and opinions expressed in this article are those of the author. The metrics and numbers used in this presentation are from the open blogs which are not validated. This is a technical presentation which will make you think about the new platform options in the technology.
  42. 42. References: ▪ http://labs.vmware.com/vmtj/autonomous-resource-sharing-for-multithreaded-workloads-in-virtualized-servers ▪ http://adamgent.com/post/10440924094/does-java-have-an-answer-tonode-js ▪ http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js ▪ http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/ ▪ http://bijoor.me/2013/06/09/java-ee-threads-vs-node-js-which-is-better-forconcurrent-data-processing-operations/ ▪ http://www.ibm.com/developerworks/java/library/j-nodejs/index.html ▪ http://www.qnx.com/developers/docs/6.4.1 /neutrino/getting_started/s1_procs.html#More_synchronization ▪ http://zef.me/5390/decoupling-events-vs-dependency-injection ▪ http://highscalability.com/blog/2013/3/18/beyond-threads-and-callbacksapplication-architecture-pros-a.html ▪ http://stackoverflow.com/questions/4296505/understanding-promises-innode-js

×