SlideShare a Scribd company logo
SCALING
WITH SYMFONY

+

=

PHP UK CONFERENCE 2014
HELLO PHPUK!
•

Ricard Clau, born and grown up in Barcelona, Spain

•

Software engineer at Hailo London

•

Symfony2 lover and PHP believer

•

Open-source contributor, sometimes I give talks

•

Twitter @ricardclau / Gmail ricard.clau@gmail.com
WHY THIS TALK?
•

Lots of PHP haters these days. I just don´t get it.

•

Some misconceptions about full-stack PHP frameworks

•

PHP is absolutely fine for most of your applications

•

But at some point you may need to replace some bits

•

DragonCity - Social game - 7.5M DAU - Symfony
AGENDA
•

Performance and scalability

•

Profiling and optimization

•

Storage: SQL vs NoSQL

•

Symfony2 is fast enough! Seriously!

•

Some war stories!

•

Almost everything applies to all PHP projects
Millions of
Users
Worldwide
24x7x365

CONCEPTS
Scalability, Availability, Load Balancing, Sharding
SCALABILITY
Which model would you choose?
AVAILABLE 24X7X365
We need to recover fast from any failure
LOAD BALANCING
It allows you to make changes without stopping your app
SHARDING
Luckily, you will get to a point when you need to do it...
And it can hurt if you have never considered it!
DON´T IF NOT NEEDED
•

Avoid premature optimizations

•

Microoptimizations are completely useless

•

Focus on impacting things

•

Incremental improvements

•

If the business is not working, it will be useless
BUT ACTIVELY PREVENT RISKS
•

Monitor servers: Ram, CPUs, Disk, network, idle
processes...

•

Try to engage stakeholders

•

When something surpasses half capacity, start
creating a B plan

•

Death of success is terrible
HANDS ON!
Where do we start from?
LOVE YOUR FRONTEND
Reduce # of requests and their size
SOME QUICK ADVICES
•

Fastest request -> No actual request

•

Icons in base64 inside your CSS

•

Minify CSS and JS, image size (jpegoptim, pngcrush, ...)

•

Use HTTP headers to cache at several layers

•

Network latency matters a lot

•

User experience takes benefit from all of these
SCALING PHP
Facebook, Wikipedia, Yahoo, Wordpress, Etsy, Zynga, YouPorn, Hailo,
Softonic, Emagister, Privalia, SocialPoint, Tuenti, ...
IS SCALING ACTUALLY EASY?
•

PHP bootstraps on every Request, so scaling is as “easy” as adding machines
behind a Load Balancer

•

But it makes it much slower than many other languages

•

Some things are shared among requests (sessions, storage, ...) but frameworks like
Symfony make it easier

•

PHP has been proof-tested in several BIG projects

•

Most of the times, problems are caused by the DB
LOOK BEYOND LAMP
•

Light-weight HTTP servers / CDNs for assets

•

Introduce reverse proxy cache like Varnish to cache pages (or ESI blocks)

•

Cache all the things (APC, Memcached, Redis, ...). 10 seconds cache -> Only 6
hits per minute!

•

RDBMS can deal with A LOT of data. But some problems are much better
solved with NoSQL databases

•

Sometimes other languages are more suitable for our problem
PHP PERFORMANCE
Opcode caches, composer, HHVM, quick wins
Upgrading from PHP5.3 will boost ~20-40%
APC: OUR OLD BESTIE
•

If you have ever worried about performance... you know it!

•

apc.stat -> Off (Apache reload to see changes)

•

apc.serializer -> igbinary (compact_strings -> Off)

•

apc.shm_size -> Check if 32Mb is enough

•

apc.write_lock -> Avoids cold cache issues

•

Check http://www.php.net/manual/en/apc.configuration.php
APC STATUS
http://svn.php.net/viewvc/pecl/apc/trunk/apc.php?view=markup
ZEND OPCACHE
•

Included in PHP5.5 standard distribution (valid with 5.2) will avoid weird
random issues like PHP5.4+APC

•

Better performance than APC in all tests

•

README https://github.com/zendtech/ZendOptimizerPlus

