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.
DISCOVERING & SOLVING
I will give you…
a quick tour of some tools I use
an opinionated guide of practices
an overview of typical problems/solutions
BEFORE YOU START…
FIGURE OUT YOUR PROBLEM
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 diﬀerent load
Verify application behavior under normal and peak load conditions.
Determine or validate an application’s behavior when pushed
beyond normal or peak load conditions.
Determine how many users and/or transactions a given system
will support and still meet performance goals.
access & error logs
size, throughput, connections, slow queries
hits, misses, size
CPU & memory usage, disk I/O, network
WHAT TO DO?
slowly increase sample size
monitor changes & spot anomalies
make one change at a time
based on a verifiable assumption
Search for causes not symptoms
Do not make changes without cause
Change as few things as possible
Know when to stop
You have rock solid & kickass monitoring
for your production system!
Tests & monitoring can be reused & adapted
for other scenarios
Performance Testing Guidance
for Web Applications
WHAT ABOUT THE CLIENT?
MEANWHILE ON THE SERVER…
SYMFONY WEB PROFILER
PROFILING AS A SERVICE
$config = new \Blackfire\ClientConfiguration(
$client = new \Blackfire\Client($config);
$probe = $client->createProbe();
// code to be profiled
TYPICAL PROBLEM GROUPS
HOW TO DEVELOP FOR
WHAT DOES THAT MEAN?
ABSTRACTIONS & MAGIC
You are solving concrete business problems
Saving a few µs in cpu cycles never matters
Only real data from your performance counts
PHP INSPECTIONS (EA EXTENDED)
BYTE CODE CACHE
opcache.max_accelerated_files = 20000
Use composer classmap
composer dump-autoload --optimize \
composer install -noa
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.
CACHEABLE HTTP RESPONSES
Helper methods in Response-object
‘public, s-maxage=600, must-revalidate’
DON’T BE FOOLED
REDIS IS NOT EASY TO SETUP
USE WITH CPU-HEAVY TASKS
NOT MEMORY-HEAVY TASKS
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 eﬀective 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.
BACK IT UP WITH DATA!