![Page 1: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/1.jpg)
RATIONALLYBOOSTSYMFONY2APPLICATION
2014 VERSION
![Page 2: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/2.jpg)
welcometothebundle.com@liuggio welcometothebundle.com
![Page 3: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/3.jpg)
PERFORMANCE PROBLEM?
![Page 4: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/4.jpg)
PERFORMANCE PROBLEM?TODAY SPEED IS A FEATURE
![Page 5: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/5.jpg)
BUSINESSNEEDSSPEED?
(speed in terms of adding a new feature, bug hunting ...)
![Page 6: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/6.jpg)
loadbalancer
reverseproxy
CDN
web server
MQ
DBcache
sessionstorage
DB
internalstorage
BROWSER
privatecache
shared cache
DNS
ISP
your company
![Page 7: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/7.jpg)
GUESS
PRIDE PREJUDICE AND GUESSING
![Page 8: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/8.jpg)
THEENDLESSCYCLE
make change
benchmark
profile
![Page 9: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/9.jpg)
benchmarking
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
the process of comparing …
sterilized environment - disable profiler
1
![Page 10: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/10.jpg)
ab$ apt-get install apache-utils$ ab -e output.csv -c 10 -t 10 http://book.local$ ab -p post.txt -T application/x-www-form-urlencoded -e output.csv -kc 10 -t 10 http://book.local
● http_load simple● siege complete● jmeter complex
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 11: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/11.jpg)
ProfilingXHProf demo ...2
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
make change
benchmark
profile
![Page 12: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/12.jpg)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 13: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/13.jpg)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 14: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/14.jpg)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 15: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/15.jpg)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 16: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/16.jpg)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 17: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/17.jpg)
Make Changes
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
3
make change
benchmark
profile
![Page 18: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/18.jpg)
404 silver bulletNot Found
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 19: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/19.jpg)
● Think as readonly filesystem● Don’t let the user wait● Caches are your friends
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
● Try to quit from the optimization-cycle
![Page 20: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/20.jpg)
PHPAPC
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
● apc.stat=0 (need maintenance)● fragmentation
(symfony is not slow! opcode, php 5.4, apc)
![Page 21: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/21.jpg)
● Zend Opcode● ACPu (emulate all the apc_* calls)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
PHP5.5
![Page 22: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/22.jpg)
HHVM->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
(hhvm - HPHPc - Performance on real application)
![Page 23: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/23.jpg)
HHVM = PHP++ ?->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
(HHVM is a great opportunity for Symfony and for object oriented lovers)
![Page 24: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/24.jpg)
symfonyecosystem● $ composer dump-autoload --optimize
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
● twig extension http://twig.sensiolabs.org/doc/installation.html
![Page 25: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/25.jpg)
symfonyecosystem● [ASSETIC] use assetic and CDN, compress and minify files
● [SWIFT MAILER] email in the spool like Redis/Gearman or MQ (remember to flush)
● [PROXY] no logic in the constructor!
<service id="foo" class="Acme\Foo" lazy="true" />
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 26: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/26.jpg)
[MONOLOG] don’t log to file in production debugging: Sentry or Graylog
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 27: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/27.jpg)
yourcachewarmup->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 28: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/28.jpg)
liip/LiipDoctrineCacheBundle
Doctrine/Common/CacheWithout bundle
services.yml
in your application
Use a bundle
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 29: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/29.jpg)
doctrineORM● Database Abstraction Layer (DBAL)● Object Relational Mapper (ORM)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 30: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/30.jpg)
ORMcachesmetadata, query, result
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change
![Page 31: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/31.jpg)
understandUOWUnit Of Work
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 32: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/32.jpg)
UOWeffect
TLDR;
keeps track changes of objectsand coordinates the writing
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the
resolution of concurrency problems
![Page 33: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/33.jpg)
UnitofWork
Managed
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 34: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/34.jpg)
UnitofWork
Managed
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 35: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/35.jpg)
UOWeffect
flush is expensive* while { …. $this->em->persist($v); $this->em->flush() }
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
* profile your domain first.
![Page 36: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/36.jpg)
Reducing the flush cost*
— Number of managed Entities
— Type of entities (Read-Only)
$em->flush($entity);
/** * @Entity * @READONLY*/ Class Status {
$em->getUnitOfWork() ->markReadOnly($entity);
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
* if you really need
![Page 37: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/37.jpg)
Reducing the flush cost*/** @Entity * @ChangeTrackingPolicy("DEFERRED_EXPLICIT”)
tracking policy
implicit DB === UOW explicit DB != OUW
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
* if you really need
![Page 38: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/38.jpg)
doctrineORM● Reference
● Partial object*
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
$q = $em->createQuery("select partial u.{id,name} from \Domain\User u");
$comment->setPost($em->getReference(‘AcmeBundleEntityPost’, $postId));
* smelling tip, inconsistent objects
![Page 39: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/39.jpg)
doctrineORM
● Change Hydration *
HYDRATE_OBJECT
$query->setHydrationMode(\Doctrine\ORM\Query::HYDRATE_ARRAY); HYDRATE_SCALAR HYDRATE_SINGLE_SCALAR HYDRATE_SIMPLEOBJECT
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
* Object Oriented will cry.
![Page 40: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/40.jpg)
theHidden Hydrationcache *
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
* Be careful, only for Read operations
![Page 41: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/41.jpg)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
theHydrationcache * With ResultCache
With HydrationCache
* profile data from my domain not yours.
![Page 42: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/42.jpg)
cacheproblem● invalidation● cache miss storm
morelesscache● pre-caching cache-back● microcaching
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 43: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/43.jpg)
doctrineORMassociation● Fetching is LAZY by default
● Changing for some queries
● Fetching EXTRA LAZY
$query = …$query->setFetchMode(“Order”, “Cart”, “LAZY”);
->contains($entity); ->count(); ->slice($offset, $length);
/*** @ManyToOne(targetEntity=”Cart”, cascade={“all”}, fetch=”EAGER”)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 44: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/44.jpg)
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
HTTPCache
● http specification● validation / expiration● safe methods● Edge Side Included
http://symfony.com/doc/current/book/http_cache.html
![Page 45: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/45.jpg)
measure … and Metrics?● Behaviour● Measure applications data● Don’t use for benchmarking
Visual tool to better understand the reality
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
![Page 46: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/46.jpg)
benchmark->profile->make change
metrics produces graphs decisions
composer install liuggio/statsd-client-bundle ~1
![Page 47: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/47.jpg)
Optimizing dev tool
->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->profile->make change->benchmark->
https://www.flickr.com/photos/itomcash/12953162645/sizes/l/
(multiple xdebug configs, db on ram, tricks, shared and private fixtures)
![Page 48: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/48.jpg)
OOD, SOA, DDD, 12factorsArchitecture
![Page 49: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/49.jpg)
BALANCED
OPTIMIZATION vs MAINTAINABILITY
BE
![Page 50: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/50.jpg)
References1. http://labs.qandidate.com/blog/2013/10/21/running-symfony-standard-on-hhvm/2. http://www.appdynamics.com/blog/php/php-performance-crash-course-part-1-the-basics/3. https://support.cloud.engineyard.com/entries/26902267-PHP-Performance-I-Everything-You-Need-
to-Know-About-OpCode-Caches4. https://speakerdeck.com/dshafik/lonestar-php-fast-not-furious-how-to-identify-and-fix-slow-code5. http://share.ez.no/learn/ez-publish/ez-publish-performance-optimization-part-1-of-3-introduction-
and-benchmarking/%28page%29/56. http://www.linuxhelp.in/2012/11/benchmarking-with-http-load.html7. https://speakerdeck.com/bastianhofmann/profiling-php-applications8. http://www.symfony.com9. http://blog.ircmaxell.com/2013/09/rambling-on-internals.html
10. .P of EAA page 184 Patterns of Enterprise Application Architecture by Martin Fowler11. https://doctrine-orm.readthedocs.org/en/latest/reference/unitofwork.html12. http://docs.doctrine-project.org/en/latest/reference/change-tracking-policies.htmlFlush optimization13. http://slides.seld.be/?file=2011-10-20+High+Performance+Websites+with+Symfony2.html#1
Credits:https://www.flickr.com/photos/kelehen/8962203423https://www.flickr.com/photos/itomcash/12953162645
![Page 51: Benchmark Profile and Boost your Symfony application](https://reader034.vdocuments.us/reader034/viewer/2022051412/54b4ee354a795994458b46cb/html5/thumbnails/51.jpg)
QUESTIONSAREALWAYSBETTERTHANANSWERS
@liuggio
https://joind.in/10783