Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Discovering & solving performance issues in PHP-apps

Denis Brumann
September 30, 2017

Discovering & solving performance issues in PHP-apps

I want to lay out how to effectively anticipate, identify and mitigate performance issues in a common PHP application. I want to discuss how to approach performance optimizations including micro-optimizations, some tools available to a developer for investigating and monitoring performance issues as well as some ways to improve performance, including a quick introduction to both application and HTTP-caching.

Denis Brumann

September 30, 2017
Tweet

More Decks by Denis Brumann

Other Decks in Programming

Transcript

  1. I will give you… a quick tour of some tools

    I use an opinionated guide of practices an overview of typical problems/solutions
  2. It can be used to simulate a heavy load on

    a server, group of servers, network or object to test its strength or to analyze overall performance under different load types. https://jmeter.apache.org/
  3. LOAD TEST
 Verify application behavior under normal and peak load

    conditions. STRESS TEST 
 Determine or validate an application’s behavior when pushed
 beyond normal or peak load conditions. CAPACITY TEST
 Determine how many users and/or transactions a given system
 will support and still meet performance goals.
  4. WEB SERVER 
 access & error logs DATABASE 
 size,

    throughput, connections, slow queries CACHE
 hits, misses, size SYSTEM
 CPU & memory usage, disk I/O, network
  5. WHAT TO DO? slowly increase sample size monitor changes &

    spot anomalies make one change at a time
 based on a verifiable assumption repeat
  6. Search for causes not symptoms Do not make changes without

    cause Change as few things as possible Know when to stop
  7. You have rock solid & kickass monitoring
 for your production

    system! Tests & monitoring can be reused & adapted
 for other scenarios
  8. $config = new \Blackfire\ClientConfiguration(
 $clientId, $clientToken
 ); $client = new

    \Blackfire\Client($config); $probe = $client->createProbe(); // code to be profiled $client->endProbe($probe); BLACKFIRE SDK
  9. AVOID ABSTRACTIONS & MAGIC
 You are solving concrete business problems

    MICRO-OPTIMIZATIONS
 Saving a few µs in cpu cycles never matters GUESSING
 Only real data from your performance counts
  10. Varnish Cache is a web application accelerator also known as

    a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture. https://varnish-cache.org/intro/index.html#the-basics
  11. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/ improving-performance.html METADATA & QUERY CACHES
 it is strongly discouraged

    to use Doctrine without a Metadata and Query cache (preferably with APC or Memcache as the cache driver). ALTERNATIVE RESULT FORMATS
 Make effective use of the available alternative query result formats like nested array graphs or pure scalar results, especially in scenarios where data is loaded for read-only purposes.