•

APC Userland Cache + Upload Hooks now live in APCU
(https://github.com/krakjoe/apcu)

•

Lots of companies are already using it!
OPCACHE STATUS
1 full-stack file, Rasmus style :)
(https://github.com/rlerdorf/opcache-status)
COMPOSER AUTOLOAD
•

You all already use Composer, right?

•

Default PSR-0 implementation is slow because we access
the FileSystem a lot

•

composer.phar install --optimize-autoloader (-o)
generates ClassMap

•

Same performance apc.stat = Off than
ApcUniversalClassLoader and less keys stored in APC
APC VS ZEND OPCACHE

http://www.ricardclau.com/2013/03/apc-vs-zend-optimizer-benchmarks-withsymfony2/
APC VS ZEND OPCACHE

http://www.ricardclau.com/2013/03/apc-vs-zend-optimizer-benchmarks-withsymfony2/
HHVM: THE FUTURE ENGINE?
•

Impressive progress in HHVM these past months

•

Most frameworks and libraries ~100% compatibility

•

Fewer memory, interesting speed improvements

•

We might finally have a language specification for PHP!

•

Specific HHVM features? -> Dangerous!

•

It will still not be comparable to compiled languages
FINE TUNING SYMFONY2
•

Disable unused bundles

•

SwiftMailer is quite slow, delegate to queue processes

•

If you can, use SubRequests with ESI and Varnish

•

Also check Twig C extension

•

You can implement a Cache Warmer for special needs

•

If using Apache, try app/console router:dump-apache
PROFILING
Diagnosing bottlenecks
PROFILING TOOLS
•

How often do you profile your code?

•

xDebug (Derick Rethans) and XHProf (Facebook)

•

Very convenient to install them in live servers and
activate to grab real data

•

Many things can also be discovered locally

•

Some tragedies only happen with live traffic
XHPROF (DEV VS PROD)
https://github.com/jonaswouters/XhprofBundle
HELLO WORLD
PHP and its frameworks...
Benchmarks comparing completely different things...
¿FRAMEWORKS == SLOW?
•

Some people think that writing their own
framework from scratch is a good idea

•

Also, that big frameworks use a lot of memory. (ZF1
and Symfony2 work with memory_limit 32M)

•

If this is your problem, PHP is not the solution

•

Don´t trust Hello World Performance Tests!

•

Nobody is better than a big community
TECHEMPOWER BENCHMARK
•

Symfony2 appears at the bottom

•

Comparison with light-weight frameworks is unfair.
Some incoherences (frameworks PHP >> PHP)

•

PHP will never be faster than a compiled language

•

In real apps, caching and DB optimizations equal things

•

Symfony2 roadmap improving performance
STORAGE
Use the right tool for the job. Silver bullets do not exist
RELATIONAL DBS
•

Mature technologies, good performance

•

Transactions: Atomicity, Consistency, Isolation, Durability

•

Foreign Keys, Joins, complex reporting queries

•

Millions of records without issues

•

We can use a NOSQLs key-value approach using
BLOB fields with serialized objects
NOSQL SOLUTIONS
•

Solutions to some concrete problems

•

CAP theorem (Consistency, Availability, Partition tolerance).
You can only get 2 of them... theoretically

•

Inmaturity in some of them. Complex to scale.

•

¿Big Data? 100M of records is NOT BIG DATA.

•

Redis, Cassandra, Riak and Solr work really well
QUEUE SYSTEMS
Read the docs, they are all completely different!
REAL-TIME DATA?
•

Try to delegate as much as possible to batch processes

•

Sending mails, external API requests, image
resizing, non-critical stats, ...

•

99% of stats don´t need to be real-time

•

60 seconds delay is mostly real-time!

•

Batch processes can be coded in different languages!
PHP NEEDS FRIENDS
Sometimes it is just not the best tool for our needs
PHP BAD SCENARIOS
•

24x7 running CLI daemon apps

•

Heavy math calculations, massive data processing,
programming contests

•

High concurrency apps with non-cachable requests

•

Threading, Forking, concurrent programming...

•

Writing DSLs
LOOK BEYOND PHP
•

JavaScript will be the king in the client side

•

In the server, Erlang and Go are growing adopters. And time will say about
Node.JS

•

Compiled languages like Go, C, C++ or Java will always be used in our stack.

•

JVM languages like Scala and Clojure are sexy now!

•

Learning other languages makes you a better engineer!
SYMFONY2
It is fast enough for most of what you want to do
WHY SYMFONY2?
•

Symfony2 is NOT the fastest “Hello world” framework...
but it is fast enough for most APIs and web applications

•

Big-community frameworks allow you to test any
technology in less than 5 minutes

•

A custom framework has usually higher costs and risks

•

LTS releases roadmap, stability, big projects are using it

•

Mature community, # of bundles
SOCIAL VIDEOGAME
https://apps.facebook.com/dragoncity/
(~7.5M DAU Facebook, iOS & Android Game)
DRAGONCITY: NUMBERS
•

~7.5 million daily users

•

~300 millions of registered users

•

Hundreds of millions of records for analytics generated daily

•

MySQL (32x2 + Analytics), Redis (~30), Cassandra (3)

•

HTTP requests are your progress -> No cacheable

•

Yes, most of the code is Symfony2! :)
POWERED BY SYMFONY2
@adanlobato showing happiness and pride!
6 DIGITS IN ANALYTICS
Yeah, still Symfony2! o/
WRAP-UP
•

