Top Banner
Zzz and bla ^3 will move your to the next level. ???
101

Caching and data analysis will move your Symfony2 application to the next level

May 10, 2015

Download

Technology

If you don't ignore data you could find a business value.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 1.Zzz and bla^3will move yourto the next level.???

2. I have notinvented anythingpleaseread carefullythe referencesnot yet 3. Im @liuggio(aka Giulio De Donato)I LOVEand its dark passengerfabpot 4. _ _ _ and _ _ _will move yourto the next level.??? 5. _ _ _ and _ _ _will move yourto the next level.Symfony2application 6. proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/455.jpg HTTP/1.1"200 986 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/nav/tab_left_middle.gifHTTP/1.1" 200 1020 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"dyn-530.optus.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/5332.jpg HTTP/1.1" 200244 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)" "-"Gambardella, MatthewXML Developers GuideComputer44.952000-10-01dhcp-465.telstra.com.au - - [22/Apr/2009:18:52:51@charset "UTF-8";html,body,div,span,applet,object,iframe,h1,h2,h3,h4,+1200] "GET /gallery.php?section=entertainment HTTP/1.0" 200 58636 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en)AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=LME2 HTTP/1.1"302 378 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/ad/RH4Y.jpeg HTTP/1.1"200 1031 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/favicon.ico HTTP/1.1" 2002824 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=GD52 HTTP/1.1"302 379 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeIn your companyevery minutedata is generateda lot ofdifferenttotally 7. proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/455.jpg HTTP/1.1"200 986 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/nav/tab_left_middle.gifHTTP/1.1" 200 1020 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"dyn-530.optus.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/5332.jpg HTTP/1.1" 200244 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)" "-"dhcp-465.telstra.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /gallery.php?section=entertainmentHTTP/1.0" 200 58636 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=LME2 HTTP/1.1"302 378 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/ad/RH4Y.jpeg HTTP/1.1"200 1031 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/favicon.ico HTTP/1.1" 2002824 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=GD52 HTTP/1.1"302 379 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /stories.php?date=yesterdayHTTP/1.1" 200 4231 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /latest.php HTTP/1.1" 200 991 "-""Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, like Gecko)Version/3.1 Safari/525.13" "-"proxy-622.dsl.clear.net.nz - - [22/Apr/2009:18:52:51 +1200] "GET /latest-news.rss HTTP/1.0" 200 7199data- Difficult to read- Difficulto to measure- Time consuming 8. proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/455.jpg HTTP/1.1"200 986 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/nav/tab_left_middle.gifHTTP/1.1" 200 1020 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"dyn-530.optus.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/5332.jpg HTTP/1.1" 200244 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)" "-"dhcp-465.telstra.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /gallery.php?section=entertainmentHTTP/1.0" 200 58636 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=LME2 HTTP/1.1"302 378 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/ad/RH4Y.jpeg HTTP/1.1"200 1031 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/favicon.ico HTTP/1.1" 2002824 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=GD52 HTTP/1.1"302 379 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /stories.php?date=yesterdayHTTP/1.1" 200 4231 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /latest.php HTTP/1.1" 200 991 "-""Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, like Gecko)Version/3.1 Safari/525.13" "-"proxy-622.dsl.clear.net.nz - - [22/Apr/2009:18:52:51 +1200] "GET /latest-news.rss HTTP/1.0" 200 7199dataDifference audences and destination-business -applications -external services-error logs ( js error, and application error)- . . .sucks 9. proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/455.jpg HTTP/1.1"200 986 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/nav/tab_left_middle.gifHTTP/1.1" 200 1020 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"dyn-530.optus.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /images/photos/5332.jpg HTTP/1.1" 200244 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)" "-"dhcp-465.telstra.com.au - - [22/Apr/2009:18:52:51 +1200] "GET /gallery.php?section=entertainmentHTTP/1.0" 200 58636 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=LME2 HTTP/1.1"302 378 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/ad/RH4Y.jpeg HTTP/1.1"200 1031 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /images/favicon.ico HTTP/1.1" 2002824 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /adclick.php?c=GD52 HTTP/1.1"302 379 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, likeGecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /stories.php?date=yesterdayHTTP/1.1" 200 4231 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13(KHTML, like Gecko) Version/3.1 Safari/525.13" "-"proxy-435.dialup.xtra.co.nz - - [22/Apr/2009:18:52:51 +1200] "GET /latest.php HTTP/1.1" 200 991 "-""Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, like Gecko)Version/3.1 Safari/525.13" "-"proxy-622.dsl.clear.net.nz - - [22/Apr/2009:18:52:51 +1200] "GET /latest-news.rss HTTP/1.0" 200 7199rocksdataDifference audences and destination-business -applications -external services-error logs ( js error, and application error)- . . . 10. What we dowith data?_ _ _ _ _ !ignoretrack 11. We track data_ _ _ _ _ !ignorethen 12. dataBUSINESSVALUEthen 13. still 42.andbussinessvalue?andbussinessvalue?4242hitchhikers guide to the galaxy 14. Our code generates business value when it runs,not when we write code.@coda 15. Store log and error dataQuery on past eventsLocate the bugKnow Servers/applicationstatus: healthy/resources/Responding as it should?Face the reality of myecosystemUnderstand why andwhere the app. is slowAnalyze the behaviourwhen it s runningwatch databe alertedfast websiteNeedsdataBUSINESSVALUE 16. NeedsBUSINESSVALUEloggingdebuggingmonitoringprofilingmetrickingoptimizingActionsStore log and error dataQuery on past eventsLocate the bugKnow Servers/applicationstatus: healthy/resources/Responding as it should?Face the reality of myecosystemUnderstand why andwhere the app. is slowAnalyze the behaviourwhen it s runningwatch databe alertedfast website 17. BUSINESSVALUEloggingdebuggingmonitoringprofilingmetrickingoptimizingActionsmonolog, Logstash,GraylogSentry / GraylogNagios, Cacti external serviceXhProfstatsd-php-client,StatsD, Graphite 18. Its not about the accuracy of estimating itsabout facing the reality of uncertainty.@jimhighsmith 19. metricshttp://samate.nist.gov/index.php/Metrics_and_Measures.htmlhttp://nvlpubs.nist.gov/nistpubs/jres/104/6/j46gra.pdfThe IEEE Standard Glossary of Software Engineering Terminologyalso defines quality metric as :(1) A quantitative measure of the degree to whichan item possesses a given quality attribute.(2) A function whose inputs are software data and whose output is asingle numerical value that can be interpreted as the degree to whichthe software possesses a given quality attribute.* @param array $data* @return floatfunction calculateUglyness(array $data);Ninja territory 20. measuringhttp://samate.nist.gov/index.php/Metrics_and_Measures.htmlHOW TO MEASURE ANYTHING - FINDING THE VALUE OF INTANGIBLES IN BUSINESSsecond edition Hubbardexperimentally obtainingone or more quantity valuesthat can reasonably beattributed to a quantity.reasonably => uncertainty reductionNinja territory 21. What metricsmeans?DUNNOMerlin knows Yes Matrix Isaw the film 22. metricsVisual tool tobetter understandreality 23. metricsalign technical andbusiness vision ofIT. 24. producesgraphsDECISIONSmetrics 25. StatsD simple Node.JS daemon. Listens for message over UDPsimple daemon for easy stats aggregation.Graphite rude Graphite stores numeric time-series data. Real-time graphing system Components: Carbon stores the data in Graphites specialized database. The data can then be visualized through graphiteweb interface developed with django. Whisper allows carbon to write multiple data points.metrics 26. Symfony2 integration:theres a bundle for it liuggio/StatsDClientBundle Amount of visitor Logged vs Anonymous user Doctrine collector Amount of PHP peak Execution Time Monolog Easily add a new metric:$this->get(stats_d_client.factory)->increment(upload.file);metrics 27. Symfony2 integration PHP Peakmetricsthis is aTimer 28. Concepts Bucket Values Flush Intervalmetricsmetrics Counter Gauge Timer Set SampleUnderstand StatsD 29. GAUGES are arbitrary values, which can be recorded.metrics$factory = $this->get(stats_d_client.factory);$data[] = $factory->gauge(cart.item.number, 30);$data[] = $factory->gauge(cart.item.number, 34);$data[] = $factory->gauge(cart.item.number, 38);$this->get(stats_d_client.service)->send($data);cart.item.number|38Result is the last one (per flush time) 30. COUNTS increment and decrement a value.metrics$factory = $this->get(stats_d_client.factory);$data[] = $factory->increment(user.visitor);$this->get(stats_d_client.service)->send($data);The value stay in memory until the flush interval. 31. TIMERS collects numbers.metrics$factory = $this->get(stats_d_client.factory);$data[] = $factory->timing(php-peak, 500);$this->get(stats_d_client.service)->send($data);Operations [mean, upper, sum, lower, count, ...]are already calculated 32. Collect from different sources# echo "deploy.web:1|c" | nc -w 1 -u graphite.com 8125 33. trackeverythings thatmovescanmetrics 34. you have moredata than you thinkand you need lessdata than you thinkMORELESS 35. new metrics Why do you want to know? How much do you know now? What is the value to additionalinformation 36. The time you spend for metrics has a cost,and usually is more economicalthan many managers assume.maybe becausethey didntmeasure.bazingametrics 37. producesDECISIONSfastmetricsgood 38. good and fastDECISIONSBUSINESShelp the 39. and _ _ _will move yourto the next level.metrics??? 40. OptimizingPerformance problems?Enlargeyourprofiler 41. Great caching is like great sex.It hides all the real problems@vivekhaldar 42. Wikipedia: a Cache ( /k/ KASH[1]) is acomponent that transparently stores dataso that future requests for that data can beserved faster.the cache misshappens once for thesame response.given the same request the Cache miss happens once.given the same request the response is not processed twice.A Cache Hit happens if the Cachecontains the answer.A Cache Miss happens if the Cachedoesnt contain the answer.The perfect cache when 43. CACHEIS A RESPONSEMATTER 44. Application caching: app/cache with opcode Response caching and HTTP-CACHE Doctrine2 Query and Result Caching CDN and static files OtherCACHE + SF2 45. Terravison vendor folder is about 340 MBThe app/cache/prod folder is about 3000 files1. Annotation (Entity/Controller/...)2. Templatea. name => fileb. twig in php3. Assetic (definition)4. Url matcher, Url creator5. Translations array key=>value6. Doctrine Entity Proxy./app/cache 46. Add your class to the services with the tag kernel.cache_warmerNote: the CacheWarmerInterface is not properly the same as the snippet.cache warmernamespace SymfonyComponentHttpKernelCacheWarmer;interface CacheWarmerInterface/*** Warms up the cache.* @param string $cacheDir The cache directory*/public function warmUp($cacheDir);public function isOptional() 47. Symfony2 is a web framework built from scratch aroundthe http specification a resource could be Fresh || Stale http-caching only on safe method validation || expirationHTTP 48. HTTP cache 49. HTTP headers$response->setPublic() //default is private$response->setMaxAge(600);// Same as above but only for shared caches$response->setSharedMaxAge(600);$response->setETag(md5($response->getContent()));$response->setLastModified($datetime);if ($response->isNotModified($this->getRequest()))...$response->setVary(Accept-Encoding);symfony.com/doc/master/book/http_cache.html 50. The leastexpensivequery is thequery younever run. 51. DoctrineCommonCacheCache(Theres not tagging)doctrine cache// Fetches an entry from the cache.string function fetch($id);// Tests if an entry exists in the cache.bool function contains($id);// Put data into the cache.bool function save($id, $data, $lifeTime);// Deletes a cache entry.bool function delete($id); 52. MetaData Cache Annotation (OPCODE)Query Cache DQL parsed into SQL(OPCODE/REDIS/MEMCACHED)Result Cache The query result(REDIS/MEMCACHED/OPCODE)doctrine caches 53. doctrine cacheClass ProductRepository...$query = $this->createQueryBuilder(p)->where(p.price > :price)->setParameter(price, 19.99)->getQuery();$products = $query->getResult();$query->useResultCache(true,$lifetime,__METHOD__ . serialize($query->getParameters()));$query->useQueryCache(); 54. There are only two hard things in Computer Sciencecache invalidation and naming thingsPhil KarltonThere are only two hard things in Computer Sciencecache invalidation, naming things and off-by-1errors.anonymous 55. InvalidationEspecially for http, but in general, you should not waste time toinvalidate a value, but you should invest resources to find the righttime of validity.Cache miss stormWhen a resource is no longer available (cache miss), and is requiredby many clients simultaneously (storm), a congestion happens.cache miss storm, cache stampede,dog-piling, APC Cache slamcache 56. Pre-Caching/CachebackSometimes you need to have some data already available and youdont want that the first request wait.Uniqueness of the cache keyAttention to the conflicts in the key definition, always put a prefix ornamespace such as language or role.Http-Microcaching:Save all the responses for 1||2 secondslot of examples on internet for Nginxcache 57. and _ _ _will move yourto the next level.??? 58. Performancetips - rule #1Mantainibilitywin overPerformance 59. The user should never waitslow operation data in a queue (Redis/*MQ)processed by a consumer (cli + supersivord): Image Manipulation File Creation (pdf) Sending email as spool I/O operation Use Session with Redis/Memcache Caution on what do you do in the loop && nested loopeasy 60. tips Must! OPCODE: APC using the apc.stat = 0 $php composer.phar dump-autoload optimize Twig.c php extension Assets Minify and combine all of your CSS and JS files Run all (or just some) of your CSS or JS filesthrough some sort of compiler,such as LESS, SASS or CoffeeScript Run image optimizations on your imageshttp://symfony.com/doc/current/book/performance.htmlhttps://speakerdeck.com/alexandresalome/symfony2-and-performances 61. the DIC of sf2.3 is lazyA lazy loading value holder proxy is a virtual proxy that wraps andlazily initializes a "real" instance of the proxied class.When do I use a lazy value holder?-Your object takes a lot of time and memory to be initialized (with alldependencies)-Your object is not always used, and the instantiation overhead can beavoidedgithub.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-value-holder.mdgithub.com/Ocramius/symfony-docs/blob/master/components/dependency_injection/lazy_services.rst 62. Cache Driver# config_prod.ymlservices:cache:class: DoctrineCommonCacheApcCache #MemcacheCache# config_dev.ymlservices:cache:class: DoctrineCommonCacheArrayCacheif ($fooString = $this->get(cache)->fetch(foo)) {$foo = unserialize($fooString);} else {// do something with $foo$this->get(cache)->save(foo, serialize($foo),$lifetime);}http://docs.doctrine-project.org/en/latest/reference/caching.html 63. DOCTRINEObject relational mapper(ORM) for PHP that sits ontop of a powerful databaseabstraction layer (DBAL) 64. doctrine >=2.4New features:https://speakerdeck.com/asm89/what-is-new-in-doctrineit ill be faster ?NO 65. doctrine >= 2.32.4 flush multiples entities$em->flush(array($entityA, $entityB);2.4 paginator2.4 master slave2.4 join to the interface2.3 You can override metadata2.3 Event listener in a separated class/*** @ORMManyToOne(targetEntity="Tvision...EntityStatusInterface")**/https://speakerdeck.com/asm89/what-is-new-in-doctrine 66. Optimize Doctrinehttp://xkcd.com/1195/ 67. Optimize Doctrinehttps://doctrine-orm.readthedocs.org/en/latest/reference/unitofwork.htmlstep1:deeply understand UOWstep2:goto step1 68. $article = new Article();$article->setHeadline(I love PHPday);$em->persist($article); // the entity is managed$em->flush(); // the entity is persisted...$article->setHeadline(I love JSday and PHPday);$em->flush(); // the Headline is updatedon the persistence layer$em->persist($article); 69. $article = $em->find(Article, 1234);$article->setHeadline(I love GRUSP);$article2 = $em->find(Article, 1234);echo $article2->getHeadline(); // I love GRUSPif ($article === $article2) ---> true!! 70. Unit of workhttps://doctrine-orm.readthedocs.org/en/latest/reference/unitofwork.htmlMaintains a list of objects affected by a business transaction andcoordinates the writing out of changes and the resolution of concurrencyproblems.P of EAA page 184 Patterns of Enterprise Application Architectureby Martin FowlerUOW = keeps trackchanges of ObjectsTL;DR 71. Identity MapThe flush has a cost Number of managed Entities Tracking policy Type of entitieshttps://doctrine-orm.readthedocs.org/en/latest/reference/unitofwork.htmlcontains all the managed entitiesOn flush makes a property by property comparison for all theentities managed. 72. tracking policyDoctrine definition:is the process of determining what has changed in managed entitiessince the last time they were synchronized with the database. implicit tracking (default and simple) explicit tracking (suggested for lot of entities managed) notify tracking/*** @Entity* @ChangeTrackingPolicy("DEFERRED_EXPLICIT)http://docs.doctrine-project.org/en/latest/reference/change-tracking-policies.htmlFlush optimization #1 73. tracking policyDeferred ImplicitUOW = DBhttp://docs.doctrine-project.org/en/latest/reference/change-tracking-policies.htmlDeferred ExplicitUOW != DB UOW = I love PUG Roma DB is not updated.Need the persist!Flush optimization #1// $article is already managed or loaded// we are changing the Headline$article->setHeadline(I love PUG Roma);$em->flush();echo $article->getHeadline();// is I love PUG Roma 74. Read only entity/*** @Entity* @READONLY*/Class Status {$em->getUnitOfWork->markReadOnly($entity);Temporarily mark entities as read onlyFlush optimization #2 75. Flush only on fewentities$em->flush($entity)Flush optimization #3 76. Reducing theflush costThe flush has a cost Number of managed Entities (flushing only some) Tracking policy (explicit || implicit) Type of entities (read-only || temp. read-only)Recap. 77. reference$post = $postRepository->find($postId);$comment->setPost($post);...// $postId comes from somewhere$comment->setPost($em->getReference(AcmeBundleEntityPost, $postId));. 78. lazy associationsAssociation are LAZY by default// Order/*** @ManyToOne(targetEntity=Cart, cascade={all},fetch=EAGER)*/private $cart