View
94
Download
0
Category
Preview:
Citation preview
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 1
PHP#Meetup#Melbourne,#Australia#
April#2014#
Harald#Zeitlhofer#
@HZeitlhofer#
PHP#Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 2
• 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 DISTRIBUTE 3
I’m#from#Austria#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 4
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 5
But#you#probably#know#that...#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 6
And#for#sure#you##know#that##
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 7
Also#from#Austria#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 8
You#might#have#heard#of...#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 9
Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 10
Failures happen!!
Nobody likes it when …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 11
Unless you work for Google or Microsoft !
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 12
… or this …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 13
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 14
.. as it leads to this …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 15
The#“War#Room”#
#Facebook#–#December#2012#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 16
… and potentially to this …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 17
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 18
And this isn’t helping either …
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 19
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 20
Yes, failures happen!!
but we can identify and/or avoid them !
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 21
but#where#should#we#start?#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 22
and#when#???#?
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 23
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 24
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 25
some%use%cases%and%best%prac/ces%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 26
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 27
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 DISTRIBUTE 28
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 DISTRIBUTE 29
cached#content#
s=ll#creates#roundtrips#!#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 30
use%proper%caching%%
pack%JS,%CSS%files%%
use%sprites%for%images%%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 31
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 32
frustrated#users#
slow#user#ac=on#
response#=me#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 33
errors#in#PHP#execu=on#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 34
less#library#caused#
performance##
hotspot#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 35
know%your%code%%
know%your%%external%libraries%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 36
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 37
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 38
/katgrp/browse#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 39
/katgrp/get/$/1626#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 40
/cave/browse/gis/$/katgrp/1626#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 41
/cave/browse/gis/$/katgrp/1626#–#applica=on#context#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 42
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 DISTRIBUTE 43
Looks#bener#now…#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 44
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 45
performance#hotspot#
/en/externalprice/#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 46
response#=me##
hotspot#PHP#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 47
session#data#locking#
response#=me#hotspot:#
usleep();%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 48
be%careful%with%locking%%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 49
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 50
Locking#problem#solved,#but#…#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 51
/katgrp/browse#server#side#execu=on#
=me#to#check##
the#database#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 52
From#the#DB#perspec=ve#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 53
Here#we#go:#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 54
N+1#Queries#
Metrics:####SQL#Execu=ons#/#Request#
##of#“same”#SQL#Execu=ons#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 55
mind%the%database%!!!%%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 56
anything#else#we#can#do?#
what#about##
3rd#party#content?#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 57
3rd#party#content#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 58
3rd#party#content#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 59
watch%external%services%%
be%aware%there%are%services%you%%can't%control%
%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 60
to#summarize#that#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 61
PHP#Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 62
PHP#OpCache#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 63
PHP#OpCache#disabled#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 64
PHP#OpCache#enabled#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 65
huge#number#of#
sta=c#resources#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 66
Web#Request#handling#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 67
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 68
Web#Request#handling#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 69
Transac=on#flow#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 70
Nginx#FastCGI#cache#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 71
Nginx#FastCGI#cache#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 72
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 DISTRIBUTE 73
• 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 DISTRIBUTE 74
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 DISTRIBUTE 75
use%right%server%tools%%
configure%properly%%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 76
But still, failures happen!!
make sure to identify
them as soon as possible
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 77
EndtTotEnd#Applica=on#Monitoring#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 78
monitor%all%transac/ons%in%all%channels%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 79
User#Experience#Management#
locate%regional%performance%issues%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 80
monitor%your%infrastructure%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 81
process%monitoring%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 82
iden/fy%response%/me%hotspots%in%the%backend%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 83 drill%down%to%find%the%root%cause%
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 84
Applica=on#Performance#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 85
Performance#Tools#
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 86
• 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 DISTRIBUTE 87
www.dynatrace.com#
Thank#you#!!!#
Harald%Zeitlhofer%Senior#Technology#Strategist#
#HZeitlhofer#
harald.zeitlhofer@dynatrace.com#
hnp://blog.dyntrace.com#
Recommended