cache e performance (in portuguese)
DESCRIPTION
TRANSCRIPT
![Page 2: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/2.jpg)
Cache e Performance
PHP Advanced
Conteúdo• Arquitectura
• Profiling
• Benchmarking
• Cache
• Compressão
• Projecto
• Resumo
2
![Page 3: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/3.jpg)
Cache e Performance
PHP Advanced
Arquitectura
• Determina a forma como o sistema se comporta
• Afecta directamente a escalabilidade
• Consequentemente afecta a performance do sistema
3
storage MySQL
Web Server Web Server
Load Balancer
![Page 4: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/4.jpg)
Cache e Performance
PHP Advanced
Arquitectura
4
• Vários front-ends respondem a pedidos dos utilizadores
• Dados de sessão devem ser gravados num storage partilhado
• Scripts e conteúdo estático devem ser gravados em storage local
• Escala horizontalmente
![Page 5: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/5.jpg)
Cache e Performance
PHP Advanced
Arquitectura• Exemplo: 2 frontends, com escalabilidade
5
storage MySQL
Web Server Web Server
Load Balancer
![Page 6: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/6.jpg)
Cache e Performance
PHP Advanced
Arquitectura• Exemplo: 2 frontends, 2 MySQLs
6
storageMySQL
read
Web Server Web Server
Load Balancer
MySQL
write
![Page 7: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/7.jpg)
Cache e Performance
PHP Advanced
Arquitectura• Exemplo: 2 frontends, 2 MySQLs reads, 1
MySQL write
7
storage
MySQL
read
Web Server Web Server
Load Balancer
MySQL
write
MySQL
read
Load Balancer
![Page 8: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/8.jpg)
Cache e Performance
PHP Advanced
Profiling
• Permite medir os tempos de execução de um script, ou de parte de um script
• Permite medir a utilização de memória durante a execução de um script
• Fornece informação que ajuda a melhorar a performance de toda a aplicação
8
![Page 9: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/9.jpg)
Cache e Performance
PHP Advanced
Profiling
• Xdebug: http://www.xdebug.org/
• Zend Platform: http://www.zend.com/
9
![Page 10: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/10.jpg)
Cache e Performance
PHP Advanced
Profiling
10
![Page 11: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/11.jpg)
Cache e Performance
PHP Advanced
Benchmarking
• Permite medir os tempos de execução de um script ou conjunto de scripts, remotamente
• Ajuda a compreender até que ponto um Web Site consegue responder a pedidos
• Tipicamente é executado repetidamente ou durante um período de tempo
11
![Page 12: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/12.jpg)
Cache e Performance
PHP Advanced
Benchmarking• ab (Apache Benchmark):
http://httpd.apache.org/docs/2.0/programs/ab.html
• JMeter: http://jakarta.apache.org/jmeter/
12
![Page 13: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/13.jpg)
Cache e Performance
PHP Advanced
Conteúdo estático
• Não envolve processamento
• Fornecido directamente pelo Web Server
• Leve e rápido
• Exemplos:
• imagens, HTML, CSS, JavaScript
13
![Page 14: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/14.jpg)
Cache e Performance
PHP Advanced
Conteúdo dinâmico
• Envolve processamento no servidor
• Tipicamente um script é interpretado
• Mais lento que o conteúdo estático
• Exemplos:
• Perl, PHP, Python, Ruby
14
![Page 15: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/15.jpg)
Cache e Performance
PHP Advanced
Objectivos
• Sempre que possível, usar todo o conteúdo estático
• Dividir as páginas em blocos estáticos e dinâmicos, minimizando a quantidade de blocos dinâmicos
• Utilizar cache nos blocos dinâmicos
15
![Page 16: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/16.jpg)
Cache e Performance
PHP Advanced
Cache
• Permite gravar conteúdo dinâmico de modo a servi-lo estático
• Tem um tempo de vida, findo o qual o conteúdo volta a ser gerado dinamicamente
• Tipicamente o conteúdo estático é gravado no disco
16
![Page 17: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/17.jpg)
Cache e Performance
PHP Advanced
PEAR::Cache_Lite
• Instalação: pear install Cache_Lite
• Permite gravar conteúdo em cache
• Optimizado para a rapidez de escrita e leitura
• Grava conteúdo em disco ou memória
• Serializa conteúdo antes de gravar
17
![Page 18: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/18.jpg)
Cache e Performance
PHP Advanced
PEAR::Cache_Lite• Opções importantes
• cacheDir: directório onde os ficheiros de cache serão gravados
• lifeTime: tempo de vida da cache
• automaticSerialization: serialização automática do conteúdo a ser gravado
• memoryCaching: liga a cache em memória
18
![Page 19: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/19.jpg)
Cache e Performance
PHP Advanced
PEAR::Cache_Lite
19
![Page 20: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/20.jpg)
Cache e Performance
PHP Advanced
Compressão
• Permite servir conteúdo comprimido
• Depende das capacidades de cada browser
• Pode ser configurada através do Apache (httpd.conf ou .htaccess)
• Pode ser iniciada a partir do PHP
• Oferece poupanças na largura de banda utilizada
20
![Page 21: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/21.jpg)
Cache e Performance
PHP Advanced
Compressão
• Configuração no Apache
21
SetOutputFilter DEFLATEBrowserMatch ^Mozilla/4 gzip-only-text/htmlBrowserMatch ^Mozilla/4\.0[678] no-gzipBrowserMatch \bMSIE !no-gzip !gzip-only-text/html
![Page 22: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/22.jpg)
Cache e Performance
PHP Advanced
Compressão
• Iniciação no PHP através de ob_gzhandler
22
![Page 23: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/23.jpg)
Cache e Performance
PHP Advanced
Compilação de código
• Transforma o código PHP em opcodes
• Código permanece em memória
• É mais rápido a executar
• Não requer interpretação dos scripts
23
![Page 24: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/24.jpg)
Cache e Performance
PHP Advanced
Compilação de código
• Zend Optimizer: http://www.zend.com/
• APC: http://www.php.net/apc
24
![Page 25: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/25.jpg)
Cache e Performance
PHP Advanced
Projecto
• Inserção de cache na visualização dos resultados
• Determinação do correcto tempo de vida da cache através do TTL dos RSS
• Finalização do projecto
25
![Page 26: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/26.jpg)
Cache e Performance
PHP Advanced
Resumo
• Diferentes tipos de arquitectura
• Profiling e benchmarking
• Conteúdo estático vs conteúdo dinâmico
• Cache através de PEAR::Cache_Lite
• Compressão
• Compilação
26
![Page 27: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/27.jpg)
OOP em PHP
PHP Summer School
Questões?
27
![Page 28: Cache e Performance (in portuguese)](https://reader033.vdocuments.mx/reader033/viewer/2022051817/54880908b4af9f7d0d8b5550/html5/thumbnails/28.jpg)
Cache e Performance
PHP Advanced
Mais informação
28
• O meu blog: http://unfoldingtheweb.com/
• Manual de PHP: http://www.php.net/
• PEAR: http://pear.php.net/