PHP application performance

Harald Zeitlhofer
Harald ZeitlhoferPerformance Advocate
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#
1 von 87

Más contenido relacionado

Destacado(20)

6 gkh internet6 gkh internet
6 gkh internet
Anastasia Vinogradova425 views
Homecoming 2014 FinalHomecoming 2014 Final
Homecoming 2014 Final
jeremycaldwell212233 views
Elemen Perubahan Kurikulum revElemen Perubahan Kurikulum rev
Elemen Perubahan Kurikulum rev
apriliakeren249 views
kacxis sveti  C I Ukacxis sveti  C I U
kacxis sveti C I U
defoo1.2K views
Assure model day 1Assure model day 1
Assure model day 1
sebastiankyle258 views
Customer journey mcb 2015Customer journey mcb 2015
Customer journey mcb 2015
Edwin Vlems368 views
.Sla 3.Sla 3
.Sla 3
hinosbadi267 views
Means of transportationMeans of transportation
Means of transportation
Doriscortes78221 views
InternetInternet
Internet
FéRnando Coro Q393 views
Isee 2016   early morning session - hkIsee 2016   early morning session - hk
Isee 2016 early morning session - hk
Haneen Khreis99 views
WordPress WorkshopWordPress Workshop
WordPress Workshop
Purushottam Dahal407 views
JardasJardas
Jardas
Denny Yahya881 views
Assure model day 3Assure model day 3
Assure model day 3
sebastiankyle322 views
Google page rankingGoogle page ranking
Google page ranking
Purushottam Dahal398 views
SchoolCTF 2012 - RingsSchoolCTF 2012 - Rings
SchoolCTF 2012 - Rings
delimitry352 views

Similar a PHP application performance(20)

PHP App Performance / Sydney PHPPHP App Performance / Sydney PHP
PHP App Performance / Sydney PHP
Harald Zeitlhofer941 views
SEO for PWAs #PubConSEO for PWAs #PubCon
SEO for PWAs #PubCon
Aleyda Solís2.1K views
PHP Application PerformancePHP Application Performance
PHP Application Performance
Harald Zeitlhofer696 views
ARTES 20 IAP Success Story - VecmapARTES 20 IAP Success Story - Vecmap
ARTES 20 IAP Success Story - Vecmap
Space-Applications872 views

Más de Harald Zeitlhofer(13)

Scaling PHP web appsScaling PHP web apps
Scaling PHP web apps
Harald Zeitlhofer932 views
PHP and databasesPHP and databases
PHP and databases
Harald Zeitlhofer938 views
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on Nginx
Harald Zeitlhofer1.5K views
Running PHP on NginxRunning PHP on Nginx
Running PHP on Nginx
Harald Zeitlhofer965 views
Improve Magento PerformanceImprove Magento Performance
Improve Magento Performance
Harald Zeitlhofer416 views
Running PHP on Nginx / PHP wgtnRunning PHP on Nginx / PHP wgtn
Running PHP on Nginx / PHP wgtn
Harald Zeitlhofer817 views
Running PHP on nginxRunning PHP on nginx
Running PHP on nginx
Harald Zeitlhofer595 views
Running php on nginxRunning php on nginx
Running php on nginx
Harald Zeitlhofer2.5K views
Nginx performance monitoring with DynatraceNginx performance monitoring with Dynatrace
Nginx performance monitoring with Dynatrace
Harald Zeitlhofer1.9K views
Nginx, PHP, Apache and SpelixNginx, PHP, Apache and Spelix
Nginx, PHP, Apache and Spelix
Harald Zeitlhofer2.6K views
Nginx, PHP and Node.jsNginx, PHP and Node.js
Nginx, PHP and Node.js
Harald Zeitlhofer2.4K views

PHP application performance