blackfire.io phpvigo talk
Post on 22-Jan-2018
180 Views
Preview:
TRANSCRIPT
Meetups
@SergioCarracedoRubén GonzálezProgramador vocacional.Teleco.JS, C, C++, Java, PHP, Python, Scala, Rust, Go...
@rubenrua
Control de calidad del software
Meetups
● Test unitarios● Test funcionales● Test de integración● Test de UX● Test de performance
Control de calidad del software
Meetups
● Test unitarios● Test funcionales● Test de integración● Test de UX● Test de performance
¿Quien hace test de performance?
¿Por qué el performance importa?
Meetups
● ...
¿Por qué el performance importa?
Meetups
● Dejar un mundo más verde.○ Menos recursos necesarios.○ Menos energía gastada.
● $$$$○ Otra forma de ver el punto anterior.
● Happy users ⟹ More users (SEO)○ 40% of users abandon a website that takes more than 3 seconds to load.
● Fama.○ http://www.techempower.com/benchmarks/○ http://benchmarksgame.alioth.debian.org/u64q/php.html
¿Como se consigue performance?
Meetups
● Cliente: Optimizar assets (guetzli), JS, Chrome DevTools...● Red: HTTP/2, comprimir tráfico (TLS 1.3 0-RTT)...● Servidor: cache, optimizar servidor, optimizar aplicación.● Base de datos: saltar ORM/ODM, desnormalizar esquema, cache...
¿Como se consigue performance en PHP?
Meetups
Usa PHP7 (Con OPcache)
¿Como se consigue performance en PHP?
Meetups
Usa PHP7 (Con OPcache y sin Xdebug)
Sobre performance
Meetups
Antes de optimizar, mide mucho y bien. (blackfire.io)
¿Que es blackfire.io?
Meetups
● Profiler para PHP● Mejora la UX de XHProf (y de var_dump([microtime(), memory_get_usage()]);)● De los creadores de Symfony ● Saas● Instalar servicio linux (docker) y zend_extension● Vale para peticiones HTTP y para CLI● Blackfire puede ser usado en cualquier fase del ciclo de video de tu aplicación: durante el
desarrollo, test, pre-produccion and produccion, para medir, test, debug y optimizar su performance.
¿Que es blackfire.io?
Meetups
Como se instala
Meetups
# https://blackfire.io/docs/up-and-running/installation
$ # Configuring the Debian Repository$ wget -O - https://packagecloud.io/gpg.key | apt-key add -$ echo "deb http://packages.blackfire.io/debian any main" | tee /etc/apt/sources.list.d/blackfire.list$ apt-get update
$ # Installing the Agent$ apt-get install -y blackfire-agent$ sudo blackfire-agent -register$ sudo /etc/init.d/blackfire-agent restart
$ # Installing the CLI tool$ blackfire config
$ # Installing the PHP Probe$ apt-get install -y blackfire-php$ php -m[PHP Modules]blackfire…[Zend Modules]Zend OPcacheblackfire
DEMO: First profile
Meetups
● https://blackfire.io/docs/24-days/04-first-profile● http://gitlist.demo.blackfire.io/● https://blackfire.io/profiles/bc2e9173-1e17-4fdd-aa36-d1b4e742a945/graph
DEMO: First profile
Meetups
● https://blackfire.io/docs/24-days/04-first-profile● Site, profile and comparation.
Caso real: PuMuKIT
Meetups
root@aa272b34fafc:/var/www/pumukit2# blackfire curl http://172.17.42.2/podcast/conferencevideo.xml Profiling: [########################################] 10/10Blackfire cURL completed Profile URL: https://blackfire.io/profiles/eed51004-e27c-452d-82be-49677a263113/graph Total time: 3.56 s I/O: 31.8 ms Memory: 358 MB root@aa272b34fafc:/var/www/pumukit2# blackfire curl http://172.17.42.2/podcast/conferencevideo.xml Profiling: [########################################] 10/10Blackfire cURL completed Profile URL: https://blackfire.io/profiles/3bc6fccf-d64e-4e51-9e5c-64e732bd6e9f/graph Total time: 3.06 s I/O: 29.3 ms Memory: 37.9 MB
● Force an UnitOfWork::clear● https://github.com/campusdomar/PuMuKIT2/commit/7c5fa20a8eca5e243ba57daaf24530e42c38b3d8?w=1
Caso real 2: Composer
Meetups
● https://github.com/composer/composer/pull/6168● https://blackfire.io/profiles/675af85e-e54c-43af-9144-f7021639563a/graph● https://blackfire.io/profiles/compare/675af85e-e54c-43af-9144-f7021639563a...0c2b42
21-8b63-4b65-9931-84629ec58e99/graph
El código
Meetups
<?php//Memory 38MB
class Rule{ public $literals;
public function __construct(array $literals) { $this->literals = $literals; }}
$rules = array();
$i = 0;while ($i<80000){ // $i++;
$array = array(-$i, $i); $rule = new Rule($array); $rules[] = $rule;}
El código
Meetups
<?php//Memory 38MB
class Rule{ public $literals;
public function __construct(array $literals) { $this->literals = $literals; }}
$rules = array();
$i = 0;while ($i<80000){ // $i++;
$array = array(-$i, $i); $rule = new Rule($array); $rules[] = $rule;}
<?php//Memory 11.1MB
class Rule2Literal{ public $literal1; public $literal2;
public function __construct($literal1, $literal2) { $this->literal1 = $literal1; $this->literal2 = $literal2; }}
$rules = array();
$i = 0;while ($i<80000){ // $i++;
$rule = new ConflictRule(-$i, $i); $rules[] = $rule;}
Resultado
Meetups
Project master 1st iter 2nd iter
https://github.com/Sylius/Sylius.git 43.7s 983 MB 41.8s 765 MB 46.6s 539 MB
https://github.com/laravel/laravel.git 7.49s 205 MB 6.9s 189 MB 6.96s 178 MB
https://github.com/symfony/symfony-demo 31.9s 699 MB 31.4s 546 MB 32s 383 MB
Private project 51.1s 1000MB -- 50.6s 536MB
Otros casos reales
Meetups
● Composer got a huge performance boost last week thanks to the disabling of the garbage collector● How we sped up Sylius' Behat suite with Blackfire: The Sylius test suite is now 6 times faster and
consumes 90% less memory!● Optimizing league/commonmark with Blackfire.io: Two simple changes led to a whopping 52.5%
performance boost!● Pomm: A two hours run with Blackfire.io: "35% performance improvement is a major enhancement in
such a test case."● ownCloud: Recent Performance Optimizations: "Enthusiasm around the tool is becoming very visible,
with a large number of performance related pull requests showing up with Blackfire graphs."
Otros casos reales
Meetups
● Composer got a huge performance boost last week thanks to the disabling of the garbage collector● How we sped up Sylius' Behat suite with Blackfire: The Sylius test suite is now 6 times faster and
consumes 90% less memory!● Optimizing league/commonmark with Blackfire.io: Two simple changes led to a whopping 52.5%
performance boost!● Pomm: A two hours run with Blackfire.io: "35% performance improvement is a major enhancement in
such a test case."● ownCloud: Recent Performance Optimizations: "Enthusiasm around the tool is becoming very visible,
with a large number of performance related pull requests showing up with Blackfire graphs."
Otros casos reales
Meetups
● Composer got a huge performance boost last week thanks to the disabling of the garbage collector● How we sped up Sylius' Behat suite with Blackfire: The Sylius test suite is now 6 times faster and
consumes 90% less memory!● Optimizing league/commonmark with Blackfire.io: Two simple changes led to a whopping 52.5%
performance boost!● Pomm: A two hours run with Blackfire.io: "35% performance improvement is a major enhancement in
such a test case."● ownCloud: Recent Performance Optimizations: "Enthusiasm around the tool is becoming very visible,
with a large number of performance related pull requests showing up with Blackfire graphs."
Otros casos reales
Meetups
● Composer got a huge performance boost last week thanks to the disabling of the garbage collector● How we sped up Sylius' Behat suite with Blackfire: The Sylius test suite is now 6 times faster and
consumes 90% less memory!● Optimizing league/commonmark with Blackfire.io: Two simple changes led to a whopping 52.5%
performance boost!● Pomm: A two hours run with Blackfire.io: "35% performance improvement is a major enhancement in
such a test case."● ownCloud: Recent Performance Optimizations: "Enthusiasm around the tool is becoming very visible,
with a large number of performance related pull requests showing up with Blackfire graphs."
Consejos
Meetups
● Primero usa PHP7 (y OPCache).● Antes de optimizar, mide mucho y bien. (blackfire.io)● Conoce tus herramientas (time) (@igrigorik). ● PHP no vale para todo. (@julienPauli)● La optimización prematura es la raíz de todos los males. (Donald Knuth)● You can optimise for execution speed. You can optimise for space.
But the most precious thing you should optimise for is understandability
Links
Meetups
● https://blackfire.io/docs/24-days/01-introduction● https://blog.blackfire.io/php-7-performance-improvements-packed-arrays.html● https://hpbn.co/● http://www.ideas2it.com/blog/symfony-performance-tips-tricks/● http://jpauli.github.io/2015/03/05/opcache.html#configuring-opcache● https://getcomposer.org/doc/articles/autoloader-optimization.md
www.opsou.com www.pedrofigueras.com
top related