Nodejs

1,536 views
1,476 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,536
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
2
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Nodejs

  1. 1. node.js
  2. 2. Concurrency?
  3. 3. In system level it is achieved by Time Division Multiplexing
  4. 4. 1. Process Forking
  5. 6. Process Forking
  6. 7. <ul>2. Threads </ul>
  7. 9. <ul>Threads? </ul>
  8. 10. a. Context switching between threads is faster than that between processes
  9. 11. a. Context switching between threads is faster than that between processes a. Context switching between threads is not free
  10. 12. b. Multiple threads within a process share state as well as memory and other resources
  11. 13. b. Multiple threads within a process share state as well as memory and other resources b. Call stack associated with a thread is > 0 bytes
  12. 15. c. Scaling is achieved by creating a new thread per connection.
  13. 16. c. Scaling is achieved by creating a new thread per connection. c. For massive concurrency we can not use one O/S thread per connection.
  14. 18. d. Creating a thread is faster than creating a process.
  15. 19. d. Creating a thread is faster than creating a process. d. Thread creation is not really cheap, and in some systems it's costlier than forking.
  16. 21. Threaded model drops in performance as concurrency increases
  17. 22. 1. Using Java NIO/MQ for asynchronous calls, I/O operations. 2. Using green threads 3. Thread pooling
  18. 23. But it needs expert knowledge and system level hacking in some cases.
  19. 24. Concurrency?
  20. 25. 3. Event Loop
  21. 27. a. Long running routines will block the loop
  22. 28. Event loop can not support long running blocking routines
  23. 29. What is long running?
  24. 30. I/O
  25. 31. I/O latency eats CPU cycles
  26. 32. Non blocking, asynchronous I/O
  27. 33. node.js
  28. 34. Provides a simplistic API to write extremely scalable event-driven server
  29. 35. <ul><li>Server side js
  30. 36. Evented non/blocking i/o
  31. 37. Built on V8 Engine
  32. 38. CommonJS standard </li></ul>
  33. 39. Evented non blocking platform to write high concurrent applications
  34. 40. How it works?
  35. 41. How Browser Works <ul><li>Event Loop
  36. 42. Non blocking I/O
  37. 43. Interrupts </li></ul>
  38. 44. How to use it?
  39. 45. // Old blocking style resultSet = database.select(&quot;something&quot;); // wait... tap tap tap doStuff(resultSet);
  40. 46. // New non-blocking style database.select(&quot;something&quot;, function(resultSet) { // called on completion doStuff(resultSet); });
  41. 47. var sys = require('sys'), http = require('http'); http.createServer(function (req, res) { setTimeout(function () { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World! '); }, 2000); }).listen(8000); sys.puts('Server running at http://127.0.0.1:8000/'); Hello World!
  42. 48. Where can we use it?
  43. 49. <ul><li>commet apps
  44. 50. real time application
  45. 51. socket apps
  46. 52. ... </li></ul>
  47. 53. Good stuffs <ul><li>Single configuration, multiple instances
  48. 54. Loads of available modules
  49. 55. It's JS, easy to install and deploy </li></ul>
  50. 56. Bad stuffs <ul><li>Can not scale to multiprocessor architecture yet </li></ul>
  51. 57. var sys = require(&quot;sys&quot;); sys.puts(&quot;Happy Hacking!&quot;);

×