Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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.

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

→ 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!

Slide 11

Slide 11 text

→ 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!

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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