SlideShare a Scribd company logo
1 of 71
Download to read offline
Marko Mitranić Aleksandar Ilić Milomir Dragović
1.
●
●
●
●
https://markomitranic.github.io/
PHP-Serbia-2019-Performance/
or shorthand
https://bit.ly/2EmfCZU
1. Edit the /Docker/.env file by inserting your own BlackFire credentials and changing the ports if needed.
2. Enter the project’s Docker folder and execute ./deploy.sh.
3. Visit http://localhost:80/. That’s it.
   
   
   
Improving performance is all
about optimizing resource usage
Don’t optimize before
knowing what is slowing down
your application
“For premature optimization is
the root of all evil.”
'SUPERSTITION' IN THE PIGEON
1. Profile key pages
2. Start from the slowest ones
3. Compare and analyze profiles to spot differences and bottlenecks
4. Always look for the biggest (solvable) bottleneck
5. Not all bottlenecks should be solved, sometimes they are the price of business
The creature in the picture is a “Dwarf in the flask” from
Fullmetal Alchemist anime.
It was a successful experiment which broke its own flask
and eventually nearly managed to kill everyone.
The author did not plan on such success, so they did not
take a great amount of precautions.
Sometimes, you just grew out of your flask. Your failed
performance can be compensated for via creating a good
flexible app && server architecture.
The solution is not always the code, it lies more often in the
architecture of the app. Keep it as simple as possible, but
prepare for the future.
Splitting responsibilities, granulating your application into smaller
ones, DB sharding or caching, CDN, continuous integration.
But this is a topic for a whole set of other workshops...
When faced with a really heavy query, there is usually not much you can do.
Sometimes you can do better indexing, optimize joins, even do some caching.
40k Client entities in total
Sort and extract top 10. Based on a complex set of requirements.
Symfony 3.4 | MongoDB 3.3 | Doctrine ODM
Query Took ~6.2 seconds to complete.
On each non-cached load of this page.
The business logic is what it is, you can’t make it simpler because it suits you.
What you would usually do is start optimizing the query. Indexing, making joins when
possible etc.
But in this case all of that was already done by the previous team…
So, it seems that no code could be improved.
Not true. Once you have a bird’s-eye view of the code execution you start to notice the real
problems.
1. By some weird and not-easy-observable edge case, the query is run twice.
2. The real bottleneck is not DB, it is ODM.
Based on this, first we saved 3.1s by handling the edge case.
Then we created a new reader which simply uses direct DB queries for this particular query.
In the end, we use Symfony Cache mechanism to only run this once per day.
Sometimes, you simply don’t have the real need for using Doctrine document Hydration.
Yes, i said it.
Instead you can instead use Array or Scalar fetch methods.
What is little known to developers who have never worked dealt withSQL directly is the
ability to prepare changes and trigger a DB transaction at a specific time.
In doctrine it’s called a flush().
All the changes that you make on entities are only saved to the database once you call the
flush method.
This is a double edged sword...
Never flush within a loop.
Unless..
Large transactions can also be slooow.
You need to find a sweetspot if dealing with large
datasets.
With MongoDB we usually use ~400 entities per
transaction, except in cases where there are a lot
of changes.
Sometimes you don’t even have to loop. Try using multi updates when updating the
whole set of documents in the same way.
● Always evaluate query speed when not sure.
● Use Cursors whenever possible.
● Watch out for N+1 Problems
● DB Calls within a loop - use prepared statements.
● ***Learn to properly use Indexes and Cardinality***
● Enable slow query log and make sure none of your queries do a full table scan.
If all else is done but you still have a problem with the volume of work (user visits, queries) it
might be time to start researching scaling techniques. (remember our Dwarf in the flask?)
Usually in these applications the same bottlenecks remain present.
Research database sharding, replication and DB caching layer.
https://www.youtube.com/watch?v=GDqtEyhjpqU
Long running scripts often deal with some sort of watcher jobs or migrations.
For example, here we got this 160.000 users, take each one and match them to their
respective data from another system via a backchannel call.
Take a user from DB, Call API and match, Save changes. Repeat x140k.
● In these cases optimizing cache is useless, and workload is often huge.
● PHP has a composer vendor libraries problem with RAM leaks.
● Script works for hours, racks up maximum ram and then stalls slower and slower when
GC kicks in.
Always practice to use Dependency Injection instead of (ab)using Container directly.
Apart from being a prettier and more maintainable code style, this allows Symfony to
not-recompile parts of the container during the request.
One of our sites used IPS Community Forums and was running PHP 7.0
The vendor fully supports PHP up to 5.4 and 7.4.
One of the plugins installed, the author used mb_strripos which only works good on 7.3
...
Sometimes a cache can be slow.
By default, most built-in caching mechanisms use Filesystem storage.
If you hit this bump, try with Redis, Varnish, or memcache.
Combine technologies when you see an opportunity.
● When instantiating objects within a big loop, use a factory which clones a prototype of
the object instead of new MyObject(); (66% faster).
● If you are working with objects of large cardinality, use named classes instead of
arrays. Use stdclass never.
● Avoid these slow built-in PHP functions.
https://github.com/dseguy/clearPHP/blob/master/rules/avoid-those-slow-functions.md
● Use associative arrays basically never.
https://steemit.com/php/@crell/php-use-associative-arrays-basically-never
Don’t optimize before
knowing what is slowing down
your application
“For premature optimization is
the root of all evil.”
●
●
○
●
○
●
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire

