Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Profiling PHP @ HackYeah 2019

Profiling PHP @ HackYeah 2019

You cannot improve what you cannot measure. That's why profiling applications should always be the first step before trying to improve its performance. Learn how to spot your applications' bottlenecks and how to adopt profiling into your developer pipeline.

Sebastian Grodzicki

September 14, 2019
Tweet

More Decks by Sebastian Grodzicki

Other Decks in Programming

Transcript

  1. phpinfo(); Sebastian Grodzicki
 • Engineering Manager at • ex-CTO at

    SHOWROOM & GoldenLine • PHP developer for 15+ years • #perfmatters @sebgrodzicki
  2. tests:
 
 "Application should never hit the DB":
 path: "/.*"


    assertions:
 - "metrics.sql.queries.count == 0"
 
 
 "Homepage should never call the API":
 path: "/"
 assertions:
 - "metrics.http.requests.count == 0"
 
 
 "Pages should be fast enough":
 path: "/.*"
 assertions:
 - "main.wall_time < 100ms"
 .blackfire.yml
  3. public function getSingleMetaForChannel(string $path): SeoMeta
 {
 
 $data = $this->client->getSingleMetaForChannel(null,

    $path);
 
 
 if (isset($data[$path])) {
 return SeoMeta::createFromSdk($data[$path]);
 } 
 throw new NotFoundException("Meta for path ${path} not found");
 } SeoRepository.php
  4. <?php declare(strict_types=1);
 
 namespace Repository;
 
 use ValueObject\SeoMeta;
 
 interface

    SeoRepositoryInterface
 {
 public function getSingleMetaForChannel(string $path): SeoMeta;
 } SeoRepositoryInterface.php
  5. public function getSingleMetaForChannel(string $path): SeoMeta
 {
 
 $options = [


    'lang' => self::MAP_CHANNEL_LOCALE[$this->channel],
 'orderings' => '[document.last_publication_date desc]',
 ];
 
 
 $document = $this->client->findOneByPath(
 'seo__content',
 $path,
 $options
 );
 
 
 if (null === $document) {
 throw new NotFoundException("Meta for path {$path} not found");
 }
 
 
 return new SeoMeta($document);
 } PrismicSeoRepository.php
  6. <?php
 
 $start = hrtime(true);
 
 sleep(3);
 
 $stop =

    hrtime(true);
 
 error_log(($stop - $start) / 1e+9); hackyeah.php
  7. $ blackfire run php hackyeah.php 
 
 3.00448906
 
 Blackfire

    Run completed
 Graph URL https://blackfire.io/profiles/4ae6c42b- b051-41bd-8ef9-65545bdf0c34/graph
 No tests! Create some now https://blackfire.io/docs/ cookbooks/tests
 No recommendations
 
 Wall Time 3.01s
 I/O Wait n/a
 CPU Time n/a
 Memory 40.7KB
 Network n/a n/a n/a
 SQL n/a n/a CLI