Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Desmistificando o profiling no PHP com Cachegri...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Gus Antoniassi
December 06, 2019
Programming
0
80
Desmistificando o profiling no PHP com Cachegrind e Meminfo
Gus Antoniassi
December 06, 2019
Tweet
Share
More Decks by Gus Antoniassi
See All by Gus Antoniassi
Arquitetando aplicações escaláveis e resilientes com PHP
gusantoniassi
0
100
Other Decks in Programming
See All in Programming
Claude Codeログ基盤の構築
giginet
PRO
7
3k
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.6k
Docコメントで始める簡単ガードレール
keisukeikeda
1
110
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
130
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
2.2k
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.3k
最初からAWS CDKで技術検証してもいいんじゃない?
akihisaikeda
4
130
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
220
猫の手も借りたい!ので AIエージェント猫を作って社内に放した話 Claude Code × Container Lambda の Slack Bot "DevNeko"
naramomi7
0
260
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
250
CSC307 Lecture 13
javiergs
PRO
0
320
How to stabilize UI tests using XCTest
akkeylab
0
120
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Navigating Weather and Climate Data
rabernat
0
140
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
We Are The Robots
honzajavorek
0
190
Raft: Consensus for Rubyists
vanstee
141
7.4k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
230
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
120
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.5k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
170
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!