More Related Content

What's hot

Current status of PSR - Phpblt1
Current status of PSR - Phpblt1Current status of PSR - Phpblt1
Current status of PSR - Phpblt1Yui Sakamoto
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using GearmanEric Cho
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLIJacques Woodcock
 
Khanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionKhanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionJavaScript Meetup HCMC
 
CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011Graham Weldon
 
Asynchronous programming - .NET Way
Asynchronous programming - .NET WayAsynchronous programming - .NET Way
Asynchronous programming - .NET WayBishnu Rawal
 
A first look into the Project Loom in Java
A first look into the Project Loom in JavaA first look into the Project Loom in Java
A first look into the Project Loom in JavaLukas Steinbrecher
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)danwrong
 
PyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingPyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingJuti Noppornpitak
 
Myphp-busters: symfony framework
Myphp-busters: symfony frameworkMyphp-busters: symfony framework
Myphp-busters: symfony frameworkStefan Koopmanschap
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pieTomas Doran
 
Node.js exception handling
Node.js exception handlingNode.js exception handling
Node.js exception handlingMinh Hoang
 
Myphp-busters: symfony framework (PHPCon.it)
Myphp-busters: symfony framework (PHPCon.it)Myphp-busters: symfony framework (PHPCon.it)
Myphp-busters: symfony framework (PHPCon.it)Stefan Koopmanschap
 
MySQL::Replication (Melbourne Perl Mongers 2011-07)
MySQL::Replication (Melbourne Perl Mongers 2011-07)MySQL::Replication (Melbourne Perl Mongers 2011-07)
MySQL::Replication (Melbourne Perl Mongers 2011-07)Alfie John
 
A look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architectureA look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architectureAimee Maree Forsstrom
 
CakePHP - The Path to 2.0
CakePHP - The Path to 2.0CakePHP - The Path to 2.0
CakePHP - The Path to 2.0Graham Weldon
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machineelliando dias
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swposcon2007
 

What's hot (20)

Current status of PSR - Phpblt1
Current status of PSR - Phpblt1Current status of PSR - Phpblt1
Current status of PSR - Phpblt1
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using Gearman
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
 
Khanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionKhanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solution
 
CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011
 
Asynchronous programming - .NET Way
Asynchronous programming - .NET WayAsynchronous programming - .NET Way
Asynchronous programming - .NET Way
 
A first look into the Project Loom in Java
A first look into the Project Loom in JavaA first look into the Project Loom in Java
A first look into the Project Loom in Java
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
 
Node.JS
Node.JSNode.JS
Node.JS
 
PyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingPyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous Programming
 
Myphp-busters: symfony framework
Myphp-busters: symfony frameworkMyphp-busters: symfony framework
Myphp-busters: symfony framework
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
Zero mq logs
Zero mq logsZero mq logs
Zero mq logs
 
Node.js exception handling
Node.js exception handlingNode.js exception handling
Node.js exception handling
 
