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.

Realtime webapp with node.js

3,748 views

Published on

My presentation on bancakan

Published in: Education, Technology
  • Be the first to comment

Realtime webapp with node.js

  1. 1. TECHNOLOGY TRENDS Realtime web application
  2. 2. TECHNOLOGY TRENDS Realtime web application Muqorrobien Marufi r@nosql.asia
  3. 3. PASTSearching....
  4. 4. NOW?
  5. 5. Subscribing
  6. 6. Subscribing
  7. 7. Subscribing
  8. 8. Subscribing
  9. 9. Subscribing
  10. 10. Subscribing
  11. 11. PUBSUBPUBLISHER-SUBSCRIBER
  12. 12. PUBSUB PUBLISHER-SUBSCRIBERInformation Provider
  13. 13. PUBSUB PUBLISHER-SUBSCRIBERInformation Information Provider Consumer
  14. 14. PUBSUB PUBLISHER-SUBSCRIBER PUBSUB MIDDLEWAREInformation Information Provider Consumer
  15. 15. PUBSUB PUBLISHER-SUBSCRIBER PUBSUB MIDDLEWARE PublishInformation Information Provider Consumer
  16. 16. PUBSUB PUBLISHER-SUBSCRIBER PUBSUB MIDDLEWARE Publish SubscribeInformation Information Provider Consumer
  17. 17. PUBSUB PUBLISHER-SUBSCRIBER PUBSUB MIDDLEWARE Publish Receive SubscribeInformation Information Provider Consumer
  18. 18. THE PROBLEM IS...
  19. 19. THE CHALLENGE IS...
  20. 20. CHALLENGE
  21. 21. CHALLENGE1.Realtime service.
  22. 22. CHALLENGE1.Realtime service.2.Concurrent user.
  23. 23. CHALLENGE1.Realtime service.2.Concurrent user.3.Big Data & Scalability.
  24. 24. CHALLENGE1.Realtime service.2.Concurrent user.3.Big Data & Scalability.4.Security.
  25. 25. SOLUTIONS
  26. 26. 1. NON BLOCKING I/O
  27. 27. 1. NON BLOCKING I/O MULTI THREADED IO LOOP / EVENT BASED
  28. 28. 1. NON BLOCKING I/O MULTI THREADED IO LOOP / EVENT BASED
  29. 29. 1. NON BLOCKING I/O MULTI THREADED IO LOOP / EVENT BASED
  30. 30. 1. NON BLOCKING I/O
  31. 31. 1. NON BLOCKING I/O• Event-based I/O.
  32. 32. 1. NON BLOCKING I/O• Event-based I/O. • Tornado, Twisted, Gevent (Python).
  33. 33. 1. NON BLOCKING I/O• Event-based I/O. • Tornado, Twisted, Gevent (Python). • EventMachine (Ruby).
  34. 34. 1. NON BLOCKING I/O• Event-based I/O. • Tornado, Twisted, Gevent (Python). • EventMachine (Ruby). • Node.JS (Javascript).
  35. 35. 1. NON BLOCKING I/O• Event-based I/O. • Tornado, Twisted, Gevent (Python). • EventMachine (Ruby). • Node.JS (Javascript).
  36. 36. WHY NODE.JS?
  37. 37. WHY NODE.JS?
  38. 38. WHY NODE.JS?JAVASCRIPT IS FASTEST SCRIPTING LANGUAGE
  39. 39. WHY NODE.JS?JAVASCRIPT IS FASTEST SCRIPTING LANGUAGE WHEN USING V8
  40. 40. WHY NODE.JS? GOOGLE V8
  41. 41. WHY NODE.JS?
  42. 42. WHY NODE.JS? Dynamic Machine Code Generationpoint.x
  43. 43. WHY NODE.JS? Dynamic Machine Code Generationpoint.xcmp ebx, [cached_hidden_class]jne cache_missmov eax, ebx
  44. 44. WHY NODE.JS?
  45. 45. WHY NODE.JS? ASYNCHRONOUSNON-BLOCKING BY DEFAULT
  46. 46. WHY NODE.JS? OPEN SOURCE &COMMUNITY SUPPORTED
  47. 47. WHY NODE.JS?WEB DEVELOPER FRIENDLY
  48. 48. WHY NODE.JS?HAS PACKAGE MANAGER$ npm install antigravity
  49. 49. WHY NODE.JS?
  50. 50. WHY NODE.JS?LONG POLLING IS HARD
  51. 51. WHY NODE.JS?LONG POLLING IS EASY
  52. 52. WHY NODE.JS?
  53. 53. WHY NODE.JS?CODE EXAMPLE:client.open(function(err, db){ db.query("select * from users", function(err, result){ // do with result });});
  54. 54. WHY NODE.JS?
  55. 55. WHY NODE.JS?CODE EXAMPLE: SIMPLE HTTP SERVERvar net = require(net);var server = net.createServer(function (stream) { stream.write(hellorn); stream.on(data, function (data) { stream.write(data); }); stream.on(end, function () { stream.end(goodbyern); });});server.listen(80, localhost);
  56. 56. WHY NODE.JS?
  57. 57. WHY NODE.JS?CREATE PUB/SUB SERVERJUST IN 3 LINE OF CODE!SERIOUS!?
  58. 58. WHY NODE.JS?CREATE PUB/SUB SERVERJUST IN 3 LINE OF CODE!SERIOUS!?var Faye = require(faye), server = new Faye.NodeAdapter({mount: /});server.listen(8000);
  59. 59. 2. NOSQL DB
  60. 60. 2. NOSQL DB
  61. 61. 2. NOSQL DBWHY REDIS?
  62. 62. 2. NOSQL DBWHY REDIS? Async SEMI PERSISTENT
  63. 63. 2. NOSQL DB WHY REDIS? DECR, DECRBY, DEL, EXISTS, GET, GETSET, HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HKEYS, HLEN,HMSET, HSET, HVALS, INCR, INCRBY, KEYS, LINDEX, LLEN, LPOP, LPUSH, LRANGE, LREM, LSET, LTRIM, MGET, MSET, RICHER THAN MEMCACHED MSETNX, RENAME, RENAMENX, RPOP, RPOPLPUSH, RPUSH, SADD, SCARD, SDIFF, SDIFFSTORE, SET, SETNX,SINTER, SINTERSTORE, SISMEMBER, SMEMBERS, SMOVE, SORT, SPOP, SRANDMEMBER, SREM, SUNION, SUNIONSTORE, TTL, TYPE, ZADD, ZCARD, ZINCRBY, ZRANGE, ZRANGEBYSCORE, ZREM, ZREMRANGEBYSCORE, ZREVRANGE, ZSCORE
  64. 64. 2. NOSQL DB
  65. 65. 2. NOSQL DBWHO’S USING REDIS?
  66. 66. 2. NOSQL DBWHO’S USING REDIS?
  67. 67. 2. NOSQL DB
  68. 68. 2. NOSQL DBNODE.JS + REDIS: $ npm install redis
  69. 69. 2. NOSQL DB
  70. 70. 2. NOSQL DBCODE EXAMPLE:var redis = require("redis"), client = redis.createClient();client.set("user.id:1", "robin", redis.print);client.get("user.id:1",function(err, replies){ console.log(replies); client.quit();});
  71. 71. 3. THROTTLING
  72. 72. 3. THROTTLING• Prevent flooding attack.
  73. 73. 3. THROTTLING• Prevent flooding attack.• Limit input/request per minute/hour/day.
  74. 74. 3. THROTTLING• Prevent flooding attack.• Limit input/request per minute/hour/day.• goog.async.Throttle() -- Google Closure Library.
  75. 75. Thanks!r@nosql.asia

×