sensible scaling

Download Sensible scaling

Post on 10-Jun-2015

4.522 views

Category:

Technology

1 download

Embed Size (px)

DESCRIPTION

Talk from 4Developers '12 and PHP Barcelona '11 It’s fun to architect your application to handle millions of pageviews, but in reality that’s time where you could be adding features. We’ll examine some practical solutions for designing your platform to deal with increasing traffic and how to add those features on an incremental basis. This will take us through options for scaling the code and additional methods for scaling the infrastructure.

TRANSCRIPT

  • 1. Sensible Scaling Rowan Merewood

2. Sensible ScalingIf your application doesnt scale, its your fault not mine. Rasmus Lerdorf (@rasmus)Rowan Merewood 3. Who? 4. Who?@rowan_m 5. Who?@rowan_mSoftware Engineer& Team Lead 6. Who?@rowan_mSoftware Engineer& Team Lead@ibuildings &@techportal 7. Why? 8. Why?Ive built small apps 9. Why?Ive built small appsand pretty large ones 10. Why?Ive built small appsand pretty large onesIve seen massiveover-engineering 11. Why?Ive built small appsand pretty large onesIve seen massiveover-engineeringand platforms thatcannot scale 12. TDD Principles 13. TDD PrinciplesWrite only enoughcode to pass the test 14. TDD PrinciplesWrite only enoughcode to pass the testDo not over-engineer 15. TDD PrinciplesWrite only enoughcode to pass the testDo not over-engineerDont give away workfor free! 16. Build for now 17. Build for now Dont be afraid to throw code away 18. Build for now Dont be afraid to throw code away XPs spikes 19. Build for now Dont be afraid to throw code away XPs spikes Take advantage of current tech. without tying yourself to it 20. Who are your users? 21. Who are your users?Lots of short visits? 22. Who are your users?Lots of short visits?Anonymous orsession-based? 23. Who are your users?Lots of short visits?Anonymous orsession-based?Long, complexinteractions? 24. Who are your users?Lots of short visits?Anonymous orsession-based?Long, complexinteractions?Subscribers orfree users? 25. Monitor and Analysehttp://community.plus.net/blog/2011/10/24/a-record-setting-manchester-derby/ 26. Monitor and AnalysePredict usagepatternshttp://community.plus.net/blog/2011/10/24/a-record-setting-manchester-derby/ 27. Monitor and AnalysePredict usagepatternsPlan for peaks andtroughshttp://community.plus.net/blog/2011/10/24/a-record-setting-manchester-derby/ 28. Profiling 29. ProfilingYou do not knowwhat is slow 30. ProfilingYou do not knowwhat is slowEnsure you measuremore than just code! 31. Profiling 32. ProfilingPHP - Xdebug Derick Rethans (@derickr)Kcachegrind, Webgrind, etc. 33. ProfilingPHP - Xdebug Derick Rethans (@derickr)Kcachegrind, Webgrind, etc.PHP XHProf 34. ProfilingPHP - Xdebug Derick Rethans (@derickr)Kcachegrind, Webgrind, etc.PHP XHProfJavaScript Firebug 35. ProfilingPHP - Xdebug Derick Rethans (@derickr)Kcachegrind, Webgrind, etc.PHP XHProfJavaScript FirebugJavaScript Venkman 36. ProfilingPHP - Xdebug Derick Rethans (@derickr)Kcachegrind, Webgrind, etc.PHP XHProfJavaScript FirebugJavaScript VenkmanGeneral page display - YSlow 37. ProfilingCPU Load top & /proc/loadavg 38. ProfilingCPU Load top & /proc/loadavgDisk IO iotop 39. ProfilingCPU Load top & /proc/loadavgDisk IO iotopMemory free 40. ProfilingCPU Load top & /proc/loadavgDisk IO iotopMemory freeNetwork netstat 41. ProfilingCPU Load top & /proc/loadavgDisk IO iotopMemory freeNetwork netstatMonitoring watch & time 42. Profiling under load 43. Profiling under loadCode bottlenecks !=Platform bottlenecks 44. Profiling under loadCode bottlenecks !=Platform bottlenecksTest in production,if possible 45. Profiling under loadCode bottlenecks !=Platform bottlenecksTest in production,if possibleUse multiple VMs(Vagrant can helpautomate this) 46. Profiling under loadCode bottlenecks !=Platform bottlenecksTest in production,if possibleUse multiple VMs(Vagrant can helpautomate this)Use siege & ab 47. Finding bottlenecks 48. Finding bottlenecksRight Wrong 49. Finding bottlenecksRight WrongDatabase 50. Finding bottlenecksRight WrongDatabaseDisk IO 51. Finding bottlenecksRight WrongDatabaseDisk IOExternal services 52. Finding bottlenecksRight WrongDatabaseDisk IOExternal servicesApplication work 53. Finding bottlenecksRight WrongDatabaseAutoloadersDisk IOExternal servicesApplication work 54. Finding bottlenecksRightWrongDatabaseAutoloadersDisk IO Config filesExternal servicesApplication work 55. Finding bottlenecksRightWrongDatabaseAutoloadersDisk IO Config filesExternal services LoggingApplication work 56. Finding bottlenecksRightWrongDatabaseAutoloadersDisk IO Config filesExternal services LoggingApplication workObject instantiation 57. Finding bottlenecksRightWrongDatabaseAutoloadersDisk IO Config filesExternal services LoggingApplication workObject instantiationFrameworks 58. Finding bottlenecksRight WrongDatabaseAutoloadersDisk IO Config filesExternal services LoggingApplication workObject instantiationFrameworksAsk Jo (@juokas)about Doctrine! 59. Tell users its slow 60. Tell users its slowUser experience !=Raw speed 61. Tell users its slowUser experience !=Raw speedKeep the UIresponsive 62. Tell users its slowUser experience !=Raw speedKeep the UIresponsiveSet expectations 63. Tell users its slowUser experience !=Raw speedKeep the UIresponsiveSet expectationsAdapt to changes(@blongden) 64. Fail gracefully 65. Fail gracefullyActively chooseto time-out 66. Fail gracefullyActively chooseto time-outPrioritisecore/profitablefunctionality 67. Fail gracefullyActively chooseto time-outPrioritisecore/profitablefunctionalityHave aBIG RED BUTTON 68. Separate functionality 69. Separate functionality AdminBatch 70. Separate functionality Admin BatchDifferent users ==diff. requirements 71. Separate functionality Admin BatchDifferent users ==diff. requirementsNo cache 72. Separate functionality Admin BatchDifferent users ==diff. requirementsNo cacheMaster storage 73. Separate functionality Admin BatchDifferent users ==diff. requirementsNo cacheMaster storageSecurity 74. Separate functionality Admin BatchDifferent users == Not time criticaldiff. requirementsNo cacheMaster storageSecurity 75. Separate functionality Admin BatchDifferent users == Not time criticaldiff. requirements CPU/RAM hungryNo cacheMaster storageSecurity 76. Separate functionality Admin BatchDifferent users == Not time criticaldiff. requirements CPU/RAM hungryNo cache nice / ioniceMaster storageSecurity 77. Separate functionality Admin BatchDifferent users == Not time criticaldiff. requirements CPU/RAM hungryNo cache nice / ioniceMaster storage Network rate limitingSecurity 78. Separate functionality Admin BatchDifferent users == Not time criticaldiff. requirements CPU/RAM hungryNo cache nice / ioniceMaster storage Network rate limitingSecurity Read only? 79. Configure hardware correctly 80. Configure hardware correctlyWhat is required for1 request? 81. Configure hardware correctlyWhat is required for1 request?How manyconcurrent requests? 82. Configure hardware correctlyWhat is required for1 request?How manyconcurrent requests?Is it a linear scale? 83. Configure hardware correctlyWhat is required for1 request?How manyconcurrent requests?Is it a linear scale?Ask yourhosting company 84. Aim for services 85. Aim for services 86. Obey the Law of Demeter 87. Obey the Law of DemeterTalk to your friends,dont talk tostrangers 88. Obey the Law of DemeterTalk to your friends,dont talk tostrangersPromotesloose coupling 89. Obey the Law of Demeter Good Bad 90. Obey the Law of Demeter Good $person->requestPayment($amount); Bad 91. Obey the Law of Demeter Good $person->requestPayment($amount);Bad$wallet = $person->getWallet();$wallet->getMoney($amount); 92. Obey the Law of Demeter Good Bad 93. Obey the Law of Demeter Good Bad 94. Obey the Law of Demeter Good Bad 95. Create immutable objects 96. Create immutable objectsObjects that cannot change after creation 97. Create immutable objectsObjects that cannot change after creationCopy On Write (COW - unicode cow) 98. Create immutable objectsObjects that cannot change after creationCopy On Write (COW - unicode cow)More memory-hungry, but easy to roll back 99. Create immutable objectsObjects that cannot change after creationCopy On Write (COW - unicode cow)More memory-hungry, but easy to roll backValue objects should be immutable 100. Create immutable objectsObjects that cannot change after creationCopy On Write (COW - unicode cow)More memory-hungry, but easy to roll backValue objects should be immutableThink of them like a response from a service 101. Identify single server factors 102. Identify single server factorsFile uploads / user content 103. Identify single server factorsFile uploads / user contentIP restrictions / server access 104. Identify single server factorsFile uploads / user contentIP restrictions / server accessLicensing? 105. Create services 106. Create servicesYour API should be: 107. Create servicesYour API should be:Independent ofapplication state 108. Create servicesYour API should be:Independent ofapplication stateLoosely coupled 109. Create servicesYour API should be:Independent ofapplication stateLoosely coupledAccepting/returningimmutable objects 110. Use caches 111. Use caches REST-ful services over HTTP let you cache easily 112. Use caches REST-ful services over HTTP let you cache easily Internal caching is trickier, but out-of- the-box with most frameworks 113. Use cachesREST-ful servicesover HTTP let youcache easilyInternal caching istrickier, but out-of-the-box with mostframeworksProxy other peoples services through your own cache! 114. Use queues 115. Use queuesFull blown job server:Gearman 116. Use queuesFull blown job server:GearmanAMQPimplementation:RabbitMQ 117. Use queuesFull blown job server:GearmanAMQPimplementation:RabbitMQLight-weight sockets:0MQ 118. Use the right storage 119. Use the right storage 120. Use the right storage ConsistencyAvailabilityPartitioning 121. Use the right storage ConsistencyAvailabilityEnforced consistency Eventual consistency(RDBMS) (NoSQL) Partitioning 122. Scale your storage 123. Sca