Myphp-busters: symfony framework (PHPCon.it)
Myphp-busters: symfony framework (PHPCon.it)Myphp-busters: symfony framework (PHPCon.it)
Myphp-busters: symfony framework (PHPCon.it)
 
MySQL::Replication (Melbourne Perl Mongers 2011-07)
MySQL::Replication (Melbourne Perl Mongers 2011-07)MySQL::Replication (Melbourne Perl Mongers 2011-07)
MySQL::Replication (Melbourne Perl Mongers 2011-07)
 
A look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architectureA look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architecture
 
CakePHP - The Path to 2.0
CakePHP - The Path to 2.0CakePHP - The Path to 2.0
CakePHP - The Path to 2.0
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
 

Similar to 2019 PHP Serbia - Boosting your performance with Blackfire

2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
 
PHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in phpPHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in phpAhmed Abdou
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruitBruce Werdschinski
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthPhilip Norton
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practiceswebuploader
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability MistakesJohn Coggeshall
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesJohn Coggeshall
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara AnjargolianHakka Labs
 
NoSQL into E-Commerce: lessons learned
NoSQL into E-Commerce: lessons learnedNoSQL into E-Commerce: lessons learned
NoSQL into E-Commerce: lessons learnedLa FeWeb
 
Lessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at CraigslistLessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at CraigslistJeremy Zawodny
 
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di PriscoFwdays
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidStanojko Markovik
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGearsAlessandro Molina
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 
Troubleshooting: The Two Laws - IXIASOFT User Conference 2016
Troubleshooting: The Two Laws - IXIASOFT User Conference 2016Troubleshooting: The Two Laws - IXIASOFT User Conference 2016
Troubleshooting: The Two Laws - IXIASOFT User Conference 2016IXIASOFT
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 
Bp106 Worst Practices Final
Bp106   Worst Practices FinalBp106   Worst Practices Final
Bp106 Worst Practices FinalBill Buchan
 

Similar to 2019 PHP Serbia - Boosting your performance with Blackfire (20)

2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
PHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in phpPHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in php
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruit
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practices
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability Mistakes
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 Mistakes
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
NoSQL into E-Commerce: lessons learned
NoSQL into E-Commerce: lessons learnedNoSQL into E-Commerce: lessons learned
NoSQL into E-Commerce: lessons learned
 
Lessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at CraigslistLessons Learned Migrating 2+ Billion Documents at Craigslist
Lessons Learned Migrating 2+ Billion Documents at Craigslist
 
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di Prisco
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGears
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Troubleshooting: The Two Laws - IXIASOFT User Conference 2016
Troubleshooting: The Two Laws - IXIASOFT User Conference 2016Troubleshooting: The Two Laws - IXIASOFT User Conference 2016
Troubleshooting: The Two Laws - IXIASOFT User Conference 2016
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Bp106 Worst Practices Final
Bp106   Worst Practices FinalBp106   Worst Practices Final
Bp106 Worst Practices Final
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

