performance tips for symfony2 & php

Post on 03-Jul-2015

341 Views

Category:

Engineering

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Performance tips for Symfony2 & PHP

TRANSCRIPT

PERFORMANCE TIPS

FOR SYMFONY2 & PHP

Minsk PHP User Group Meetup #10

Intro

Max Romanovsky

37 Slides

Questions after presentation

Out of scope: HW & OS tuning, VM vs HW

servers

“Premature optimization is the root of all evil”

Knuth’s quote is missing

No cats, boobs or other images in slides

2

Quiz3

What to optimize?

Architecture

Code

Services

Agenda

Overview

Measure

Services

Architecture

Code

Symfony2 tips

4

Overview5

How to start?

Forget about microoptimizations for now

Курочка по зернышку – весь двор в говне

Make it scalable

What is cheaper? To scale or to optimize?

6

Tune

Tune services

Tune architecture

Consider tuning code

7

Quiz8

What was the sloooooowest?

DB queries

Network communication

PHP configuration

VM/HW server

Stupid code

What could be slow9

Network communication (with client, inside

LAN)

VM/HW server

OS & runtime itself

Communication with services

Code (finally!)

Measure10

Stop! Measure11

Measure before

Measure during

Measure after

Measure periodically

measure

Measure

MEASURE!!1

Quiz12

What do you use?

Symfony Profiler

symfony/stopwatch

Из говна и палок

Xhprof

Xdebug

Zend Profiler

Tools13

Xhprof / uprofiler

Xdebug

Framework tools

= overhead & irrelevant results

Question14

Can we compare xhprof & xdebug results?

Are they relevant?

Overhead & irrelevant results?15

Runtime (i.e. code execution) is slower with

profiler enabled

Communication with services is not slower

Mess in results

You are analyzing DIFFERENT results

Use lightweight profiler16

XHProf

XHgui (saves runs to RDBMS)

Uprofiler (fork?)

https://github.com/FriendsOfPHP/uprofiler

Measure performance in real

world17

Turn on profiler periodically

For 1% of requests

For 1 app server

Record & replay user activity

Use Jmeter to record scenarios

Use good old ab, siege, http_load

Tune18

Tune 1 factor at once

Store configuration & measuring results in

VCS

Measure after tuning

Services19

Why?20

Receive profit without changing a single line of

code

Question21

Do you know what is an Opcache?

Do you use it?

PHP22

Don’t use the latest PHP version, please!

Use PHP-FPM (or even HHVM?)

Opcache or APC

APCu

Compile stable libraries as PHP extensions

Twig

Redis

AMQP

Composer23

composer install --optimize-autoloader

Architecture24

Architecture

Make it scalable. Period.

Use PAAS services

CDN

File storage

Choose efficient protocols & frameworks

Apache Thrift

Google Protocol Buffers

25

Cache26

Raw data

Computed data

View layer

Cache27

Raw data = DB/Data Source

MySQL query cache

HTTP API reverse proxy cache

Cache28

Computed data = Key-value

Persistent?

Consistent?

Check your DB features

Cache29

View layer = HTTP cache

Nginx

Varnish

Code30

Why not to optimize31

Improve architecture

Man, it’s PHP! It is designed to be SLOOOOW

Optimize code for people, not for machines

Курочка по зернышку?..

Well… OK. But profile

What to optimize. Boooring32

DB

Move calculations to DB

Move aggregation to DB

MOVE LIMIT TO DB!!1

Move calculations outside the loop

Don’t concatenate string insanely

Don’t pass huge arrays by value to functions

Don’t use arrays anyway

Symfony2 tips33

As seen on TV34

http://symfony.com/doc/current/book/performa

nce.html

Use a Byte Code Cache

Composer's Class Map

Caching the Autoloader with APC

Use Bootstrap Files

Tipzzz35

Services

Lazy with ocramius/proxy-manager

Controllers

Console commands

Move app/cache to tmpfs

Twig C extension

Don’t use router:dump. It’s deprecated

https://github.com/symfony/symfony/issues/9652

Don’t use Symfony Profiler for profiling

More?36

http://symfony.com/blog/push-it-to-the-limits-

symfony2-for-high-performance-needs

https://www.youtube.com/watch?v=b8ewqVGu

77w

https://profiler.sensiolabs.com/ - still waiting for

invite

The End37

max.romanovsky@gmail.com

http://maxromanovsky.com

top related