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.

9a328142924c93e5e148c75356ba6d42?s=128

Sebastian Grodzicki

September 14, 2019
Tweet

Transcript

  1. Profiling PHP Sebastian Grodzicki @ HackYeah 2019 @sebgrodzicki

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

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

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

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

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

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

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

    SHOWROOM & GoldenLine • PHP developer for 15+ years • #perfmatters @sebgrodzicki
  9. SHOWROOM

  10. SHOWROOM

  11. You cannot improve what you cannot measure.

  12. APM Application Performance Monitoring

  13. Google Analytics

  14. AWS CloudWatch

  15. AWS CloudWatch

  16. AWS CloudWatch

  17. AWS CloudWatch

  18. AWS Athena

  19. AWS X-Ray

  20. AWS X-Ray

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

  22. Elastic Stack

  23. New Relic

  24. Datadog

  25. AppDynamics

  26. Dynatrace

  27. SolarWinds

  28. You cannot improve what you cannot measure.

  29. Profiling

  30. Speaker Deck

  31. None
  32. None
  33. None
  34. None
  35. None
  36. None
  37. None
  38. None
  39. None
  40. None
  41. None
  42. None
  43. None
  44. None
  45. None
  46. None
  47. None
  48. None
  49. None
  50. None
  51. None
  52. 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
  53. None
  54. None
  55. None
  56. None
  57. None
  58. None
  59. None
  60. 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
  61. <?php declare(strict_types=1);
 
 namespace Repository;
 
 use ValueObject\SeoMeta;
 
 interface

    SeoRepositoryInterface
 {
 public function getSingleMetaForChannel(string $path): SeoMeta;
 } SeoRepositoryInterface.php
  62. 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
  63. None
  64. None
  65. None
  66. None
  67. CLI Command Line Interface

  68. <?php
 
 $start = hrtime(true);
 
 sleep(3);
 
 $stop =

    hrtime(true);
 
 error_log(($stop - $start) / 1e+9); hackyeah.php
  69. $ php hackyeah.php
 
 3.002292529 CLI

  70. $ 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
  71. None
  72. None
  73. Are you still with me? :)

  74. GoldenLine

  75. Increasing e-mail throughput by 110%

  76. Increasing e-mail throughput by 110%

  77. Increasing e-mail throughput by 110%

  78. swiftmailer:
 default_mailer: default
 mailers:
 default:
 transport: aws.ses.transport
 spool: { type:

    db }
 config.yml
  79. Increasing e-mail throughput by 110%

  80. Increasing e-mail throughput by 110%

  81. Blackfire's book to PHP Performance

  82. Questions?

  83. Thank you!

  84. FREE BOOKS