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.

Network with node

2,644 views

Published on

Talk about basic networking with nodejs. Originally at MunichJS 5.5.2011 (munichjs.org)

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Network with node

  1. 1. NETWORKING WITH NODEJS Philipp Fehre http://sideshowcoder.com Inspired by Dirk Haage http://dirk.haage.info/
  2. 2. WHY?
  3. 3. • Speed
  4. 4. • Speed• Event driven programming
  5. 5. • Speed• Event driven programming• Javascript
  6. 6. • Speed• Event driven programming• Javascript• Because we can!
  7. 7. BASICS
  8. 8. • Real Simple TCP
  9. 9. • Real Simple TCP• Build a binary packet
  10. 10. • Real Simple TCP• Build a binary packet• Sent the Packet (UDP/TCP Socket)
  11. 11. • Real Simple TCP• Build a binary packet• Sent the Packet (UDP/TCP Socket)• Make DNS Requests
  12. 12. TCP SERVER
  13. 13. TCP CLIENT
  14. 14. DATA
  15. 15. ENCODING
  16. 16. BUILD PACKET
  17. 17. OPEN A SOCKET
  18. 18. SENDING
  19. 19. EXAMPLE
  20. 20. GROWL
  21. 21. DOING SOMETHING USEFUL NOW...
  22. 22. RDNS ISTRUKTA PROJECT
  23. 23. RDNS ISTRUKTA PROJECT• Resolve reverse DNS names
  24. 24. RDNS ISTRUKTA PROJECT• Resolve reverse DNS names• Scanthe whole Internet
  25. 25. RDNS ISTRUKTA PROJECT• Resolve reverse DNS names• Scanthe whole Internet• 2^32 IPs so better be fast!
  26. 26. MAKE A DNS REQUEST
  27. 27. REMINDER HOW DNS WORKS
  28. 28. 2^32 REQUEST TO 1 DNS SERVER?
  29. 29. 2^32 REQUEST TO 1 DNS SERVER?• Does not work, any sensible server will respond with “meh”
  30. 30. 2^32 REQUEST TO 1 DNS SERVER?• Does not work, any sensible server will respond with “meh”• Need to spread request across servers
  31. 31. 2^32 REQUEST TO 1 DNS SERVER?• Does not work, any sensible server will respond with “meh”• Need to spread request across servers• Handle own recursive resolution
  32. 32. 2^32 REQUEST TO 1 DNS SERVER?• Does not work, any sensible server will respond with “meh”• Need to spread request across servers• Handle own recursive resolution• Need to set DNS Server per request
  33. 33. EXPOSING SETTING
  34. 34. MAKE A DNS REQUEST VIA A SPECIFIC SERVER
  35. 35. WHY NODE?
  36. 36. WHY NODE?• Requests need to run async
  37. 37. WHY NODE?• Requests need to run async• The Javascript way to handle evented systems
  38. 38. WHY NODE?• Requests need to run async• The Javascript way to handle evented systems• First implementation in Python did not perform well enough...
  39. 39. EVENTED ARCHITECTURE
  40. 40. 2^32 IP = NEED FOR SPEED
  41. 41. 2^32 IP = NEED FOR SPEED• Sync: Python 4 workers 36000 Requests/min = 82 Days
  42. 42. 2^32 IP = NEED FOR SPEED• Sync: Python 4 workers 36000 Requests/min = 82 Days• Async: Node 1 process 500000 Requests/min = 5 Days* * Calculated wrong before sorry it’s not 2.5h
  43. 43. DEMO
  44. 44. PRO-THOUGHTS
  45. 45. PRO-THOUGHTS• Event driven programming
  46. 46. PRO-THOUGHTS• Event driven programming• Easily modifiable
  47. 47. PRO-THOUGHTS• Event driven programming• Easily modifiable• Node is moving quick
  48. 48. PRO-THOUGHTS• Event driven programming• Easily modifiable• Node is moving quick• Javascript is fun!
  49. 49. COUNTER-THOUGHTS
  50. 50. COUNTER-THOUGHTS• API not “there” yet in some cases
  51. 51. COUNTER-THOUGHTS• API not “there” yet in some cases• Really web focused
  52. 52. COUNTER-THOUGHTS• API not “there” yet in some cases• Really web focused• Node is moving to quick (from time to time)!
  53. 53. REFERENCES• Node DNS Patch: https://github.com/sideshowcoder/Add-NodeJS-DNS-Server-Settings• Growl for Node: https://github.com/sideshowcoder/Nodrrr• Web: http://sideshowcoder.com Twitter: @ischi• Pictures courtesy of google image search ;)
  54. 54. AD!

×