Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Desmistificando o profiling no PHP com Cachegri...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Desmistificando o profiling no PHP com Cachegrind e Meminfo

Avatar for Gus Antoniassi

Gus Antoniassi

December 06, 2019
Tweet

More Decks by Gus Antoniassi

Other Decks in Programming

Transcript

  1. Conexão lenta com o BD - tc qdisc add dev

    eth0 root netem delay 500ms
  2. 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
  3. 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
  4. 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); } } // ...
  5. Ajustando nosso código // ... if ($i % 1000 ===

    0) { echo $i . " usuários importados\n"; $this->entityManager->flush(); $this->entityManager->clear(); } } // ...