PHP and Symfony2 work for most projects

•

Clever caching strategy is helpful

•

Profiling can make performance improve

•

The storage is almost always the bottleneck

•

Proper architecture design is crucial

•

PHP is not the best solution to some problems
QUESTIONS?
•

Twitter: @ricardclau

•

E-mail: ricard.clau@gmail.com

•

Github: https://github.com/ricardclau

•

Blog about PHP and Symfony2: http://www.ricardclau.com

•

Please, rate this talk at https://joind.in/talk/view/10697

More Related Content

What's hot (19)

PDF
Innovating faster with SBT, Continuous Delivery, and LXC
kscaldef
 
ODP
Real-world Experiences in Scala
Amir Karimi
 
PDF
What we talk about when we talk about DevOps
Ricard Clau
 
PDF
Perl-Critic
Jonas Brømsø
 
PDF
Beyond Apache: Faster Web Servers
webhostingguy
 
PDF
The Wix Microservice Stack
Tomer Gabel
 
PDF
Streaming 101: Hello World
Josh Fischer
 
PDF
MariaDB - The Future of MySQL?
Bokowsky + Laymann GmbH
 
PDF
Apcera Case Study: The selection of the Go language
Derek Collison
 
PDF
Travel with your mock server
Jorge Ortiz
 
PPTX
Compression talk
Ilya Ganelin
 
PDF
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Tim Bunce
 
PPTX
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Panagiotis Kanavos
 
PDF
Ruby in office time reboot
Kentaro Goto
 
PDF
Building real time applications with Symfony2
Antonio Peric-Mazar
 
PDF
Gophers Riding Elephants: Writing PostgreSQL tools in Go
AJ Bahnken
 
PDF
Mini-Training: Redis
Betclic Everest Group Tech Team
 
PPTX
Scala in the Wild
Tomer Gabel
 
PPTX
Ansible Best Practices - July 30
tylerturk
 
Innovating faster with SBT, Continuous Delivery, and LXC
kscaldef
 
Real-world Experiences in Scala
Amir Karimi
 
What we talk about when we talk about DevOps
Ricard Clau
 
Perl-Critic
Jonas Brømsø
 
Beyond Apache: Faster Web Servers
webhostingguy
 
The Wix Microservice Stack
Tomer Gabel
 
Streaming 101: Hello World
Josh Fischer
 
MariaDB - The Future of MySQL?
Bokowsky + Laymann GmbH
 
Apcera Case Study: The selection of the Go language
Derek Collison
 
Travel with your mock server
Jorge Ortiz
 
Compression talk
Ilya Ganelin
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Tim Bunce
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Panagiotis Kanavos
 
