Slide 1

Slide 1 text

How to spot bottleneck in web applications

Slide 2

Slide 2 text

“Hello World”

Slide 3

Slide 3 text

Krzysztof “skowron-line” Skaradziński

Slide 4

Slide 4 text

#1 Don't think about optimization during development, focus on requirements

Slide 5

Slide 5 text

greenfield vs brownfield

Slide 6

Slide 6 text

Greenfield Development happens when you start a brand new project, as in, clean slate development. No legacy code lying around, no old development to maintain. You’re starting afresh, from scratch, from a blank slate, with no restrictions on what you’re doing (other than business rules of course).

Slide 7

Slide 7 text

Brownfield Development happens when business decide to develop/improve upon an existing application infrastructure. As an upgrade is implemented into an existing solution, the development is said to be Brownfield.

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Web Debug Toolbar

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Performance

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

blackfire.io

Slide 16

Slide 16 text

X-Blackfire-Query BLACKFIRE_QUERY

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Network activity includes calls to databases like MySQL, PostgreSQL, 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.

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

Graph

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

References

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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...5e719 fd0-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 -

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Recommendations

Slide 40

Slide 40 text

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...5e719 fd0-5839-4495-866a-142181a0f4a1/graph 1 recommendation https://blackfire.io/profiles/5e719fd0-5839-4495-866a-142181a0f4a1/graph?settin gs%5BtabPane%5D=recommendations Wall Time 207ms -26ms -14.5% CPU Time 176ms -52ms -14.5% ...

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Assertions

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

https://blackfire.io/docs/validator

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

Test Scenarios

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

Only for HTTP requests, not CLI command

Slide 51

Slide 51 text

Server / Database / Custom logs

Slide 52

Slide 52 text

long_query_time=1

Slide 53

Slide 53 text

# Time: 100224 19:50:45 # User@Host: root[root] @ localhost [127.0.0.1] # Query_time: 89.843750 Lock_time: 0.000000 Rows_sent: 6256088 Rows_examined: 3 use we; SET timestamp=1267037445; select * from places,employees,departments,votes;

Slide 54

Slide 54 text

Code review

Slide 55

Slide 55 text

{{ app.user }} {{ app.request.query.get('page') }} vs {% set user = app.user %} {% set page = app.request.query.get('page') %}

Slide 56

Slide 56 text

$marquise=Marquise::initialize(); // heavy logic if ($request->get('_route') !== 'homepage') { return; } $marquise->show();

Slide 57

Slide 57 text

{% for project in projects %}

{{ project.name }}

{% if is_granted('SUPER_ADMIN') %} {{ 'remove' | trans({}, 'top') }} {% endif %} {% endfor %}

Slide 58

Slide 58 text

{% for project in projects %}

{{ project.name }}

{% if is_granted('SUPER_ADMIN') %} {{ 'remove' | trans({}, 'top') }} {% endif %} {% endfor %}

Slide 59

Slide 59 text

#1 Don't think about optimization during development, focus on requirements

Slide 60

Slide 60 text

That’s all

Slide 61

Slide 61 text

Thanks