blackfire.io phpvigo talk

29

Upload: php-vigo

Post on 22-Jan-2018

179 views

Category:

Presentations & Public Speaking


0 download

TRANSCRIPT

Page 1: Blackfire.io PHPVigo Talk
Page 2: Blackfire.io PHPVigo Talk

Meetups

@SergioCarracedoRubén GonzálezProgramador vocacional.Teleco.JS, C, C++, Java, PHP, Python, Scala, Rust, Go...

@rubenrua

Page 3: Blackfire.io PHPVigo Talk

Control de calidad del software

Meetups

● Test unitarios● Test funcionales● Test de integración● Test de UX● Test de performance

Page 4: Blackfire.io PHPVigo Talk

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?

Page 5: Blackfire.io PHPVigo Talk

¿Por qué el performance importa?

Meetups

● ...

Page 6: Blackfire.io PHPVigo Talk

¿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

Page 7: Blackfire.io PHPVigo Talk

¿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...

Page 8: Blackfire.io PHPVigo Talk

¿Como se consigue performance en PHP?

Meetups

Usa PHP7 (Con OPcache)

Page 9: Blackfire.io PHPVigo Talk

¿Como se consigue performance en PHP?

Meetups

Usa PHP7 (Con OPcache y sin Xdebug)

Page 10: Blackfire.io PHPVigo Talk

Sobre performance

Meetups

Antes de optimizar, mide mucho y bien. (blackfire.io)

Page 11: Blackfire.io PHPVigo Talk

¿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.

Page 12: Blackfire.io PHPVigo Talk

¿Que es blackfire.io?

Meetups

Page 13: Blackfire.io PHPVigo Talk

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

Page 14: Blackfire.io PHPVigo Talk

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

Page 16: Blackfire.io PHPVigo Talk

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

Page 20: Blackfire.io PHPVigo Talk

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;}

Page 21: Blackfire.io PHPVigo Talk

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;}

Page 22: Blackfire.io PHPVigo Talk

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

Page 23: Blackfire.io PHPVigo Talk

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."

Page 24: Blackfire.io PHPVigo Talk

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."

Page 25: Blackfire.io PHPVigo Talk

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."

Page 26: Blackfire.io PHPVigo Talk

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."

Page 27: Blackfire.io PHPVigo Talk

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

Page 28: Blackfire.io PHPVigo Talk

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

Page 29: Blackfire.io PHPVigo Talk

www.opsou.com www.pedrofigueras.com