2019 PHP Serbia - Boosting your performance with Blackfire

  • 1.
  • 2. Marko Mitranić Aleksandar Ilić Milomir Dragović
  • 3.
  • 4. 1.
  • 5.
  • 8. 1. Edit the /Docker/.env file by inserting your own BlackFire credentials and changing the ports if needed. 2. Enter the project’s Docker folder and execute ./deploy.sh. 3. Visit http://localhost:80/. That’s it.
  • 9.
  • 10.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Improving performance is all about optimizing resource usage
  • 22.
  • 23.
  • 24.
  • 25. Don’t optimize before knowing what is slowing down your application “For premature optimization is the root of all evil.”
  • 27. 1. Profile key pages 2. Start from the slowest ones 3. Compare and analyze profiles to spot differences and bottlenecks 4. Always look for the biggest (solvable) bottleneck 5. Not all bottlenecks should be solved, sometimes they are the price of business
  • 28. The creature in the picture is a “Dwarf in the flask” from Fullmetal Alchemist anime. It was a successful experiment which broke its own flask and eventually nearly managed to kill everyone. The author did not plan on such success, so they did not take a great amount of precautions. Sometimes, you just grew out of your flask. Your failed performance can be compensated for via creating a good flexible app && server architecture.
  • 29. The solution is not always the code, it lies more often in the architecture of the app. Keep it as simple as possible, but prepare for the future. Splitting responsibilities, granulating your application into smaller ones, DB sharding or caching, CDN, continuous integration. But this is a topic for a whole set of other workshops...
  • 30.
  • 31. When faced with a really heavy query, there is usually not much you can do. Sometimes you can do better indexing, optimize joins, even do some caching. 40k Client entities in total Sort and extract top 10. Based on a complex set of requirements. Symfony 3.4 | MongoDB 3.3 | Doctrine ODM Query Took ~6.2 seconds to complete. On each non-cached load of this page.
  • 32. The business logic is what it is, you can’t make it simpler because it suits you. What you would usually do is start optimizing the query. Indexing, making joins when possible etc. But in this case all of that was already done by the previous team… So, it seems that no code could be improved.
  • 33. Not true. Once you have a bird’s-eye view of the code execution you start to notice the real problems. 1. By some weird and not-easy-observable edge case, the query is run twice. 2. The real bottleneck is not DB, it is ODM. Based on this, first we saved 3.1s by handling the edge case. Then we created a new reader which simply uses direct DB queries for this particular query. In the end, we use Symfony Cache mechanism to only run this once per day.
  • 34.
  • 35. Sometimes, you simply don’t have the real need for using Doctrine document Hydration. Yes, i said it. Instead you can instead use Array or Scalar fetch methods.
  • 36.
  • 37. What is little known to developers who have never worked dealt withSQL directly is the ability to prepare changes and trigger a DB transaction at a specific time. In doctrine it’s called a flush(). All the changes that you make on entities are only saved to the database once you call the flush method. This is a double edged sword...
  • 38.
  • 39. Never flush within a loop. Unless..
  • 40. Large transactions can also be slooow. You need to find a sweetspot if dealing with large datasets. With MongoDB we usually use ~400 entities per transaction, except in cases where there are a lot of changes.
  • 41. Sometimes you don’t even have to loop. Try using multi updates when updating the whole set of documents in the same way.
  • 42.
  • 43. ● Always evaluate query speed when not sure. ● Use Cursors whenever possible. ● Watch out for N+1 Problems ● DB Calls within a loop - use prepared statements. ● ***Learn to properly use Indexes and Cardinality*** ● Enable slow query log and make sure none of your queries do a full table scan.
  • 44. If all else is done but you still have a problem with the volume of work (user visits, queries) it might be time to start researching scaling techniques. (remember our Dwarf in the flask?) Usually in these applications the same bottlenecks remain present. Research database sharding, replication and DB caching layer.
  • 46.
  • 47. Long running scripts often deal with some sort of watcher jobs or migrations. For example, here we got this 160.000 users, take each one and match them to their respective data from another system via a backchannel call. Take a user from DB, Call API and match, Save changes. Repeat x140k.
  • 48. ● In these cases optimizing cache is useless, and workload is often huge. ● PHP has a composer vendor libraries problem with RAM leaks. ● Script works for hours, racks up maximum ram and then stalls slower and slower when GC kicks in.
  • 49.
  • 50. Always practice to use Dependency Injection instead of (ab)using Container directly. Apart from being a prettier and more maintainable code style, this allows Symfony to not-recompile parts of the container during the request.
  • 51.
  • 52. One of our sites used IPS Community Forums and was running PHP 7.0 The vendor fully supports PHP up to 5.4 and 7.4. One of the plugins installed, the author used mb_strripos which only works good on 7.3 ...
  • 53.
  • 54. Sometimes a cache can be slow. By default, most built-in caching mechanisms use Filesystem storage. If you hit this bump, try with Redis, Varnish, or memcache. Combine technologies when you see an opportunity.
  • 55. ● When instantiating objects within a big loop, use a factory which clones a prototype of the object instead of new MyObject(); (66% faster). ● If you are working with objects of large cardinality, use named classes instead of arrays. Use stdclass never. ● Avoid these slow built-in PHP functions. https://github.com/dseguy/clearPHP/blob/master/rules/avoid-those-slow-functions.md ● Use associative arrays basically never. https://steemit.com/php/@crell/php-use-associative-arrays-basically-never
  • 56. Don’t optimize before knowing what is slowing down your application “For premature optimization is the root of all evil.”
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.