Medindo a Performance deCódigos PHPPor Jonata Weber
View Slide
@JonataWeber
www.app2sales.com
PerformanceComputer performance is the amount of work accomplished by acomputer system.
Aspects of performance● Availability● Response Time● Processing Speed● Latency● Bandwidth● Throughtput● Scalability
Pick any twoCheapGoodFast
Development vs Production
Tools
Faker
Profile Before Optimizing
$then = microtime();myFunc();$now = microtime();echo sprintf("Elapsed: %f", $now - $then);There's a better way, right? :)
Apache Benchmarking$ ab -n 100 -c 10 http://localhost:8000
HTTP Benchmarking$ wrk -t12 -c400 -d30s http://localhost:8000
Testing High Availability
Load testing tool
Profiling
Install the xdebug$ pecl install xdebug
Starting the Profiler (php.ini)xdebug.profiler_enable=1xdebug.profiler_output_dirxdebug.profiler_enable_trigger=1More informations:https://xdebug.org/docs/profiler
Profiler Viewer
Profiler Viewer (in the browser)
Flame Graphs
XHProf: A Hierarchical Profiler for PHP
Demo
Problemas comuns
Problemas comuns● Arquitetura● Workload
Arquitetura● Sem cache;● Hardware mal dimensionado;● Aplicação single thread;● Latência de rede não prevista.
Workload● Mais usuários que o esperado;● Cache mal planejado.
Otimização precoce,fazer ou não fazer, eis a questão.
YAGNIYou Aren't Gonna Need It
Mas, as vezes é preciso!
Make work.Make right.Make fast.
O que não pode ser medido nãopode ser melhorado.
Esteja pronto, sempre!
Obrigado!@JonataWeber
Referênciashttps://speakerdeck.com/tarsisazevedo/performance-analysis-101http://wiki.c2.com/?PrematureOptimizationhttp://wiki.c2.com/?ProfileBeforeOptimizinghttp://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast