[Case Simulation Workshop] Michael Evans - High performance system building

download [Case Simulation Workshop] Michael Evans - High performance system building

of 34

  • date post

    21-Jan-2018
  • Category

    Technology

  • view

    130
  • download

    1

Embed Size (px)

Transcript of [Case Simulation Workshop] Michael Evans - High performance system building

  1. 1. Michael Basic: High performance system building contact: michael@cinnamon.is
  2. 2. Introduction Graduated: Ha Noi University of Science and Technology - Software Engineer - 2010 Got No.3, Viet Name Talent in IT eld - 2011. from 2007 - 2013: work at Med-Aid as Team Leader, a partner of Prowess. From 2013 - Now: working at Cinnamon as Software Architecture Leader.
  3. 3. Main points researching High performance system building Data mining Articial Intelligent
  4. 4. How to build high performance system?
  5. 5. Normal system architecture database System logic Server side Third party system Client side Problem come from here!!!
  6. 6. Real use case Social network one user have: followers, followings, posts.
  7. 7. Server side - Database
  8. 8. Database issues? Queries So slow - Multiple queries in one request - Each query take time to run System run slow
  9. 9. Database solution? Queries So slow Set Index for all important elds Optimise number of queries on each request / task Anything else?
  10. 10. Caching solution always check if needed data exist on cache or not if exist > get from cache. if not > query from DB and add to cache too. Logic CacheExist? Query if not exist in cache Update cache for each query
  11. 11. Caching solution Redis cache: https://redis.io Memcache: https://memcached.org
  12. 12. Example If User 1111 create new post which has ID = cccc > system need update that post id for all his following users. How will you do? UserId PostId 2222 aaaa 2222 bbbb 3333 aaaa Feeds table UserId FollowingID 1111 2222 1111 3333 1111 4444 Following table
  13. 13. Normal way Step 1: Get all following users ids from 1111. (0.2s) Step 2: For each following users: Step 2.1: Insert new record on Feeds table for that user. (0.2s) If 1111 have 50 following > system will take: 0.2 + 50*0.2 = 10.2s !!!! > Too slow!!!
  14. 14. Improved way Step 1: Get all following users ids from 1111. (0.2s) Step 2: For each following users: Step 2.1: Create feeds record for each user. (so small time) Step 3: Insert all records in one command. (0.3s) If 1111 have 50 following > system will take: 0.2 + 0.3 = 0.5s !!!! >Much faster!!!
  15. 15. Apply cache? Step 1: Get all following users ids from cache. (0.002s) Step 2: For each following users: Step 2.1: Create feeds record for each user. (so small time) Step 3: Insert all records in one command. (0.3s) Step 4: Insert all records to cache. (0.003s) If 1111 have 50 following > system will take: 0.002 + 0.3 + 0.003 = 0.305s !!!! >Much faster!!!
  16. 16. Server side - Logic
  17. 17. Server side - Logic POST / PUT/ DELETE GET Third party Data database Logic SLOW Third party Data Logic SLOW database Third party
  18. 18. POST/PUT/DELETE issues? Tasks need to do Database Third Party Request Response time > 2s Too much tasks need to do
  19. 19. POST/PUT/DELETE solution? Database Third Party Request Response time < 500 ms Realtime Background
  20. 20. How background work? It should be use message queue system. some message queue system: RabbitMQ, ZeroMQ, Kafka, Redis PubSub Main server Message queue Background server 1 Background server 2
  21. 21. Messaging queue technology PubSub pattern (AMQP, MQTT)
  22. 22. Can we make Realtime task run faster?
  23. 23. Caching for realtime task Task 1 Access DB Task 2 Update DB . OLD way Task 1 Access Cache Task 2 Update Cache . NEW way Task n Task n
  24. 24. Example when new post created by user 1111 > push notication for all following users about that. How will you do?
  25. 25. Normal way User create new post Get all following user ids. for each following user: Insert new record to Feed table call push notication method to send push notication. Return result. So take time here
  26. 26. Improved way User create new post Get all following user ids. Insert all records in one command into Feed table For each following users: Add one task to message queue to run in background. Return result. So Fast
  27. 27. GET issues? Data queries Database Third Party Request Response time > 2s Too much thing need to format Format response data Too slow
  28. 28. Solution Data queries Database Third Party Request Response time