Transcript
  • 1. Caching and tuning funfor high scalability Wim Godden Cu.be Solutions

2. Who am I ?Wim Godden (@wimgtr)Owner of Cu.be Solutions (http://cu.be)Open Source developer since 1997Developer of OpenXZend Certified EngineerZend Framework Certified EngineerMySQL Certified Developer 3. Who are you ?Developers ?System/network engineers ?Managers ?Caching experience ? 4. Goals of this tutorialEverything about caching and tuningA few techniques How-to How-NOT-to Increase reliability, performance and scalability5 visitors/day 5 million visitors/day(Dont expect miracle cure !) 5. LAMP 6. Architecture 7. Test page3 DB-queries select firstname, lastname, email from user where user_id = 5; select title, createddate, body from article order by createddate desc limit 5; select title, createddate, body from article order by score desc limit 5;Page just outputs result 8. Our base benchmarkApachebench = useful enoughResult ?Single webserverProxyStatic PHP Static PHPApache + PHP3900 17.56700 17.5Limit : Limit :CPU, network databaseor disk 9. Caching 10. What is caching ?CACHE 11. What is caching ? x = 5, y = 2 Same resultn = 50 CACHE select * from articlejoin user Doesnt changeon article.user_id = user.idall the time order by created desc limit 10 12. Theory of cachingDBle t ab fro m ul t res ata ned e ct d retursel ta = $da if ($data == false) Page GET /pageset( key, $$dafals data)ta = eget( key)Cache 13. Theory of cachingDBHITCache 14. Caching techniques#1 : Store entire pages #2 : Store part of a page (block) #3 : Store data retrieval (SQL ?) #4 : Store complex processing result #? : Your call !When you have data, think :Creating time ?Modification frequency ?Retrieval frequency ? 15. How to find cacheable dataNew projects : start from cache everythingExisting projects : Look at MySQL slow query log Make a complete query log (dont forget to turn it off !) Check page loading times 16. Caching storage - DiskData with few updates : goodCaching SQL queries : preferably notDONT use NFS or other network file systems especially for sessions locking issues ! high latency 17. Caching storage - Disk / ramdiskLocal5 Webservers 5 local cachesHow will you keep them synchronized ? Dont say NFS or rsync ! 18. Caching storage - Memcache(d)Facebook, Twitter, YouTube, need we say more ?Distributed memory caching systemMultiple machines 1 big memory-based hash-tableKey-value storage systemKeys - max. 250bytesValues - max. 1Mbyte 19. Caching storage - Memcache(d)Facebook, Twitter, YouTube, need we say more ?Distributed memory caching systemKey-value storage system Keys - max. 250bytes Values - max. 1MbyteExtremely fast... non-blocking, UDP (!) 20. Memcache - where to install 21. Memcache - where to install 22. Memcache - installation & running itInstallation Distribution package PECL Windows : binariesRunning No config-files memcached -d -m -l -p ex. : memcached -d -m 2048 -l 172.16.1.91 -p 11211 23. Caching storage - Memcache - some notesNot fault-tolerant Its a cache ! Lose session data Lose shopping cart data ... 24. Caching storage - Memcache - some notesNot fault-tolerant Its a cache ! Lose session data Lose shopping cart data Firewall your Memcache port ! 25. Memcache in code


Recommended