SlideShare a Scribd company logo
http://lynt.cz
WordPress + performance
Vladimir Smitka
vladimir.smitka@lynt.cz
@smitka
Lynt services s.r.o.
9. 10. 2015 1
http://lynt.cz
Hidden advertisement
• We launched a new blog about
automatization in PPC few days ago
http://ppc-scripts.eu
9. 10. 2015 2
http://lynt.cz
How to speedup WP?
9. 10. 2015 3
Let someone else do it!
http://lynt.cz
Thank you for your
attention!
9. 10. 2015 4
http://lynt.cz
Speech no. 2 – DIY
• What mentioned services do?
– Caching of generated page on their servers
– Resources optimization – combine&minify JS & CSS, image
optimization
9. 10. 2015 5
http://lynt.cz/blog/wordpress-
in-the-czech-complex-research
http://lynt.cz
Image optimization
• Appropriate dimensions
• Check if thumbnails are really small
• Use appropriate formats
• „Web graphics“ – 8 bit PNG, SVG
• Photos – JPG (quality 75 is OK, 60 in
Photoshop)
• Videos – MP4, FLV, GIF!
9. 10. 2015 6
http://lynt.cz
Image optimization – 24 bit PNG
• Usually used because of alpha channel
• They are often used unnecessarily – alpha
channel is also supported by 8 bit PNG (produced
images are much smaller), Photoshop couldn‘t
produce it recently (new Photoshop CC can)
• https://tinypng.com/
• TruePNG - http://css-ig.net/articles/truepng
• AdvDef -http://advancemame.sourceforge.net/comp-
download.html
9. 10. 2015 7
http://lynt.cz
Image optimization - plugins
• https://wordpress.org/plugins/ewww-image-
optimizer/ + https://ewww.io
• https://wordpress.org/plugins/shortpixel-
image-optimiser/ - 100 images/month for
free
• https://wordpress.org/plugins/kraken-image-
optimizer/ - subscription
9. 10. 2015 8
http://lynt.cz
CSS sprites & data URI
• What is the problem?
• HTTP headers are 0.5 - 1KB length in average (in case of
small images headers are bigger than useful data)
• Connection time to the server is negligible
• Our goal is to reduce number of requests to the server:
A) If you have more images you can merge them to one bigger
image (http://draeton.github.io/stitches/)
B) You can load particular small images with data URI:
<img src="data:image/png;base64,…data v
base64…">
9. 10. 2015 9
http://lynt.cz
JS & CSS optimization
• Goal – reduction of requests to server,
reduction of size (again)
• You can combine more CSS and JS files into
one + minify them
• https://wordpress.org/plugins/autoptimize/
• https://wordpress.org/plugins/bwp-minify/
9. 10. 2015 10
http://lynt.cz
Autoptimize
9. 10. 2015 11
http://lynt.cz
Page cache
• Saves processed page into static HTML file for
future load
• https://wordpress.org/plugins/wp-super-
cache/
• https://wordpress.org/plugins/w3-total-
cache/
9. 10. 2015 12
http://lynt.cz
WP Super Cache
9. 10. 2015 13
http://lynt.cz9. 10. 2015 14
Thank you for your attention!
http://lynt.cz
Speech no. 3 – the real one
9. 10. 2015 15
Problem diagnostics:
https://gtmetrix.com/
Application Resources
http://lynt.cz9. 10. 2015 16
http://lynt.cz
Resources loading under hood
• http://www.webpagetest.org/
9. 10. 2015 17
http://lynt.cz
Resources loading – common problems
• Expires headers (mod_expires) – ensure that
resources don‘t need to be downloaded again
(else browser will use heuristic analysis)
• GZIP compression (mod_deflate) – usually saves
about 30-70% size of text files
• Keep Alive – keeps connections open, there is no
need to establish connection again, it uses little
more RAM
9. 10. 2015 18
http://lynt.cz
Keep Alive
9. 10. 2015 19
30ms
Keep Alive turning off may be
critical on sites with many
resources - especially on mobile
devices with long latency
Ping 300ms, 150 resources, 5 simultaneous connections:
2x300x150/5 = 18s waiting for connection + ending
Why so many
redirects?
http://lynt.cz
HTTPS & SPDY & HTTP/2
9. 10. 2015 20
HTTP/2
• encrypt,
• compress,
• keep alive,
• binary protocol
Neither combining CSS and JS,
nor using sprites is necessary.
Using these techniques may
little slow down your site with
HTTP/2.
Reconnecting isn‘t a problem –
only required resources are
downloaded.
http://lynt.cz
What slows TTFB down
• MySQL queries
• Unusage of cache
• HTTP requests (e.g. update checks)
• More plugins = more requests
9. 10. 2015 21
http://lynt.cz
Effect of plugins
• Test on VPS from WEDOS (1 core, 4G RAM)
ab -n 1000 -c 4 http://domain
• Clean WP:
Requests per second: 15.93 [#/sec]
Time per request: 251.095 [ms]
• WP + SliderRevolution + CF7 + Yoast SEO
Requests per second: 4.61 [#/sec]
Time per request: 868.450 [ms]
• WP + SliderRevolution + CF7 + Yoast SEO + WPML + Jetpack
Requests per second: 2.94 [#/sec]
Time per request: 1360.454 [ms]
9. 10. 2015 22
Congrats, we were
able to degrade
performance more
than 5 times in few
minutes!
http://lynt.cz
Motivation: our webserver
• WP + some common plugins
Requests per second: 319.26 [#/sec]
Time per request: 12.529 [ms]
Ping 2,5 ms
9. 10. 2015 23
35 ms
Dirty caching tricks are used, of course. We will talk about it later.
http://lynt.cz
P3 Profiler
• https://wordpress.org/plugins/p3-profiler/
• The simplest, provides less information, bad accuracy
• It can help detect a problematic plugin
9. 10. 2015 24
http://lynt.cz
Query monitor
• https://wordpress.org/plugins/query-
monitor/
• Detailed overview what happens
in WP
• Great helper during development
(e.g. shows active conditions)
9. 10. 2015 25
http://lynt.cz
Query Monitor – DB queries
9. 10. 2015 26
List of all
queries
Queries by
function
Queries by
component
http://lynt.cz
Query Monitor – more info
9. 10. 2015 27
HTTP requests based on wp_remote_X function
curl, file_get_contents etc. are not captured [you can capture them by traffic analysis (tcpdump, wireshark)]
Some important constants are missing
e.g. SAVEQUERIES – another IO req.
Writes into file:
IO operations
Minified libraries
won‘t be used:
more data
HTTP requests
http://lynt.cz
Looking from the other side
• We have examined website from application
look
• Now it is time to look where apps are running
9. 10. 2015 28
http://lynt.cz
Server infrastructure
9. 10. 2015 29
3 parts – HTTP server, DB server a Storage
Each with different requirements…
DB
Storage
WEBLOADBALANCER
Cloud
× 2
http://lynt.cz
Monitoring – looking for bottle neck
9. 10. 2015 30
htop
Munin
http://munin-monitoring.org/
http://www.zabbix.com/
http://www.librenms.org/
htop
iotop
iftop
nmon
http://lynt.cz
PHP versions
• OpCode cache
• Object cache
9. 10. 2015 31
Newer PHP versions
are faster and can
use OpCache more
effectively (it costs
more RAM)
PHP version performance – Apache Benchmark/WP
http://lynt.cz
OpCode cache
• PHP language is compiled to Bytecode during
every request
• OpCache saves result for future use, there is no
need of recompilation
• You need install it (PHP < 5.5)
• APC
• Xcache
• Zend OpCache (part of PHP 5.5)
9. 10. 2015 32
http://lynt.cz
Object Cache
• Usually part of OpCache module + standalone
• User can save data into it for future use
• You need to enable it and allocate storage
• You need to install object backend drop-in into WP
– APC
– Xcache
– APCu (for usage with Zend OpCache)
– Redis
– Memcached
• WP will use it for transient variables etc. – it can reduce
DB queries rapidly
9. 10. 2015 33
71 of them is Slider Revolution
http://lynt.cz
Some points from Query Monitor
• You'll probably find that menu and some widgets
don‘t use cache
• http://afterburner.voceplatforms.com/back-
end.html#voce-widget-cache
• http://afterburner.voceplatforms.com/back-
end.html#voce-cached-nav
• There are many more tips and tools on this website
9. 10. 2015 34
http://lynt.cz
HTTP server
• Many options to run PHP
• Apache (prefork) + mod_php
• Apache (mpm event/worker) + PHP-FPM, FastCGI
• Nginx + PHP-FPM
9. 10. 2015 35
Apache
Apache -
.htaccess
Nginx
req/s 8.2 9.35 9.96
0
2
4
6
8
10
12
req/s
Apache vs Nginx
Apache
Apache -
.htaccess
Nginx
Nginx +
Microcache
req/s 8.2 9.35 9.96 279.97
0
50
100
150
200
250
300
req/s
Apache vs Nginx + Microcache
(unfair comparism)
AllowOverride None
http://lynt.cz
/wp-content/uploads/revslider/classicslider/bike.jpg
9. 10. 2015 36
Hey, is
.htaccess
here?
And
here?Here?
Or
here?
Here it is!
Apache is not convenient to server static files
http://lynt.cz
Back to our webserver
• We used microcache to achieve excellent results –
Nginx will remember result of request for a while
(seconds, minutes)
• This technic is useful in case of peak traffic – e.g after
new content release
• Microcache: Requests per second: 319.26 [#/sec]
• WP Supercache: Requests per second: 270.84 [#/sec]
• No caching *: Requests per second: 13.52 [#/sec]
* Test was performed with hundreds other requests on production environment
9. 10. 2015 37
http://lynt.cz
The last benchmark
• Test to the WEDOS VPS with more concurrency
ab -n 1000 -c 40 http://domain
• Requests per second: 1191.49 [#/sec] (mean)
• Time per request: 33.572 [ms] (mean)
• Time per request: 0.839 [ms] (mean, across all
concurrent requests)
Important note:
„Using cache isn‘t so easy, you need to resolver cache invalidation!“
9. 10. 2015 38
Very good
result with
cheap VPS
http://lynt.cz
The real tools
9. 10. 2015 39
http://lynt.cz
Blackfire.io
• Performance profiling, great visualization
• Requires to install agent and PHP extension - tutorial
• You can run profiling from Chrome with Blackfire
Companion
• Hack version for free
• Premium version 82,5€/month
(DB queries and HTTP requests
analysis, teams,
longer data retention)
9. 10. 2015 40
http://lynt.cz9. 10. 2015 41
Performance
consumed by
function itself
http://lynt.cz
Localization takes more than 30%?
• WP uses slow PHP implemetation of GetText
• Solution:
• https://github.com/LyntServices/WP-lang-
cache (my very old hack to WP core, I have
more modifications to use ObjectCache)
• https://wordpress.org/plugins/mo-cache/
9. 10. 2015 42
http://lynt.cz9. 10. 2015 43
The big grey bar
http://lynt.cz
Why is do_action so slow?
9. 10. 2015 44
From PHP5.6 you can use optimized Argument Unpacking functionality:
…$the_['acceped_args']
Call_user_func_array function itself isn‘t problem – problem is hundreds and
thousands calls of this function (or any other function).
http://lynt.cz
Big problem - demo
9. 10. 2015 45
Recursion – shortcodes
in shortcodes in
shorcodes …
Huh, so
many calls!
Big grey bar – use of object
cache makes it worse – it
will call many userializations
http://lynt.cz
Another problem – with fix!
9. 10. 2015 46
OMG!
http://lynt.cz
Another problem – with fix!
9. 10. 2015 47
Fix:
extension=json.so
Native JSON extension was missing!
9.2s => 0.0248s = 370x better performance with one line 
http://lynt.cz
Dead end of profiling
• When you profile WP in Blackfire you usually
stop in two cases:
1) do_action – common and heavy used WP
function (like apply_filters), you cannot track
cause and effect of particular call in Blackfire
2) Grey bar – performance is lost inside function –
code isn‘t visible
• Now debugging is come
9. 10. 2015 48
http://lynt.cz
Xdebug
• PHP extension: http://xdebug.org/
• Wizard helps you to download the correct
versions and what to insert into PHP config
according your phpinfo() output:
http://xdebug.org/wizard.php
• Great config setting explanation:
https://gist.github.com/IngmarBoddington/53
11858
9. 10. 2015 49
xdebug.remote_enable = 1
xdebug.profiler_enable_trigger = 1
xdebug.trace_format = 1
xdebug.trace_enable_trigger = 1
http://lynt.cz
Xdebug – what to do?
• Allows to go through code step by step from IDE
• Trace-log generation
• Code coverage analysis
• Profiling (more overhead than Blackfire)
xdebug.profiler_enable_trigger = 1
?XDEBUG_PROFILE
• You can use WebGrind for visualization:
https://github.com/jokkedk/webgrind
• Xdebug Helper – Chrome extension:
https://chrome.google.com/webstore/detail/xdebug-
helper/eadndfjplgieldjbigjakmdgkmoaaaoc
9. 10. 2015 50
http://lynt.cz
WebGrind
9. 10. 2015 51
http://lynt.cz
Trace
• Tracelog – huge amount of data
• Useful for resolving memory problems
• https://github.com/corretge/xdebug-trace-gui
9. 10. 2015 52
line
spent time
Difference of
consumed memory
Memory consuption during script execution
http://lynt.cz
Tracing part of code
9. 10. 2015 53
xdebug_start_trace('for.xt');
for ($i=0;$i<3;$i++){
echo rand(0,$i);
}
xdebug_stop_trace();
TRACE START [2015-10-01 11:49:49]
2 2 1 0.005554 223088
2 3 0 0.005621 223128 rand 0 D:htdocswp4info.php 7
2 3 1 0.005740 223128
2 4 0 0.005770 223128 rand 0 D:htdocswp4info.php 7
2 4 1 0.005879 223128
2 5 0 0.005908 223128 rand 0 D:htdocswp4info.php 7
2 5 1 0.006016 223128
2 6 0 0.006044 223096 xdebug_stop_trace 0 D:htdocswp4info.php 9
0.006130 223120
TRACE END [2015-10-01 11:49:49]
http://lynt.cz
Stepping through code
9. 10. 2015 54
Default: localhost:9000
http://lynt.cz
Père Fouras: Pensée du jour
9. 10. 2015 55
„This is the end of web developers era,
era of system adminstrators has begun.“
http://lynt.cz
Summary – performance analysis
• How it shows from outside?
– https://gtmetrix.com/
– http://www.webpagetest.org/
– Developer console in browser
• What slows WP down?
– P3 profiler – tentative detection of slow plugins
– Query monitor – particular DB queries and more
• Profiling and debugging
– Blackfire.io
– Xdebug (visialization with webgrind)
9. 10. 2015 56
http://lynt.cz
This is the end, folks.
9. 10. 2015 57
Small gift: Blackfire.io Premium for a month:
DODWEDOS102015
valid until 19.10.2015
You can use this coupon during monthly subscription checkout
You can follow me on twitter @smitka and visit our blog http://lynt.cz/blog

More Related Content

PPTX
WordPress Security: Defend yourself against digital invaders
PPTX
WordPress security for everyone
PPTX
Anthony Somerset - Site Speed = Success!
PDF
Less and faster – Cache tips for WordPress developers
PDF
Use Xdebug to profile PHP
PPT
Roy foubister (hosting high traffic sites on a tight budget)
PDF
Search in WordPress - how it works and howto customize it
PDF
Seravo.com: WordPress Security 101
WordPress Security: Defend yourself against digital invaders
WordPress security for everyone
Anthony Somerset - Site Speed = Success!
Less and faster – Cache tips for WordPress developers
Use Xdebug to profile PHP
Roy foubister (hosting high traffic sites on a tight budget)
Search in WordPress - how it works and howto customize it
Seravo.com: WordPress Security 101

What's hot (20)

PPTX
Nahlédněte za oponu VersionPressu
PDF
Make WordPress Fly With Virtual Server Hosting - WordCamp Sydney 2014
PDF
How to investigate and recover from a security breach in WordPress
PDF
10 things every developer should know about their database to run word press ...
PDF
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
PDF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
PPTX
Managing Multisite: Lessons from a Large Network
PDF
HTTPS + Let's Encrypt
PDF
When you don't have 0days: client-side exploitation for the masses
PPTX
MySQL Tips for WordPress
PDF
Buried by time, dust and BeEF
PDF
ZeroNights2012_BeEF_Workshop_antisnatchor
PDF
WordPress Server Security
PDF
Improve WordPress performance with caching and deferred execution of code
PDF
Securing your web infrastructure
PDF
Be ef presentation-securitybyte2011-michele_orru
PDF
WordPress Development Tools and Best Practices
PDF
Advances in BeEF - AthCon2012
PDF
High Performance WordPress
PDF
Mobile Hybrid Development with WordPress
Nahlédněte za oponu VersionPressu
Make WordPress Fly With Virtual Server Hosting - WordCamp Sydney 2014
How to investigate and recover from a security breach in WordPress
10 things every developer should know about their database to run word press ...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Managing Multisite: Lessons from a Large Network
HTTPS + Let's Encrypt
When you don't have 0days: client-side exploitation for the masses
MySQL Tips for WordPress
Buried by time, dust and BeEF
ZeroNights2012_BeEF_Workshop_antisnatchor
WordPress Server Security
Improve WordPress performance with caching and deferred execution of code
Securing your web infrastructure
Be ef presentation-securitybyte2011-michele_orru
WordPress Development Tools and Best Practices
Advances in BeEF - AthCon2012
High Performance WordPress
Mobile Hybrid Development with WordPress
Ad

Viewers also liked (8)

PPTX
Wordfence 2016
PPTX
WordCamp Praha 2016 - Bezpečnost WordPress
PPT
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
PPTX
Výkon WordPress
PPTX
PHP Performance with APC + Memcached
PPTX
Maximizing PHP Performance with NGINX
PPTX
Nejčastejší problémy WordPress webů
PDF
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Wordfence 2016
WordCamp Praha 2016 - Bezpečnost WordPress
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Výkon WordPress
PHP Performance with APC + Memcached
Maximizing PHP Performance with NGINX
Nejčastejší problémy WordPress webů
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Ad

Similar to WordPress performance tuning (20)

PDF
Php go vrooom!
PDF
23 Ways To Speed Up WordPress
PDF
Optimizing the performance of WordPress
PDF
Fast Websites: The What, Why, and How
PDF
Improving WordPress performance (xdebug and profiling)
PDF
Optimizing WordPress for Performance - WordCamp Houston
PDF
Improving WordPress Performance with Xdebug and PHP Profiling
PPTX
Northeast PHP - High Performance PHP
PPT
Web Speed And Scalability
PDF
WordPress at Peak Performance (Radio Edit)
PDF
WordPress Optimization Tips for Performance & Speed
ODP
Clug 2011 March web server optimisation
PDF
BD Conf: Visit speed - Page speed is only the beginning
PDF
2013 - Dustin whittle - Escalando PHP en la vida real
PDF
WebsitePerformance
PDF
Wordpress optimization
PPTX
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
PDF
Optimizing Your Frontend Performance
ZIP
High Performance WordPress - WordCamp Jerusalem 2010
PPTX
Joomla! Performance on Steroids
Php go vrooom!
23 Ways To Speed Up WordPress
Optimizing the performance of WordPress
Fast Websites: The What, Why, and How
Improving WordPress performance (xdebug and profiling)
Optimizing WordPress for Performance - WordCamp Houston
Improving WordPress Performance with Xdebug and PHP Profiling
Northeast PHP - High Performance PHP
Web Speed And Scalability
WordPress at Peak Performance (Radio Edit)
WordPress Optimization Tips for Performance & Speed
Clug 2011 March web server optimisation
BD Conf: Visit speed - Page speed is only the beginning
2013 - Dustin whittle - Escalando PHP en la vida real
WebsitePerformance
Wordpress optimization
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Optimizing Your Frontend Performance
High Performance WordPress - WordCamp Jerusalem 2010
Joomla! Performance on Steroids

More from Vladimír Smitka (20)

PPTX
Google Tag Manager a analytika ve WordPress
PPTX
WordCamp Bratislava 2019 - Cache!
PPTX
Webmeetup #3
PPTX
Co ukázal globální scan přístupných .git repozitářů?
PPTX
Hesla a vícefaktorová autentizace ve WP
PPTX
WP Weekend 2018
PPTX
Drobné chyby, které vám mohou zlomit vaz
PPTX
Sysops tipy pro lepší WP
PPTX
Najčastejšie problémy WordPress webov
PPTX
Http/2 vs Image Sprites
PPTX
PPTX
WordCamp Brno 2017 - rychlý a bezpečný web
PPTX
WordPress - základy bezpečnosti
PPTX
WordPress: Základy - bezpečnost 3x3
PPTX
Instalace WordPress
PPTX
WP výkon a jeho profilování
PPTX
Bezpečnost WordPress pro začátečníky
PPTX
Bezpečnost WP, tipy pro každého - wordCamp Praha 2015
PDF
České weby a Wordpress (Q4/2014)
PPTX
Wordcamp Praha 2015 - další útržky z prezentace
Google Tag Manager a analytika ve WordPress
WordCamp Bratislava 2019 - Cache!
Webmeetup #3
Co ukázal globální scan přístupných .git repozitářů?
Hesla a vícefaktorová autentizace ve WP
WP Weekend 2018
Drobné chyby, které vám mohou zlomit vaz
Sysops tipy pro lepší WP
Najčastejšie problémy WordPress webov
Http/2 vs Image Sprites
WordCamp Brno 2017 - rychlý a bezpečný web
WordPress - základy bezpečnosti
WordPress: Základy - bezpečnost 3x3
Instalace WordPress
WP výkon a jeho profilování
Bezpečnost WordPress pro začátečníky
Bezpečnost WP, tipy pro každého - wordCamp Praha 2015
České weby a Wordpress (Q4/2014)
Wordcamp Praha 2015 - další útržky z prezentace

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Modernizing your data center with Dell and AMD
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Monthly Chronicles - July 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...

WordPress performance tuning

  • 1. http://lynt.cz WordPress + performance Vladimir Smitka vladimir.smitka@lynt.cz @smitka Lynt services s.r.o. 9. 10. 2015 1
  • 2. http://lynt.cz Hidden advertisement • We launched a new blog about automatization in PPC few days ago http://ppc-scripts.eu 9. 10. 2015 2
  • 3. http://lynt.cz How to speedup WP? 9. 10. 2015 3 Let someone else do it!
  • 4. http://lynt.cz Thank you for your attention! 9. 10. 2015 4
  • 5. http://lynt.cz Speech no. 2 – DIY • What mentioned services do? – Caching of generated page on their servers – Resources optimization – combine&minify JS & CSS, image optimization 9. 10. 2015 5 http://lynt.cz/blog/wordpress- in-the-czech-complex-research
  • 6. http://lynt.cz Image optimization • Appropriate dimensions • Check if thumbnails are really small • Use appropriate formats • „Web graphics“ – 8 bit PNG, SVG • Photos – JPG (quality 75 is OK, 60 in Photoshop) • Videos – MP4, FLV, GIF! 9. 10. 2015 6
  • 7. http://lynt.cz Image optimization – 24 bit PNG • Usually used because of alpha channel • They are often used unnecessarily – alpha channel is also supported by 8 bit PNG (produced images are much smaller), Photoshop couldn‘t produce it recently (new Photoshop CC can) • https://tinypng.com/ • TruePNG - http://css-ig.net/articles/truepng • AdvDef -http://advancemame.sourceforge.net/comp- download.html 9. 10. 2015 7
  • 8. http://lynt.cz Image optimization - plugins • https://wordpress.org/plugins/ewww-image- optimizer/ + https://ewww.io • https://wordpress.org/plugins/shortpixel- image-optimiser/ - 100 images/month for free • https://wordpress.org/plugins/kraken-image- optimizer/ - subscription 9. 10. 2015 8
  • 9. http://lynt.cz CSS sprites & data URI • What is the problem? • HTTP headers are 0.5 - 1KB length in average (in case of small images headers are bigger than useful data) • Connection time to the server is negligible • Our goal is to reduce number of requests to the server: A) If you have more images you can merge them to one bigger image (http://draeton.github.io/stitches/) B) You can load particular small images with data URI: <img src="data:image/png;base64,…data v base64…"> 9. 10. 2015 9
  • 10. http://lynt.cz JS & CSS optimization • Goal – reduction of requests to server, reduction of size (again) • You can combine more CSS and JS files into one + minify them • https://wordpress.org/plugins/autoptimize/ • https://wordpress.org/plugins/bwp-minify/ 9. 10. 2015 10
  • 12. http://lynt.cz Page cache • Saves processed page into static HTML file for future load • https://wordpress.org/plugins/wp-super- cache/ • https://wordpress.org/plugins/w3-total- cache/ 9. 10. 2015 12
  • 14. http://lynt.cz9. 10. 2015 14 Thank you for your attention!
  • 15. http://lynt.cz Speech no. 3 – the real one 9. 10. 2015 15 Problem diagnostics: https://gtmetrix.com/ Application Resources
  • 17. http://lynt.cz Resources loading under hood • http://www.webpagetest.org/ 9. 10. 2015 17
  • 18. http://lynt.cz Resources loading – common problems • Expires headers (mod_expires) – ensure that resources don‘t need to be downloaded again (else browser will use heuristic analysis) • GZIP compression (mod_deflate) – usually saves about 30-70% size of text files • Keep Alive – keeps connections open, there is no need to establish connection again, it uses little more RAM 9. 10. 2015 18
  • 19. http://lynt.cz Keep Alive 9. 10. 2015 19 30ms Keep Alive turning off may be critical on sites with many resources - especially on mobile devices with long latency Ping 300ms, 150 resources, 5 simultaneous connections: 2x300x150/5 = 18s waiting for connection + ending Why so many redirects?
  • 20. http://lynt.cz HTTPS & SPDY & HTTP/2 9. 10. 2015 20 HTTP/2 • encrypt, • compress, • keep alive, • binary protocol Neither combining CSS and JS, nor using sprites is necessary. Using these techniques may little slow down your site with HTTP/2. Reconnecting isn‘t a problem – only required resources are downloaded.
  • 21. http://lynt.cz What slows TTFB down • MySQL queries • Unusage of cache • HTTP requests (e.g. update checks) • More plugins = more requests 9. 10. 2015 21
  • 22. http://lynt.cz Effect of plugins • Test on VPS from WEDOS (1 core, 4G RAM) ab -n 1000 -c 4 http://domain • Clean WP: Requests per second: 15.93 [#/sec] Time per request: 251.095 [ms] • WP + SliderRevolution + CF7 + Yoast SEO Requests per second: 4.61 [#/sec] Time per request: 868.450 [ms] • WP + SliderRevolution + CF7 + Yoast SEO + WPML + Jetpack Requests per second: 2.94 [#/sec] Time per request: 1360.454 [ms] 9. 10. 2015 22 Congrats, we were able to degrade performance more than 5 times in few minutes!
  • 23. http://lynt.cz Motivation: our webserver • WP + some common plugins Requests per second: 319.26 [#/sec] Time per request: 12.529 [ms] Ping 2,5 ms 9. 10. 2015 23 35 ms Dirty caching tricks are used, of course. We will talk about it later.
  • 24. http://lynt.cz P3 Profiler • https://wordpress.org/plugins/p3-profiler/ • The simplest, provides less information, bad accuracy • It can help detect a problematic plugin 9. 10. 2015 24
  • 25. http://lynt.cz Query monitor • https://wordpress.org/plugins/query- monitor/ • Detailed overview what happens in WP • Great helper during development (e.g. shows active conditions) 9. 10. 2015 25
  • 26. http://lynt.cz Query Monitor – DB queries 9. 10. 2015 26 List of all queries Queries by function Queries by component
  • 27. http://lynt.cz Query Monitor – more info 9. 10. 2015 27 HTTP requests based on wp_remote_X function curl, file_get_contents etc. are not captured [you can capture them by traffic analysis (tcpdump, wireshark)] Some important constants are missing e.g. SAVEQUERIES – another IO req. Writes into file: IO operations Minified libraries won‘t be used: more data HTTP requests
  • 28. http://lynt.cz Looking from the other side • We have examined website from application look • Now it is time to look where apps are running 9. 10. 2015 28
  • 29. http://lynt.cz Server infrastructure 9. 10. 2015 29 3 parts – HTTP server, DB server a Storage Each with different requirements… DB Storage WEBLOADBALANCER Cloud × 2
  • 30. http://lynt.cz Monitoring – looking for bottle neck 9. 10. 2015 30 htop Munin http://munin-monitoring.org/ http://www.zabbix.com/ http://www.librenms.org/ htop iotop iftop nmon
  • 31. http://lynt.cz PHP versions • OpCode cache • Object cache 9. 10. 2015 31 Newer PHP versions are faster and can use OpCache more effectively (it costs more RAM) PHP version performance – Apache Benchmark/WP
  • 32. http://lynt.cz OpCode cache • PHP language is compiled to Bytecode during every request • OpCache saves result for future use, there is no need of recompilation • You need install it (PHP < 5.5) • APC • Xcache • Zend OpCache (part of PHP 5.5) 9. 10. 2015 32
  • 33. http://lynt.cz Object Cache • Usually part of OpCache module + standalone • User can save data into it for future use • You need to enable it and allocate storage • You need to install object backend drop-in into WP – APC – Xcache – APCu (for usage with Zend OpCache) – Redis – Memcached • WP will use it for transient variables etc. – it can reduce DB queries rapidly 9. 10. 2015 33 71 of them is Slider Revolution
  • 34. http://lynt.cz Some points from Query Monitor • You'll probably find that menu and some widgets don‘t use cache • http://afterburner.voceplatforms.com/back- end.html#voce-widget-cache • http://afterburner.voceplatforms.com/back- end.html#voce-cached-nav • There are many more tips and tools on this website 9. 10. 2015 34
  • 35. http://lynt.cz HTTP server • Many options to run PHP • Apache (prefork) + mod_php • Apache (mpm event/worker) + PHP-FPM, FastCGI • Nginx + PHP-FPM 9. 10. 2015 35 Apache Apache - .htaccess Nginx req/s 8.2 9.35 9.96 0 2 4 6 8 10 12 req/s Apache vs Nginx Apache Apache - .htaccess Nginx Nginx + Microcache req/s 8.2 9.35 9.96 279.97 0 50 100 150 200 250 300 req/s Apache vs Nginx + Microcache (unfair comparism) AllowOverride None
  • 36. http://lynt.cz /wp-content/uploads/revslider/classicslider/bike.jpg 9. 10. 2015 36 Hey, is .htaccess here? And here?Here? Or here? Here it is! Apache is not convenient to server static files
  • 37. http://lynt.cz Back to our webserver • We used microcache to achieve excellent results – Nginx will remember result of request for a while (seconds, minutes) • This technic is useful in case of peak traffic – e.g after new content release • Microcache: Requests per second: 319.26 [#/sec] • WP Supercache: Requests per second: 270.84 [#/sec] • No caching *: Requests per second: 13.52 [#/sec] * Test was performed with hundreds other requests on production environment 9. 10. 2015 37
  • 38. http://lynt.cz The last benchmark • Test to the WEDOS VPS with more concurrency ab -n 1000 -c 40 http://domain • Requests per second: 1191.49 [#/sec] (mean) • Time per request: 33.572 [ms] (mean) • Time per request: 0.839 [ms] (mean, across all concurrent requests) Important note: „Using cache isn‘t so easy, you need to resolver cache invalidation!“ 9. 10. 2015 38 Very good result with cheap VPS
  • 40. http://lynt.cz Blackfire.io • Performance profiling, great visualization • Requires to install agent and PHP extension - tutorial • You can run profiling from Chrome with Blackfire Companion • Hack version for free • Premium version 82,5€/month (DB queries and HTTP requests analysis, teams, longer data retention) 9. 10. 2015 40
  • 41. http://lynt.cz9. 10. 2015 41 Performance consumed by function itself
  • 42. http://lynt.cz Localization takes more than 30%? • WP uses slow PHP implemetation of GetText • Solution: • https://github.com/LyntServices/WP-lang- cache (my very old hack to WP core, I have more modifications to use ObjectCache) • https://wordpress.org/plugins/mo-cache/ 9. 10. 2015 42
  • 44. http://lynt.cz Why is do_action so slow? 9. 10. 2015 44 From PHP5.6 you can use optimized Argument Unpacking functionality: …$the_['acceped_args'] Call_user_func_array function itself isn‘t problem – problem is hundreds and thousands calls of this function (or any other function).
  • 45. http://lynt.cz Big problem - demo 9. 10. 2015 45 Recursion – shortcodes in shortcodes in shorcodes … Huh, so many calls! Big grey bar – use of object cache makes it worse – it will call many userializations
  • 46. http://lynt.cz Another problem – with fix! 9. 10. 2015 46 OMG!
  • 47. http://lynt.cz Another problem – with fix! 9. 10. 2015 47 Fix: extension=json.so Native JSON extension was missing! 9.2s => 0.0248s = 370x better performance with one line 
  • 48. http://lynt.cz Dead end of profiling • When you profile WP in Blackfire you usually stop in two cases: 1) do_action – common and heavy used WP function (like apply_filters), you cannot track cause and effect of particular call in Blackfire 2) Grey bar – performance is lost inside function – code isn‘t visible • Now debugging is come 9. 10. 2015 48
  • 49. http://lynt.cz Xdebug • PHP extension: http://xdebug.org/ • Wizard helps you to download the correct versions and what to insert into PHP config according your phpinfo() output: http://xdebug.org/wizard.php • Great config setting explanation: https://gist.github.com/IngmarBoddington/53 11858 9. 10. 2015 49 xdebug.remote_enable = 1 xdebug.profiler_enable_trigger = 1 xdebug.trace_format = 1 xdebug.trace_enable_trigger = 1
  • 50. http://lynt.cz Xdebug – what to do? • Allows to go through code step by step from IDE • Trace-log generation • Code coverage analysis • Profiling (more overhead than Blackfire) xdebug.profiler_enable_trigger = 1 ?XDEBUG_PROFILE • You can use WebGrind for visualization: https://github.com/jokkedk/webgrind • Xdebug Helper – Chrome extension: https://chrome.google.com/webstore/detail/xdebug- helper/eadndfjplgieldjbigjakmdgkmoaaaoc 9. 10. 2015 50
  • 52. http://lynt.cz Trace • Tracelog – huge amount of data • Useful for resolving memory problems • https://github.com/corretge/xdebug-trace-gui 9. 10. 2015 52 line spent time Difference of consumed memory Memory consuption during script execution
  • 53. http://lynt.cz Tracing part of code 9. 10. 2015 53 xdebug_start_trace('for.xt'); for ($i=0;$i<3;$i++){ echo rand(0,$i); } xdebug_stop_trace(); TRACE START [2015-10-01 11:49:49] 2 2 1 0.005554 223088 2 3 0 0.005621 223128 rand 0 D:htdocswp4info.php 7 2 3 1 0.005740 223128 2 4 0 0.005770 223128 rand 0 D:htdocswp4info.php 7 2 4 1 0.005879 223128 2 5 0 0.005908 223128 rand 0 D:htdocswp4info.php 7 2 5 1 0.006016 223128 2 6 0 0.006044 223096 xdebug_stop_trace 0 D:htdocswp4info.php 9 0.006130 223120 TRACE END [2015-10-01 11:49:49]
  • 54. http://lynt.cz Stepping through code 9. 10. 2015 54 Default: localhost:9000
  • 55. http://lynt.cz Père Fouras: Pensée du jour 9. 10. 2015 55 „This is the end of web developers era, era of system adminstrators has begun.“
  • 56. http://lynt.cz Summary – performance analysis • How it shows from outside? – https://gtmetrix.com/ – http://www.webpagetest.org/ – Developer console in browser • What slows WP down? – P3 profiler – tentative detection of slow plugins – Query monitor – particular DB queries and more • Profiling and debugging – Blackfire.io – Xdebug (visialization with webgrind) 9. 10. 2015 56
  • 57. http://lynt.cz This is the end, folks. 9. 10. 2015 57 Small gift: Blackfire.io Premium for a month: DODWEDOS102015 valid until 19.10.2015 You can use this coupon during monthly subscription checkout You can follow me on twitter @smitka and visit our blog http://lynt.cz/blog

Editor's Notes

  • #6: Co způsobuje pomalost?
  • #8: Proč se používají 24 bit PNG?
  • #20: Pozor na koncová lomítka, proveďte jejich přesměrování na straně serveru, ne na straně CMS