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. Profiling PHP
    Sebastian Grodzicki @ HackYeah 2019
    @sebgrodzicki

    View full-size slide

  2. Who is a developer?
    ȱȱȱȱȱȱȱȱȱȱ

    View full-size slide

  3. Who is not a developer?
    ȱȱȱȱȱȱȱȱȱȱ

    View full-size slide

  4. Who uses PHP?
    ȱȱȱȱȱȱȱȱȱȱ

    View full-size slide

  5. Who uses PHPUnit?
    ȱȱȱȱȱȱȱȱȱȱ

    View full-size slide

  6. Who is already profiling PHP?
    ȱȱȱȱȱȱȱȱȱȱ

    View full-size slide

  7. Who uses Blackfire?
    ȱȱȱȱȱȱȱȱȱȱ

    View full-size slide

  8. phpinfo();
    Sebastian Grodzicki

    • Engineering Manager at
    • ex-CTO at SHOWROOM & GoldenLine
    • PHP developer for 15+ years
    • #perfmatters
    @sebgrodzicki

    View full-size slide

  9. You cannot improve what you
    cannot measure.

    View full-size slide

  10. APM
    Application Performance Monitoring

    View full-size slide

  11. Google Analytics

    View full-size slide

  12. AWS CloudWatch

    View full-size slide

  13. AWS CloudWatch

    View full-size slide

  14. AWS CloudWatch

    View full-size slide

  15. AWS CloudWatch

    View full-size slide

  16. Nginx
    log_format apm '$upstream_response_time';
    access_log /var/log/nginx/access.log apm;

    View full-size slide

  17. Elastic Stack

    View full-size slide

  18. You cannot improve what you
    cannot measure.

    View full-size slide

  19. Speaker Deck

    View full-size slide

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

    View full-size slide

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

    View full-size slide


  22. namespace Repository;


    use ValueObject\SeoMeta;


    interface SeoRepositoryInterface

    {

    public function getSingleMetaForChannel(string $path): SeoMeta;

    }
    SeoRepositoryInterface.php

    View full-size slide

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

    View full-size slide

  24. CLI
    Command Line Interface

    View full-size slide


  25. $start = hrtime(true);


    sleep(3);


    $stop = hrtime(true);


    error_log(($stop - $start) / 1e+9);
    hackyeah.php

    View full-size slide

  26. $ php hackyeah.php


    3.002292529
    CLI

    View full-size slide

  27. $ 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

    View full-size slide

  28. Are you still with me? :)

    View full-size slide

  29. Increasing e-mail throughput by 110%

    View full-size slide

  30. Increasing e-mail throughput by 110%

    View full-size slide

  31. Increasing e-mail throughput by 110%

    View full-size slide

  32. swiftmailer:

    default_mailer: default

    mailers:

    default:

    transport: aws.ses.transport

    spool: { type: db }

    config.yml

    View full-size slide

  33. Increasing e-mail throughput by 110%

    View full-size slide

  34. Increasing e-mail throughput by 110%

    View full-size slide

  35. Blackfire's book to PHP Performance

    View full-size slide