High Performance Web Applications in the Cloud

1,295 views

Published on

T3CONNA 2013

Published in: Technology

High Performance Web Applications in the Cloud

  1. 1. Web ApplicationsHigh Performance…in the cloudT3CON NA- San Francisco - May 30, 2013
  2. 2. FabrizioBrancaLead System Developer at
  3. 3. San Francisco, CAJanineFionathat’s meIt’s a boy!
  4. 4. E-Commerce:MagentoCMS:TYPO3Portals:ZF, FLOW,…Mobile Searchperience:SOLR120 peoplein 7 officesworld-wideHighPerformance/ScaleGlobalEnterpriseProjects
  5. 5. PC games (download)Plush toys, shirts, ...
  6. 6. > 24.000.000 likes > 500.000 followersSocial MediaImpact
  7. 7. Magento TYPO3both run on a“LAMP” stack
  8. 8. your applicationone process of…execution timememory
  9. 9. that’s your server…running yourapplication
  10. 10. 𝑡𝑜𝑡𝑎𝑙 𝑚𝑒𝑚𝑜𝑟𝑦 = 𝑐𝑜𝑛𝑐𝑢𝑟𝑟𝑒𝑛𝑡 𝑢𝑠𝑒𝑟𝑠 ∗ 𝑚𝑒𝑚𝑜𝑟𝑦/𝑝𝑟𝑜𝑐𝑒𝑠𝑠256 MB/process100 users25 GB RAM1000 users250 GB RAM
  11. 11. Option 1Make your app “smaller”make itfaster!make itconsume lessmemory!
  12. 12. Option 2Make your box “bigger”a.k.a.“vertical scaling”
  13. 13. Option 3Add more boxesa.k.a.“horizontal scaling”
  14. 14. VerticalScalingOptimizationHorizontalScalingbiggerboxmoreboxessmaller “app”Scaling
  15. 15. Single ServerMulti-Servervs.Single servervs. Multi serverWhat’s the big deal?
  16. 16. Shared nothing?SessionStorageCacheCodeJS/CSSbundlesDatabaseAssets
  17. 17. Multi ServerDeployment
  18. 18. “Hello World!Free Shippingfor everyone!”“Check outour newproduct!”“HolidaySeason!”
  19. 19. Slow responsetimes, servercrashes,…
  20. 20. Waste ofmoney
  21. 21. Waste ofmoneySlow responsetimes, servercrashes,…
  22. 22. Auto Scaling!Pay per hour
  23. 23. Actually, itlooks morelike this
  24. 24. Cloud(in case you haven’tnoticed…:)
  25. 25. Amazon EC2 Amazon S3 Amazon RDSCloudFrontRoute 53ElastiCache Elastic LoadBalancingCloud ServicesAWS ManagementConsoleRightScale Amazon SWFOpsWorksAWSCloudFormation
  26. 26. EC2 instance
  27. 27. EC2 instanceServer Array(or “auto-scaling group”)Based onvarious metrics
  28. 28. Server Array(or “auto-scaling group”)EC2 instance
  29. 29. Server Array(or “auto-scaling group”)EC2 instance
  30. 30. ElasticArchitectureBooting newinstancesfully automaticAuto-healingInfrastructureas Code
  31. 31. LooseCouplingNo hardcoding!“RightScale API, giveme all frontendservers”“ELB, here I am”
  32. 32. S3Deployment XBackendArrayFrontendArrayWorkerArrayVarnishArrayS3 RDSElastiCacheCloudFront CloudFrontRoute 53shop.angrybirds.comBraintreeMailDRMGiftcardsELB
  33. 33. ELBBackendArrayFrontendArrayWorkerArrayVarnishArrayDeployment XRoute 53
  34. 34. Deployment X+1WorkerArraynt XRoute 53ELBBackendArrayFrontendArrayWVarnishArray
  35. 35. WorkerArraynt XRoute 53BackendArrayFrontendArrayWVarnishArrayDeployment X+1ELB
  36. 36. Route 53BackendArrayDeployment X+1FrontendArrayWorkerArrayVarnishArrayDeployment XELB ELB
  37. 37. DowntimeNumber oflost cartsNumber oflost sessionsand logins
  38. 38. 1.000.000unique visitors. per day.
  39. 39. concurrent users.
  40. 40. Orders.105 6789per second.Yes, per second!
  41. 41. AppVarnishReverse ProxyProtectingthe applicationOnly a fewrequests hit your app!
  42. 42. 90%VarnishTweakingCache Hitrate
  43. 43. 80%VarnishTweakingCache Hitrate
  44. 44. 98.6%VarnishTweakingCache Hitrate
  45. 45. ReduceNumber of Requests… hitting your application
  46. 46. Use aCDN
  47. 47. OffloaddynamicpartsDoAjax
  48. 48. Request a page (HTTP Request)deliver static pageRequestDelivering static contentPlaceholders for dynamic parts.Cache-Control headersAjax call request dynamic partsand transfers the id of the currently visited productJSON response with dynamic contentReplace placeholderWrite session id to cookieRender the pageBrowser Varnish Application
  49. 49. use cookies orlocalStorageDon’tAjax
  50. 50. Request a page (HTTP Request)deliver static pageRequestDelivering static contentPlaceholders for dynamic parts.Cache-Control headersAjax call request dynamic partsand transfers the id of the currently visited productJSON response with dynamic contentReplace placeholderWrite session id to cookieRender the pageBrowser Varnish Application
  51. 51. 3xx4xx5xxRedirectsClient errorsCache otherstatus codesServer errors
  52. 52. http://example.com/?utm_source=T3CON&utm_medium=slides…and many more.NormalizeURLsFilter these!
  53. 53. ReduceNumber of Requests… hitting your applicationDon’t AjaxDo Ajax3xx4xx5xxCache otherstatus codeshttp://example.com/?utm_source=T3CON&utm_medium=slidesNormalize URLsUse a CDN
  54. 54. BottleneckCandidatesDynamic requestsare still too slow?
  55. 55. RAM& CPUThat’s easy…
  56. 56. DatabaseThat’s not so easy…offload thedatabaseless queries(caching!)more efficientqueries(indexes,…)scalingshardingmaster/slavePercona Toolkit(slow) query log
  57. 57. GrowingDataTrimmingthe fat!OrdersPromotionscms / banners
  58. 58. File I/Oespecially onvirtual machines!
  59. 59. ExternalComponents Frontend?CacheBackend?Web Services?Webserver?
  60. 60. BottleneckCandidatesMemory CPU File I/ODatabaseExternalComponents
  61. 61. Launch!DeploymentSpace gamelaunch!USA wakes up
  62. 62. Thank you!Any questions?http://www.aoemedia.comhttp://www.fabrizio-branca.de@fbrncFollow me on twitter!My blog

×