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

Be smart, be fast with Web Debug Toolbar and Blackfire.io

K.Skaradziński
October 02, 2016
180

Be smart, be fast with Web Debug Toolbar and Blackfire.io

PHPCon 2016

K.Skaradziński

October 02, 2016
Tweet

Transcript

  1. Be smart, be fast
    With Web Debug Toolbar and Blackfire.io

    View Slide

  2. Web Debug Toolbar

    View Slide

  3. View Slide

  4. Performance

    View Slide

  5. View Slide

  6. View Slide

  7. blackfire.io

    View Slide

  8. X-Blackfire-Query
    BLACKFIRE_QUERY

    View Slide

  9. View Slide

  10. View Slide

  11. The Wall Clock Time, or Wall Time, for a
    function call is the measure of the real
    time it took for PHP to execute its code:
    the difference between the time at
    which PHP entered the function and the
    time at which PHP left the function

    View Slide

  12. The CPU time is the amount of
    time the CPU was used for
    processing instructions.

    View Slide

  13. The I/O time is the time the CPU
    waited for input/output (I/O)
    operations.

    View Slide

  14. Network activity includes calls to
    databases like MySQL, PostreSQL, or
    MongoDB; HTTP calls to web services
    and APIs; calls to cache systems like
    Redis and Memcached; communications
    with services like queues, email
    daemons, remote filesystems; etc.

    View Slide

  15. Disk activity occurs when a
    program reads files from the
    filesystem, including when PHP
    loads a script or class file.

    View Slide

  16. Wall Time = CPU Time + I/O Time
    I/O Time = Network Time + Disk Time

    View Slide

  17. The inclusive time allows
    you to find the critical
    path of an application.

    View Slide

  18. The exclusive time allows
    to find the function calls
    to optimize first.

    View Slide

  19. blackfire --samples=1 curl http://www.goldenline.pl/
    Blackfire cURL completed
    Graph URL
    https://blackfire.io/profiles/dce9448e-be85-4312-9021-760a5e27a67e/graph
    Wall Time 228ms
    CPU Time 191ms
    I/O Time 37ms
    Memory 43.5MB
    Network n/a
    SQL n/a

    View Slide

  20. View Slide

  21. View Slide

  22. blackfire run php palindrome.php
    Blackfire Run completed
    Graph URL
    https://blackfire.io/profiles/b9a7eafa-cd2f-49f9-b955-5667ac76fa33/graph
    Wall Time 2.59ms
    CPU Time 1.14ms
    I/O Time 1.45ms
    Memory 18.8KB
    Network n/a
    SQL n/a

    View Slide

  23. Graph

    View Slide

  24. View Slide

  25. View Slide

  26. References

    View Slide

  27. blackfire --samples=1 --new-reference curl http://www.goldenline.pl/
    Blackfire cURL completed
    Graph URL
    https://blackfire.io/profiles/4cf06d0d-afab-484c-ba7a-c7377f7c4e48/graph
    Reference: #1. Untitled
    Wall Time 233ms
    CPU Time 228ms
    I/O Time 4.75ms
    Memory 43.4MB
    Network n/a
    SQL n/a

    View Slide

  28. blackfire --samples=1 --reference=1 curl http://www.goldenline.pl/
    Blackfire cURL completed
    Graph URL
    https://blackfire.io/profiles/compare/4cf06d0d-afab-484c-ba7a-c7377f7c4e48...
    5e719fd0-5839-4495-866a-142181a0f4a1/graph
    Wall Time 207ms -26ms -14.5%
    CPU Time 176ms -52ms -14.5%
    I/O Time 30.6ms +25.9ms +45.8%
    Memory 43.4MB +8.88KB n/s
    Network 13µs 294B 1rq
    SQL n/a -

    View Slide

  29. View Slide

  30. View Slide

  31. Recommendations

    View Slide

  32. blackfire --samples=1 --reference=1 curl http://www.goldenline.pl/
    Blackfire cURL completed
    Graph URL
    https://blackfire.io/profiles/compare/4cf06d0d-afab-484c-ba7a-c7377f7c4e48...
    5e719fd0-5839-4495-866a-142181a0f4a1/graph
    1 recommendation
    https://blackfire.io/profiles/5e719fd0-5839-4495-866a-142181a0f4a1/graph?set
    tings%5BtabPane%5D=recommendations
    Wall Time 207ms -26ms -14.5%
    CPU Time 176ms -52ms -14.5%
    ...

    View Slide

  33. View Slide

  34. Assertions

    View Slide

  35. .blackfire.yml
    tests:
    "Home Page":
    path: "/"
    assertions:
    - metrics.redis.connections.count == 1
    - metrics.amqp.connections.count == 0
    - main.memory < 40Mb

    View Slide

  36. https://blackfire.io/docs/validator

    View Slide

  37. View Slide

  38. View Slide

  39. Writing assertions on the main profile costs is as easy as adding a valid
    dimension name to the main. Prefix:
    ● count
    ● wall_time
    ● cpu_time
    ● memory
    ● peak_memory
    ● io
    ● network_in
    ● network_out

    View Slide

  40. Test Scenarios

    View Slide

  41. .blackfire.yml
    scenarios:
    Pricing page:
    - /pricing
    Integrations page:
    - /integrations
    Blackfire.yml Validator:
    - path: /docs/validator
    method: POST
    samples: 10

    View Slide

  42. Only for HTTP requests, not
    CLI command

    View Slide

  43. Blackfire and PHPUnit

    View Slide

  44. composer require blackfire/php-sdk

    View Slide