Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Desmistificando o profiling no PHP com Cachegri...
Search
Gus Antoniassi
December 06, 2019
Programming
84
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Desmistificando o profiling no PHP com Cachegrind e Meminfo
Gus Antoniassi
December 06, 2019
More Decks by Gus Antoniassi
See All by Gus Antoniassi
Arquitetando aplicações escaláveis e resilientes com PHP
gusantoniassi
0
110
Other Decks in Programming
See All in Programming
sbt 2.0: takeoff
eed3si9n
0
160
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
480
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
Railsバージョンを4倍にした話
optim
0
370
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
280
残高管理から台帳サービスへの進化
artoy
1
200
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
1.3k
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
550
RailsConf 2023
tenderlove
30
1.6k
What's in a price? How to price your products and services
michaelherold
247
13k
Building the Perfect Custom Keyboard
takai
2
910
How to Talk to Developers About Accessibility
jct
2
580
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Transcript
DESMISTIFICANDO O PROFILING NO PHP COM CACHEGRIND E MEMINFO
WHOAMI
WHOAMI
WHOAMI “Ex” PHP dev Mandic Cloud Solutions
XDebug + CacheGrind Análises comuns Introdução ao profiling O QUE
VEREMOS HOJE Memory leaks e Meminfo
Lentidão
PROFILING
O que é profiling?
None
PROFILING COM CACHEGRIND
None
None
Cachegrind
None
Interfaces gráficas
XDEBUG
XDEBUG
Instalação do XDebug
Configuração do XDebug para profiling
Configuração do XDebug para profiling
Configuração do XDebug para profiling
MÃO NA MASSA
Criando o código
Subindo a aplicação (docker)
Executando no navegador
Verificando os arquivos gerados
Importando o arquivo no KCacheGrind
Importando o arquivo no KCacheGrind
Importando o arquivo no KCacheGrind
Profiling no KCacheGrind
Profiling no KCacheGrind
Profiling no KCacheGrind
THAT’S ALL, FOLKS
INDO ALÉM DO BÁSICO
Lentidão - Composer
None
None
None
None
Solução
INDO (MAIS) ALÉM DO BÁSICO
Conexão lenta com o BD - tc qdisc add dev
eth0 root netem delay 500ms
None
None
None
None
Solução
BLZ, MAS E A PRODUÇÃO?
XDebug em produção - Inclusive ele pode “exagerar” alguns loops
com muitas repetições
PROFILING EM PRODUÇÃO
XhProf
Tideways
Blackfire.io
Profiling tips
MEMORY LEAKS E MEMINFO
Utilização de memória nas aplicações
Utilização de memória nas aplicações
Memory Leaks https://nikic.github.io/2015/05/05/Internal-value-representation-in-PHP-7-part-1.html
Extensão Meminfo
Instalar $ phpize $ ./configure --enable-meminfo $ make $ make
install
Exemplo de memory leak da vida real "gus.antoniassi","
[email protected]
","Gustavo Antoniassi" "rasmus","
[email protected]
","Rasmus
Lerdorf" "galvao","
[email protected]
","Er Galvão Abbott" https://www.youtube.com/watch?v=NjIlKlFImlo
Exemplo de memory leak da vida real public function importUsers($usuarios)
{ for ($i = 0; $i < 100000; $i++) { $usuarioCsv = $usuarios[$i % 3]; $usuario = new User(); $usuario->setLogin($usuarioCsv[0]); $usuario->setEmail($usuarioCsv[1]); $usuario->setFullName($usuarioCsv[2]); https://www.youtube.com/watch?v=NjIlKlFImlo
Exemplo de memory leak da vida real $this->entityManager->persist($usuario); if ($i
% 1000 === 0) { echo $i . " usuários importados\n"; $this->entityManager->flush(); } } $this->entityManager->flush(); echo $i . " usuários importados\n"; } https://www.youtube.com/watch?v=NjIlKlFImlo
Executando
Execução com memory leak
Como resolver? // ... if ($i % 1000 === 0)
{ echo $i . " usuários importados\n"; $this->entityManager->flush(); $fd = fopen(__DIR__ . "/../../var/meminfo-dump-$i.json", 'w'); meminfo_dump($fd); fclose($fd); } } // ...
Dump do conteúdo da memória
Pegar o “sumário” do conteúdo da memória
Pegar o “sumário” do conteúdo da memória
Pegar o “sumário” do conteúdo da memória
Agora temos um suspeito
Agora temos um suspeito
Vamos ver quem está segurando esse cara
Depois de um pouco de Google
Ajustando nosso código // ... if ($i % 1000 ===
0) { echo $i . " usuários importados\n"; $this->entityManager->flush(); $this->entityManager->clear(); } } // ...
Executando
Comparação
Symfony me trollou
OBRIGADO! bit.ly /phpconf-gus-profiling Avalie essa talk!