COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE1
PHP#Meetup#Melbourne,#Australia#
April#2014#
Harald#Zeitlhofer#
@HZeitlhofer#
PHP#Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE2
• Technology#Strategist#at#Dynatrace#
• Database#and#Web#Development#
• PHP#for#more#than#15#years#
• Love#to#discover#new#things#
Harald#Zeitlhofer#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE3
I’m#from#Austria#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE4
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE5
But#you#probably#
know#that...#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE6
And#
for#
sure#
you##
know#
that##
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE7
Also#from#Austria#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE8
You#might#have#heard#of...#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE9
Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE10
Failures happen!!
Nobody likes it when …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE11
Unless you work for
Google or Microsoft !
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE12
… or this …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE13
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE14
.. as it leads to this …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE15
The#“War#Room”#
#
Facebook#–#December#2012#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE16
… and potentially to this …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE17
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE18
And this isn’t helping either …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE19
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE20
Yes, failures happen!!
but we can identify
and/or avoid them !
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE21
but#where#should#we#start?#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE22
and#when#???#
?
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE23
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE24
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE25
some%use%cases%
and%best%prac/ces%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE26
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE27
Not#following#Web#Performance#Best#Prac=ces# 282!$Objects#
on#that#page#9.68MB#Page#Size#
8.8s$Page#Load#
Time#
Most#objects#are#images#
delivered#from#the##
main#domain#
Very#long#connect#=me#
(1.8s)#to#the#CDN#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE28
Mobile#Web#Site:#This#SHOULD#NOT#happen!#
434$Resources$in#total#on#that#page:#
230#JPEGs,#75#PNGs,#50#GIFs,#…#
Total#size#of#~#20MB$
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE29
cached#content#
s=ll#creates#roundtrips#!#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE30
use%proper%caching%
%
pack%JS,%CSS%files%
%
use%sprites%for%images%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE31
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE32
frustrated#users#
slow#user#ac=on#
response#=me#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE33
errors#in#PHP#execu=on#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE34
less#library#caused#
performance##
hotspot#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE35
know%your%code%
%
know%your%%
external%libraries%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE36
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE37
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE38
/katgrp/browse#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE39
/katgrp/get/$/1626#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE40
/cave/browse/gis/$/katgrp/1626#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE41
/cave/browse/gis/$/katgrp/1626#–#applica=on#context#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE42
Sessions#in#PHP#
•  session_start()#locks#the#file#where#session#data#are#stored#
•  Released#when#script#ends#
•  Use#session_write_close()#to#unlock#the#file#before#execu=ng#slower#code#
•  Or#create#your#own##
save#handler#with##
session_set_save_handler()#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE43
Looks#bener#now…#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE44
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE45
performance#hotspot#
/en/externalprice/#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE46
response#=me##
hotspot#PHP#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE47
session#data#locking#
response#=me#hotspot:#
usleep();%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE48
be%careful%with%locking%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE49
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE50
Locking#problem#solved,#but#…#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE51
/katgrp/browse#server#side#execu=on#
=me#to#check##
the#database#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE52
From#the#DB#perspec=ve#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE53
Here#we#go:#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE54
N+1#Queries#
Metrics:##
##SQL#Execu=ons#/#Request#
##of#“same”#SQL#Execu=ons#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE55
mind%the%database%!!!%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE56
anything#else#we#can#do?#
what#about##
3rd#party#content?#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE57
3rd#party#content#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE58
3rd#party#content#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE59
watch%external%services%
%
be%aware%there%are%
services%you%%
can't%control%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE60
to#summarize#that#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE61
PHP#Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE62
PHP#OpCache#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE63
PHP#OpCache#disabled#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE64
PHP#OpCache#enabled#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE65
huge#number#of#
sta=c#resources#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE66
Web#Request#handling#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE67
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE68
Web#Request#handling#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE69
Transac=on#flow#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE70
Nginx#FastCGI#cache#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE71
Nginx#FastCGI#cache#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE72
Full#page#/#data#cache#with#Nginx#and#Memcached#
<?php
...
function __construct () {
$this->c = new Memcached();
$this->c->addServer('localhost',11211);
}
function setCache ($key, $content) {
$this->c->set($key, $content);
}
...
$this->setCache($_SERVER['REQUEST_URI'], $this->renderPage());
...
$this->setCache('/data/news/getlist', $this->getNewsList());
...
?>
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE73
• ngx_hnp_memcached_module#
Full#page#/#data#cache#with#Nginx#and#Memcached#
server {
location / {
set $memcached_key "$uri";
memcached_pass localhost:11211;
error_page 404 502 504 = @fallback;
}
location @fallback {
proxy_pass http://backend;
}
}
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE74
PHP,#5k#requests,#concurrency#100#
0#
1#
2#
3#
4#
5#
6#
7#
8#
Apache+PHP# Nginx+PHP# Nginx+Memcached#
<?php
echo "Hello World";
?>
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE75
use%right%server%tools%
%
configure%properly%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE76
But still,
failures happen!!
make sure to identify
them as soon as
possible
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE77
EndtTotEnd#Applica=on#Monitoring#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE78
monitor%all%transac/ons%in%all%channels%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE79
User#Experience#Management#
locate%regional%performance%issues%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE80
monitor%your%infrastructure%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE81
process%monitoring%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE82
iden/fy%response%/me%hotspots%in%the%backend%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE83 drill%down%to%find%the%root%cause%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE84
Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE85
Performance#Tools#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE86
• Load#Generator#(Apache#Benchmark,#JMeter)#
• Firebug,#Google#Developer#Tools#
Dynatrace#Ajax#Edi=on#
• Google#PageSpeed#
• Dynatrace#Free#Trial#
•  Free#trial#license#for#30#days#
•  Free#for#developers#on#local#machine#
My#favorites#
hnp://bit.ly/dnrial#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE87
www.dynatrace.com#
Thank#you#!!!#
Harald%Zeitlhofer%
Senior#Technology#Strategist#
#HZeitlhofer#
harald.zeitlhofer@dynatrace.com#
hnp://blog.dyntrace.com#

PHP application performance