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

Otimizando a execução de Código-Fonte PHP

Otimizando a execução de Código-Fonte PHP

Como detectar e minimizar problemas de performance em aplicações PHP

Avatar for Er Galvão Abbott

Er Galvão Abbott

February 21, 2014
Tweet

More Decks by Er Galvão Abbott

Other Decks in Programming

Transcript

  1. CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott -

    2/24/14 - 1 / 15 Otimizando a Execução de Cófigo-Fonte PHP www.galvao.eti.br Otimizando a Execução de Código-Fonte
  2. Quem?! CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott

    - 2/24/14 - 2 / 15 www.galvao.eti.br Er Galvão Abbott é o Presidente da ABRAPHP – Associação Brasileira de Profissionais PHP, Diretor da PHP Conference Brasil, o principal evento de PHP da América Latina e fundador do PHPBR, Grupo de Usuários com mais de 1.200 associados. Trabalha há mais de 19 anos desenvolvendo sistemas e aplicações com interface web, sendo 14 anos com PHP e 6 anos com Zend Framework. Trabalhou com diversas empresas de grande porte, tanto nacionais como internacionais. Palestra em eventos e ministra cursos em diversas instituições, bem como in company. Site: http://www.galvao.eti.br/ Twitter: @galvao Slides e Documentos: http://slideshare.net/ergalvao https://speakerdeck.com/galvao Fork me @ http://github.com/galvao Otimizando a Execução de Cófigo-Fonte PHP
  3. Objetivo Esta palestra tem por objetivo demonstrar técnicas de programação

    PHP que minimizam custos de performance, bem como analisar detalhes relativos a performance de aplicações desenvolvidas com a linguagem. Serão apresentados os seguintes tópicos: → Detectando o uso de recursos consumidos pela aplicação → Profiling → xdebug/KCachegrind → xhprof/xhgui → Configurações do PHP relacionadas a performance → Opções de código-fonte: há diferenças relevantes entre formas de código? → Conclusões CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 2/24/14 - 3 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP
  4. Profiling → xdebug/KCachegrind ↑Confiabilidade ↑Extensa Documentação ↑Intrusão mínima / inexistente

    → xhprof/xhgui ↑Facebook ↑GUI Web ↑Maior controle via PHP CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 2/24/14 - 4 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP ↓GUI Nativa (Compatibilidade) ↓Dependências (MongoDB) ↓Documentação (Extensão, Way Back) ↓Maior intrusão no código-fonte ↓Documentação Confusa (xhgui) X
  5. HowTo – xdebug/KCacheGrind CC Attribution-ShareAlike 3.0 Unported License by Er

    Galvão Abbott - 2/24/14 - 5 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP Painéis a esquerda: Flat Profile Painéis a direita: Quais funções chamaram/foram chamadas pela função
  6. HowTo – xdebug/KCacheGrind – Flat Profile CC Attribution-ShareAlike 3.0 Unported

    License by Er Galvão Abbott - 2/24/14 - 6 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP Tempo gasto na função (sem “filhas”) Quantas vezes a função foi chamada
  7. HowTo – xdebug/KCacheGrind – Callee Map CC Attribution-ShareAlike 3.0 Unported

    License by Er Galvão Abbott - 2/24/14 - 7 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP Representação visual do peso das funções/métodos executados.
  8. HowTo – xdebug/KCacheGrind – Callee Map CC Attribution-ShareAlike 3.0 Unported

    License by Er Galvão Abbott - 2/24/14 - 8 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP Tempo e quantidade de chamados da função selecionada
  9. Dicas - Atualize o PHP! PHP 5.2 → 5.3* CC

    Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 2/24/14 - 9 / 15 www.galvao.eti.br * Ref.: Documentação – Considerações de Performance – Garbage Collector Otimizando a Execução de Cófigo-Fonte PHP
  10. → Melhorias em requisições FastCGI → Melhorias no Gerenciamento de

    Memória → Melhoria no tempo de inicialização/encerramento → Uso de CPU aproximadamente 15% menor → Uso de memória aproximadamente 20% menor → Latência em requisição → resposta melhorada em aproximadamente 14% → Melhoria geral de performance de 10-15% CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 2/24/14 - 10 / 15 www.galvao.eti.br * Ref.: Rasmus Lerdorf – PHP Frameworks Day 2013 PHP 5.3 → 5.4* Otimizando a Execução de Cófigo-Fonte PHP Dicas - Atualize o PHP!
  11. → opcode Cache nativo → Pilha de chamada pré-alocada pelo

    compilador → Execução melhorada de chamadas aninhadas CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 2/24/14 - 11 / 15 www.galvao.eti.br * Ref.: Rasmus Lerdorf – PHP Conference Argentina PHP 5.4 → 5.5* Otimizando a Execução de Cófigo-Fonte PHP Dicas - Atualize o PHP!
  12. Dicas – Boas práticas Use um Autoloader CC Attribution-ShareAlike 3.0

    Unported License by Er Galvão Abbott - 2/24/14 - 12 / 15 www.galvao.eti.br Sessões no DB Output Buffering Evitar Getters & Setters simples Evitar cópias de variáveis Evitar queries SQL dentro de loops Evitar execuções desnecessárias de funções dentro de loops Otimizando a Execução de Cófigo-Fonte PHP Boas práticas
  13. Dicas - Configurações CC Attribution-ShareAlike 3.0 Unported License by Er

    Galvão Abbott - 2/24/14 - 13 / 15 www.galvao.eti.br realpath_cache_size – Afeta operações com arquivos Se há muitas operações de arquivos, aumente realpath_cache_ttl – Duração do cache de realpath Se arquivos raramente mudam, aumente (< 5.4) register_long_arrays – Se os arrays HTTP_*_VARS devem ser utilizados Desative register_argc_argv – Para execução de scripts de terminal Desative include_path – Path para inclusão de arquivos Mantenha o mais curto possível Otimizando a Execução de Cófigo-Fonte PHP Configurações
  14. Conclusões CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott

    - 2/24/14 - 14 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP Conclusões ↑ Profiling (xdebug); ↑ Boas Práticas; ↑ Tunning (PHP) ↑ Ferramentas específicas que agregam (Memcached, Gearman, etc...) ↑/↓ Ferramentas alternativas que substituem (Hack, HHVM, Phalcon/Zephyr, NginX) ↓ Alterações específicas de código-fonte* * Sobre opções de código-fonte: http://phpbench.com/ Otimizando a Execução de Cófigo-Fonte PHP
  15. Obrigado! ? Dúvidas? ↓ Críticas? ↑ Elogios?! CC Attribution-ShareAlike 3.0

    Unported License by Er Galvão Abbott - 2/24/14 - 15 / 15 www.galvao.eti.br Otimizando a Execução de Cófigo-Fonte PHP