Ruby in office time reboot
Kentaro Goto
 
Building real time applications with Symfony2
Antonio Peric-Mazar
 
Gophers Riding Elephants: Writing PostgreSQL tools in Go
AJ Bahnken
 
Mini-Training: Redis
Betclic Everest Group Tech Team
 
Scala in the Wild
Tomer Gabel
 
Ansible Best Practices - July 30
tylerturk
 

Viewers also liked (17)

PDF
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Ville Mattila
 
PDF
MidwestPHP Symfony2 Internals
Raul Fraile
 
PDF
Starting with Symfony2
Kevin Bond
 
PDF
Principles of PHP Package Design (for AmsterdamPHP)
Matthias Noback
 
PDF
A Practical Introduction to Symfony2
Kris Wallsmith
 
PDF
Interoperability and Portability for Cloud Computing: A Guide
Cloud Standards Customer Council
 
PDF
Rationally boost your symfony2 application with caching tips and monitoring
Giulio De Donato
 
PDF
Extensible Data Modeling
Karwin Software Solutions LLC
 
PDF
Symfony in microservice architecture
Daniele D'Angeli
 
PDF
Effective Doctrine2: Performance Tips for Symfony2 Developers
Marcin Chwedziak
 
PDF
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Innomatic Platform
 
PDF
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Ryan Weaver
 
PPT
Symfony2 and AngularJS
Antonio Peric-Mazar
 
PPTX
Code Review
Frank Sons
 
PDF
Scalability, Availability & Stability Patterns
Jonas Bonér
 
PDF
Symfony2 and MongoDB
Pablo Godel
 
PDF
Creating Mobile Apps With PHP & Symfony2
Pablo Godel
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Ville Mattila
 
MidwestPHP Symfony2 Internals
Raul Fraile
 
Starting with Symfony2
Kevin Bond
 
Principles of PHP Package Design (for AmsterdamPHP)
Matthias Noback
 
A Practical Introduction to Symfony2
Kris Wallsmith
 
Interoperability and Portability for Cloud Computing: A Guide
Cloud Standards Customer Council
 
Rationally boost your symfony2 application with caching tips and monitoring
Giulio De Donato
 
Extensible Data Modeling
Karwin Software Solutions LLC
 
Symfony in microservice architecture
Daniele D'Angeli
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Marcin Chwedziak
 
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Innomatic Platform
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Ryan Weaver
 
Symfony2 and AngularJS
Antonio Peric-Mazar
 
Code Review
Frank Sons
 
Scalability, Availability & Stability Patterns
Jonas Bonér
 
Symfony2 and MongoDB
Pablo Godel
 
Creating Mobile Apps With PHP & Symfony2
Pablo Godel
 
Ad

Similar to Scaling with Symfony - PHP UK (20)

PDF
2013 - Dustin whittle - Escalando PHP en la vida real
PHP Conference Argentina
 
