Profiling PHP @ phpCE Prague 2018

Profiling PHP @ phpCE Prague 2018

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

October 27, 2018
Tweet

Transcript

  1. Profiling PHP Sebastian Grodzicki @ phpCE 2018 !@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
 • CTO at SHOWROOM • 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 Athena

  16. AWS X-Ray

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

  18. Elastic Stack

  19. New Relic

  20. Datadog

  21. AppDynamics

  22. Dynatrace

  23. SolarWinds

  24. You cannot improve what you cannot measure.

  25. Profiling

  26. Speaker Deck

  27. None
  28. None
  29. None
  30. None
  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. 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
  48. None
  49. None
  50. None
  51. None
  52. None
  53. None
  54. None
  55. 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
  56. <?php declare(strict_types=1);
 
 namespace Repository;
 
 use ValueObject\SeoMeta;
 
 interface

    SeoRepositoryInterface
 {
 public function getSingleMetaForChannel(string $path): SeoMeta;
 } SeoRepositoryInterface.php
  57. 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
  58. None
  59. None
  60. None
  61. None
  62. CLI Command Line Interface

  63. <?php
 
 $url = 'https://2018.phpce.eu/en/';
 $html = \file_get_contents($url);
 $length =

    \strlen($html);
 
 echo \number_format($length) . PHP_EOL; phpCE.php
  64. $ php phpCE.php
 
 880,988 CLI

  65. $ blackfire run php phpCE.php
 
 880,988
 
 Blackfire Run

    completed
 Graph URL https://blackfire.io/profiles/3b82e363-91a6-4807- b03a-4e259a254b98/graph
 No tests! Create some now https://blackfire.io/docs/ cookbooks/tests
 No recommendations
 
 Wall Time 418ms
 I/O Wait 394ms
 CPU Time 24.1ms
 Memory 1MB
 Network 394ms 1MB 1rq
 SQL n/a n/a CLI
  66. None
  67. None
  68. Are you still with me? :)

  69. GoldenLine

  70. Increasing e-mail throughput by 110%

  71. Increasing e-mail throughput by 110%

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

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

  74. Blackfire's book to PHP Performance

  75. Questions?

  76. Thank you! # joind.in/talk/f943a

  77. None