Slide 1

Slide 1 text

Practical Debugging and Performance Pro fi ling #PHPDD23

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Photo by Stackie Jia on Unsplash Flow in which a person [….] is fully immersed in a feeling of energized focus, full involvement, and enjoyment in the process of the activity.

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

{ "name": "neos/neos-development-distribution", "description": "Neos Development Distribution", "license": "GPL-3.0-or-later", "support": { "email": "[email protected]", "slack": "http://slack.neos.io/", "forum": "https://discuss.neos.io/", "wiki": "https://discuss.neos.io/c/the-neos-project/project-documentation", "issues": "https://github.com/neos/neos-development-collection/issues", "docs": "http://neos.readthedocs.io/", "source": "https://github.com/neos/neos-development-distribution" }, "config": { "vendor-dir": "Packages/Libraries", "bin-dir": "bin", "preferred-install": { "neos/*": "source", "flowpack/*": "source" }, "allow-plugins": { "neos/composer-plugin": true } }, "require": { "neos/neos-development-collection": "8.0.x-dev", "neos/flow-development-collection": "8.0.x-dev", "neos/demo": "8.0.x-dev", "neos/neos-ui": "8.0.x-dev", "neos/neos-ui-compiled": "8.0.x-dev", "neos/fusion-form": "@dev", "neos/party": "@dev", "neos/seo": "@dev", "neos/imagine": "@dev", "neos/twitter-bootstrap": "@dev", "neos/form": "@dev", "neos/setup": "@dev", "flowpack/neos-frontendlogin": "@dev", "mikey179/vfsstream": "^1.6", "phpunit/phpunit": "^9.0", "symfony/css-selector": "^2.0", "symfony/css-selector": "^2.0", "vimeo/psalm": "~4.9.3", "neos/doctools": "^3.3" }, "repositories": { "distributionPackages": { "type": "path", "url": "./DistributionPackages/*" } }, "suggest": { "ext-pdo_sqlite": "For running functional tests out-of-the-box th }, "scripts": { "post-create-project-cmd": "./flow welcome", "post-update-cmd": "Neos\\Flow\\Composer\\InstallerScripts::postU "post-install-cmd": "Neos\\Flow\\Composer\\InstallerScripts::post "post-package-update": "Neos\\Flow\\Composer\\InstallerScripts::p "post-package-install": "Neos\\Flow\\Composer\\InstallerScripts:: "test-unit": "phpunit -c Build/BuildEssentials/PhpUnit/UnitTests. "test-functional": "phpunit -c Build/BuildEssentials/PhpUnit/Func "test-static-flow": "psalm --config=Packages/Framework/psalm.xml "psalm-baseline-update-flow": "psalm --config=Packages/Framework/ Framework/psalm-baseline.xml" }, "require-dev": { "neos/behat": "8.0.x-dev", "neos/buildessentials": "8.0.x-dev" } }

Slide 9

Slide 9 text

? ???

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

"bin-dir": "bin", "preferred-install": { "neos/*": "source", "flowpack/*": "source" }, "allow-plugins": { "neos/composer-plugin": true } }, "require": { "neos/neos-development-collection": "8.0.x-dev", "neos/flow-development-collection": "8.0.x-dev", "neos/demo": "8.0.x-dev", "neos/neos-ui": "8.0.x-dev", "neos/neos-ui-compiled": "8.0.x-dev", "neos/fusion-form": "@dev", "neos/party": "@dev", "neos/seo": "@dev", "neos/imagine": "@dev", "neos/twitter-bootstrap": "@dev", "neos/form": "@dev", "neos/setup": "@dev", "flowpack/neos-frontendlogin": "@dev", "mikey179/vfsstream": "^1.6", "phpunit/phpunit": "^9.0",

Slide 12

Slide 12 text

OSX Host System Docker Container(s) fi le mounts my model of reality

Slide 13

Slide 13 text

OSX Host System Linux Virtual Machine Docker Container(s) mounts no problem, without performance hit normal mounts not possible, !!! lots of workarounds for emulating mounting SLOW sshfs gRPC-fuse virtiofs reality

Slide 14

Slide 14 text

OSX Host System Linux Virtual Machine Docker Container(s) application source code cache fi les vendored source code

Slide 15

Slide 15 text

Method

Slide 16

Slide 16 text

Stable Foundation Hypothesis Design Experiment Execute Experiment Valid Knowledge write it down must give 100% reliable results

Slide 17

Slide 17 text

Unstable Foundation Modify some things in the codebase "which might improve things" do roughly the same steps, but not exactly

Slide 18

Slide 18 text

Use Production Data for Debugging / Pro fi ling prepare for non-linear behavior

Slide 19

Slide 19 text

What tools do we have available to design experiments? ... to generate validated knowledge

Slide 20

Slide 20 text

var_dump() die() am I in the right codebase? (die() in entrypoint) 
 am I in the right fi le? 
 is the opcache caching too agressively? 
 how often is this method called?

Slide 21

Slide 21 text

drydock execroot: enter a container as root

Slide 22

Slide 22 text

kill -USR2 [php-fpm] modify server con fi g re-read the PHP con fi g and restart

Slide 23

Slide 23 text

function B.2 throw new \RuntimeException("FOO"); read a stack trace function A function B.1 function C function main function main() { a() } function a() { b1(); b2(); } function b1() { c () } Stack

Slide 24

Slide 24 text

throw new \RuntimeException("FOO"); read a stack trace

Slide 25

Slide 25 text

xdebug_break() drydock xdebug [container] install xdebug into a running container

Slide 26

Slide 26 text

My code is slow...

Slide 27

Slide 27 text

Flame Graph

Slide 28

Slide 28 text

PHP-SPX

Slide 29

Slide 29 text

PHP-SPX drydock spx [container] install spx into a running container

Slide 30

Slide 30 text

Linux Kernel your program File IO System Calls Network IO current time

Slide 31

Slide 31 text

strace apt-get install strace (as root) strace -p [pid]

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

bpftrace

Slide 35

Slide 35 text

bpftrace

Slide 36

Slide 36 text

Summary

Slide 37

Slide 37 text

Stable Foundation Hypothesis Design Experiment Execute Experiment Valid Knowledge write it down run an experiment to establish foundation must give 100% reliable results

Slide 38

Slide 38 text

Thanks! Daniel Kahnemann: Thinking Fast and Slow xdebug, PHP-SPX github: sandstorm/drydock github: sandstorm/ebpf-tracer

Slide 39

Slide 39 text

No content