PDF
Professional PHP: an open-source alternative for enterprise development [Kort...
Combell NV
 
ODP
Modern Application Stacks
chartjes
 
PDF
Framework and Application Benchmarking
Paul Jones
 
PDF
Php go vrooom!
Elizabeth Smith
 
PDF
flickr's architecture & php
coolpics
 
PDF
Steve Corona: Scaling LAMP doesn't have to suck
WebExpo
 
PDF
Symfony 2.0 on PHP 5.3
Fabien Potencier
 
PDF
Dutch php conference_2010_opm
isnull
 
PPTX
Northeast PHP - High Performance PHP
Jonathan Klein
 
PDF
InterConPHP 2014 - Scaling PHP
Lucas Arruda
 
PDF
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
Blend Interactive
 
PDF
Top 7 Skills PHP Developer Must Have
IndumathySK
 
PDF
Flickr Architecture Presentation
web25
 
PDF
Symfony Performance
Paul Thrasher
 
PPT
FOWA Scaling The Lamp Stack Workshop
dlieberman
 
PDF
Integrating PHP With System-i using Web Services
Ivo Jansch
 
PDF
Qcon
adityaagarwal
 
PDF
PHP Web Development
Sanjida Afrin
 
PDF
PHP Web Development.pdf
Sonia Simi
 
2013 - Dustin whittle - Escalando PHP en la vida real
PHP Conference Argentina
 
Professional PHP: an open-source alternative for enterprise development [Kort...
Combell NV
 
Modern Application Stacks
chartjes
 
Framework and Application Benchmarking
Paul Jones
 
Php go vrooom!
Elizabeth Smith
 
flickr's architecture & php
coolpics
 
Steve Corona: Scaling LAMP doesn't have to suck
WebExpo
 
Symfony 2.0 on PHP 5.3
Fabien Potencier
 
Dutch php conference_2010_opm
isnull
 
Northeast PHP - High Performance PHP
Jonathan Klein
 
InterConPHP 2014 - Scaling PHP
Lucas Arruda
 
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
Blend Interactive
 
Top 7 Skills PHP Developer Must Have
IndumathySK
 
Flickr Architecture Presentation
web25
 
Symfony Performance
Paul Thrasher
 
FOWA Scaling The Lamp Stack Workshop
dlieberman
 
Integrating PHP With System-i using Web Services
Ivo Jansch
 
PHP Web Development
Sanjida Afrin
 
PHP Web Development.pdf
Sonia Simi
 
Ad

More from Ricard Clau (10)

PDF
Essential Info for the Devops Barcelona 2024 Conference
Ricard Clau
 
PDF
devopsbcn23.pdf
Ricard Clau
 
PDF
devopsbcn22.pdf
Ricard Clau
 
PDF
NoEresTanEspecial-PulpoCon22.pdf
Ricard Clau
 
PDF
DevOps & Infraestructura como código: Promesas Rotas
Ricard Clau
 
PDF
DevOps Barcelona Conference 2018 - Intro
Ricard Clau
 
PDF
Redis everywhere - PHP London
Ricard Clau
 
PDF
Escalabilidad y alto rendimiento con Symfony2
Ricard Clau
 
PDF
Betabeers Barcelona - Buenas prácticas
Ricard Clau
 
PDF
Desymfony - Servicios
Ricard Clau
 
Essential Info for the Devops Barcelona 2024 Conference
Ricard Clau
 
devopsbcn23.pdf
Ricard Clau
 
devopsbcn22.pdf
Ricard Clau
 
NoEresTanEspecial-PulpoCon22.pdf
Ricard Clau
 
DevOps & Infraestructura como código: Promesas Rotas
Ricard Clau
 
DevOps Barcelona Conference 2018 - Intro
Ricard Clau
 
Redis everywhere - PHP London
Ricard Clau
 
Escalabilidad y alto rendimiento con Symfony2
Ricard Clau
 
Betabeers Barcelona - Buenas prácticas
Ricard Clau
 
Desymfony - Servicios
Ricard Clau
 

Recently uploaded (20)

PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Digital Circuits, important subject in CS
contactparinay1
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 

Scaling with Symfony - PHP UK

  • 2. HELLO PHPUK! • Ricard Clau, born and grown up in Barcelona, Spain • Software engineer at Hailo London • Symfony2 lover and PHP believer • Open-source contributor, sometimes I give talks • Twitter @ricardclau / Gmail [email protected]
  • 3. WHY THIS TALK? • Lots of PHP haters these days. I just don´t get it. • Some misconceptions about full-stack PHP frameworks • PHP is absolutely fine for most of your applications • But at some point you may need to replace some bits • DragonCity - Social game - 7.5M DAU - Symfony
  • 4. AGENDA • Performance and scalability • Profiling and optimization • Storage: SQL vs NoSQL • Symfony2 is fast enough! Seriously! • Some war stories! • Almost everything applies to all PHP projects
  • 7. AVAILABLE 24X7X365 We need to recover fast from any failure
  • 8. LOAD BALANCING It allows you to make changes without stopping your app
  • 9. SHARDING Luckily, you will get to a point when you need to do it... And it can hurt if you have never considered it!
  • 10. DON´T IF NOT NEEDED • Avoid premature optimizations • Microoptimizations are completely useless • Focus on impacting things • Incremental improvements • If the business is not working, it will be useless
  • 11. BUT ACTIVELY PREVENT RISKS • Monitor servers: Ram, CPUs, Disk, network, idle processes... • Try to engage stakeholders • When something surpasses half capacity, start creating a B plan • Death of success is terrible
  • 12. HANDS ON! Where do we start from?
  • 13. LOVE YOUR FRONTEND Reduce # of requests and their size
  • 14. SOME QUICK ADVICES • Fastest request -> No actual request • Icons in base64 inside your CSS • Minify CSS and JS, image size (jpegoptim, pngcrush, ...) • Use HTTP headers to cache at several layers • Network latency matters a lot • User experience takes benefit from all of these
  • 15. SCALING PHP Facebook, Wikipedia, Yahoo, Wordpress, Etsy, Zynga, YouPorn, Hailo, Softonic, Emagister, Privalia, SocialPoint, Tuenti, ...
  • 16. IS SCALING ACTUALLY EASY? • PHP bootstraps on every Request, so scaling is as “easy” as adding machines behind a Load Balancer • But it makes it much slower than many other languages • Some things are shared among requests (sessions, storage, ...) but frameworks like Symfony make it easier • PHP has been proof-tested in several BIG projects • Most of the times, problems are caused by the DB
  • 17. LOOK BEYOND LAMP • Light-weight HTTP servers / CDNs for assets • Introduce reverse proxy cache like Varnish to cache pages (or ESI blocks) • Cache all the things (APC, Memcached, Redis, ...). 10 seconds cache -> Only 6 hits per minute! • RDBMS can deal with A LOT of data. But some problems are much better solved with NoSQL databases • Sometimes other languages are more suitable for our problem
  • 18. PHP PERFORMANCE Opcode caches, composer, HHVM, quick wins Upgrading from PHP5.3 will boost ~20-40%
  • 19. APC: OUR OLD BESTIE • If you have ever worried about performance... you know it! • apc.stat -> Off (Apache reload to see changes) • apc.serializer -> igbinary (compact_strings -> Off) • apc.shm_size -> Check if 32Mb is enough • apc.write_lock -> Avoids cold cache issues • Check http://www.php.net/manual/en/apc.configuration.php
  • 21. ZEND OPCACHE • Included in PHP5.5 standard distribution (valid with 5.2) will avoid weird random issues like PHP5.4+APC • Better performance than APC in all tests • README https://github.com/zendtech/ZendOptimizerPlus • APC Userland Cache + Upload Hooks now live in APCU (https://github.com/krakjoe/apcu) • Lots of companies are already using it!
  • 22. OPCACHE STATUS 1 full-stack file, Rasmus style :) (https://github.com/rlerdorf/opcache-status)
  • 23. COMPOSER AUTOLOAD • You all already use Composer, right? • Default PSR-0 implementation is slow because we access the FileSystem a lot • composer.phar install --optimize-autoloader (-o) generates ClassMap • Same performance apc.stat = Off than ApcUniversalClassLoader and less keys stored in APC
  • 24. APC VS ZEND OPCACHE http://www.ricardclau.com/2013/03/apc-vs-zend-optimizer-benchmarks-withsymfony2/
  • 25. APC VS ZEND OPCACHE http://www.ricardclau.com/2013/03/apc-vs-zend-optimizer-benchmarks-withsymfony2/
  • 26. HHVM: THE FUTURE ENGINE? • Impressive progress in HHVM these past months • Most frameworks and libraries ~100% compatibility • Fewer memory, interesting speed improvements • We might finally have a language specification for PHP! • Specific HHVM features? -> Dangerous! • It will still not be comparable to compiled languages
  • 27. FINE TUNING SYMFONY2 • Disable unused bundles • SwiftMailer is quite slow, delegate to queue processes • If you can, use SubRequests with ESI and Varnish • Also check Twig C extension • You can implement a Cache Warmer for special needs • If using Apache, try app/console router:dump-apache
  • 29. PROFILING TOOLS • How often do you profile your code? • xDebug (Derick Rethans) and XHProf (Facebook) • Very convenient to install them in live servers and activate to grab real data • Many things can also be discovered locally • Some tragedies only happen with live traffic
  • 30. XHPROF (DEV VS PROD) https://github.com/jonaswouters/XhprofBundle
  • 31. HELLO WORLD PHP and its frameworks... Benchmarks comparing completely different things...
  • 32. ¿FRAMEWORKS == SLOW? • Some people think that writing their own framework from scratch is a good idea • Also, that big frameworks use a lot of memory. (ZF1 and Symfony2 work with memory_limit 32M) • If this is your problem, PHP is not the solution • Don´t trust Hello World Performance Tests! • Nobody is better than a big community
  • 33. TECHEMPOWER BENCHMARK • Symfony2 appears at the bottom • Comparison with light-weight frameworks is unfair. Some incoherences (frameworks PHP >> PHP) • PHP will never be faster than a compiled language • In real apps, caching and DB optimizations equal things • Symfony2 roadmap improving performance
  • 34. STORAGE Use the right tool for the job. Silver bullets do not exist
  • 35. RELATIONAL DBS • Mature technologies, good performance • Transactions: Atomicity, Consistency, Isolation, Durability • Foreign Keys, Joins, complex reporting queries • Millions of records without issues • We can use a NOSQLs key-value approach using BLOB fields with serialized objects
  • 36. NOSQL SOLUTIONS • Solutions to some concrete problems • CAP theorem (Consistency, Availability, Partition tolerance). You can only get 2 of them... theoretically • Inmaturity in some of them. Complex to scale. • ¿Big Data? 100M of records is NOT BIG DATA. • Redis, Cassandra, Riak and Solr work really well
  • 37. QUEUE SYSTEMS Read the docs, they are all completely different!
  • 38. REAL-TIME DATA? • Try to delegate as much as possible to batch processes • Sending mails, external API requests, image resizing, non-critical stats, ... • 99% of stats don´t need to be real-time • 60 seconds delay is mostly real-time! • Batch processes can be coded in different languages!
  • 39. PHP NEEDS FRIENDS Sometimes it is just not the best tool for our needs
  • 40. PHP BAD SCENARIOS • 24x7 running CLI daemon apps • Heavy math calculations, massive data processing, programming contests • High concurrency apps with non-cachable requests • Threading, Forking, concurrent programming... • Writing DSLs
  • 41. LOOK BEYOND PHP • JavaScript will be the king in the client side • In the server, Erlang and Go are growing adopters. And time will say about Node.JS • Compiled languages like Go, C, C++ or Java will always be used in our stack. • JVM languages like Scala and Clojure are sexy now! • Learning other languages makes you a better engineer!
  • 42. SYMFONY2 It is fast enough for most of what you want to do
  • 43. WHY SYMFONY2? • Symfony2 is NOT the fastest “Hello world” framework... but it is fast enough for most APIs and web applications • Big-community frameworks allow you to test any technology in less than 5 minutes • A custom framework has usually higher costs and risks • LTS releases roadmap, stability, big projects are using it • Mature community, # of bundles
  • 45. DRAGONCITY: NUMBERS • ~7.5 million daily users • ~300 millions of registered users • Hundreds of millions of records for analytics generated daily • MySQL (32x2 + Analytics), Redis (~30), Cassandra (3) • HTTP requests are your progress -> No cacheable • Yes, most of the code is Symfony2! :)
  • 46. POWERED BY SYMFONY2 @adanlobato showing happiness and pride!
  • 47. 6 DIGITS IN ANALYTICS Yeah, still Symfony2! o/
  • 48. WRAP-UP • PHP and Symfony2 work for most projects • Clever caching strategy is helpful • Profiling can make performance improve • The storage is almost always the bottleneck • Proper architecture design is crucial • PHP is not the best solution to some problems
  • 49. QUESTIONS? • Twitter: @ricardclau • E-mail: [email protected] • Github: https://github.com/ricardclau • Blog about PHP and Symfony2: http://www.ricardclau.com • Please, rate this talk at https://joind.in/talk/view/10697