SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Scaling PHP
… in an “Enterprise” environment
(what’s that?)
Sarel van der Walt
- I’m from the Internet … a.k.a. afrihost.com
facebook.com/sarelvdwalt
twitter.com/sfvdwalt
– Dustin Whittle
“Scalability is about the entire architecture,
not some minor code optimisations”
Is PHP really the problem?
• Have you looked at your DB?
• Have you looked at your network?
• Have you looked at your assets?
That’s but to name a few!
versus…
Vertical = expensive
Horizontal = inexpensive,
but complex
Why Afrihost cared (suddenly!)
From this… …to this!
Our architecture, more/less (actually very high level)
haproxy haproxy
Internet
CZ4 CZ5 CZ6 CZ7 CZ8 CZ...
MySQL Master
MySQL Slave 0 MySQL Slave 24h
LogStash
$_SESSION
• File system is bad :: you can only use ONE server!
• Database (MySQL, Postgres) is ok :: vertical scaling needed
$_SESSION
• IN-Memory Cache is better - think memcached / redis
• You could also put it in mongodb, or casandra…

…session data nicely lend itself to serialisation
• Browser based is the BEST - but be careful of the 4k limit of older
browsers (and security)
IN-Memory Cache
• File-System Cache - old, but trusted - vertical
• memcached is better :: multiple servers through sharding
IN-Memory Cache [continued]
• redis is awesome (but more complicated) :: also has sharding

/* redis can do so much more */
… more redis (I love redis!)
#atomic
#fancy_replacing_your_auto_increments_with_this??
… more redis (I love redis!)
… more redis (I love redis!)
#wondering_about_message_queues
… more redis (I love redis!)
Background Work (non-blocking)
• 3rd Party Calls (tweeting, api-calls, emailing, etc)
• Expensive DB (or any other) work - especially unimportant ones
• Q: What’s “expensive” ?? 

A: 150+ milliseconds
• Ask yourself: Is it important for the next request?!
• Q: So what do I do?

A: Queue it!!

Q: How?

A: Why with REDIS, off course?! :)

… or something else… like MySQL… or not?
During billing run (25th to 2nd) Afrihost runs…
550 000 background CLI's - broken up over 253 scripts
Some of these actions, are called...
75k times
during a month, consuming...
9.7 days of server time !!!
> composer.phar install chrisboulton/php-resque
40million records added in 42 minutes
... that's 954k in a minute...
... that's 15906 in a second!! (MySQL took 34 seconds to do this)
... that's 35 seconds (rounded up, lol) to insert the entire billing-run to Afrihost Job Queue!!
MySQL didn’t stand a chance!!
(1177 seconds = 19.6 minutes!!)
HTTP Caching
• Are you caching assets on the browsers?
• Should they really download new CSS that often?
• How do you cache-bust?
• eTag much? No, it’s not this…
Reverse Proxy
• varnish - varnish-cache.org
• nginx - nginx.org
• haproxy - haproxy.org
• squid - squid-cache.org
• PS: Most Frameworks has reverse proxy built in!!
Reverse Proxy - haproxy
Database Optimisation
• SQL Slow Query Log - look at it regularly!
• Add slaves for read-scaling!
• Side-line: Disaster Recovery :: Slave 0-seconds + Slave 24-hour!
• Archive!! - makes reading AND writing faster
• Offload!! - perhaps relational DB isn’t the right place for data?
Database Optimisation [continued…]
id username in_bytes out_bytes created_at
123 sarel@afrihost.co.za 1024 2048 2014-07-15 10:01:15
124 dude@afrihost.co.za 971826 12823 2014-07-15 10:01:23
125 geek@afrihost.co.za 17263712 7126373 2014-07-15 10:01:58
126 27838127372@afrihost 12382 9563 2014-07-15 10:02:07
2009-06 :: 3110 records
2009-10 :: 1.7 million records
2010-10 :: 11.9 million records
2011-10 :: 17.4 million records
2012-10 :: 26.6 million records
2013-10 :: 59.6 million records
2014-06 :: 101.1 million records
Database Optimisation [continued…]
• A good strategy that worked for us was ztableYYYYMM!
• You could use any strategy you like, the basics of it:
• Select a bunch of rows
• Insert them into the applicable archive table
• Delete original
• Check out: https://github.com/sarelvdwalt/SFDatabaseArchiveBundle
Framework Optimisation
• Did you just install it and leave? #default_install!
• Go through your configs, switch things on and off for production
• PRO Hint :: Switch debugging off in production
• PRO Hint #2 :: Switch APC / OpCache on INSIDE your Framework (if
it has it) for things like Doctrine / ORM
Doing Essential work Up-Front
• Pre-cache data - hey, Redis / Casandra might be a good place to
put this?? :)
• Warm up your cache during rollouts
• Careful about rollout cache busting!
Move work to the client
• The math is simple: 100k clients times 4 cores = 400
000 CPU cores! Use them … use them ALL!!!!
• Seriously, render calculations belong on the
browser. CSS3, JavaScript
• Do you have an IF statement in your HTML
generation (on server)? Now you have two problems!
• Send data via API, with templates - can utilise CDN
for templates - SOA (Service Oriented
Architecture)
• AngularJS, BackboneJS, check out TodoMVC.com
Learn to debug… LIVE!
• xdebug + webgrind - this will hurt, it’s slow and eats CPU’s (and
HDD space)
• xhprof + xhprofGUI - fast, can run on production (best to keep it off
until you need it)
• Sometimes logging is good enough! Use LogStash for history and
trend… which brings me to monitoring…
Learn to debug… LIVE!
Have you tried:
Don’t lie… you echo’d
in your wetsuit, didn’t
you?
Perhaps better to wrap that…
Monitoring!
LogStash - aggregate logs from multiple servers into central location.
… let’s zoom and see WTF…
Monitoring… looking closer…
… hmmmm… what started around 18:08 on the 25th?
Monitoring… looking closer…
… hmmmm… what started around 18:08 on the 25th?
TURNS OUT FALSE ALARM, BUT STILL…
USEFUL!
Monitoring… DevOps Board…
Monitoring… DevOps Board…
SMS’s (Texts)…
… lots and lots of notifications!
ON-Call Much?
Accessibility
• How close are you to your servers?
• Do you NEED to log in to see logs?
• Catch-22 :: Developers should be able to access anything (or close
to) without having to log into the servers… but don’t deny them
access.
Side-line…
The most junior developer should do the rollouts!
Let’s look at something practical…
the Afrihost order form.
Each click, does:
1. HTTP request (hits apache, hits symfony)
2. Asks the DB for the next products in the category
3. Returns the value, and renders it
Let’s go look at it live: clientzone.afrihost.com/get-connected
Remember this?
Final thoughts…
… but sometimes it’s not so elementary.
Thank you.
Charging beer… 36%
github.com/sarelvdwalt/php-jhb
Php johannesburg   meetup - talk 2014 - scaling php in the enterprise

Contenu connexe

Tendances

Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleJulian Gamble
 
Web assembly lecture @AngularUP 2017
Web assembly lecture @AngularUP 2017Web assembly lecture @AngularUP 2017
Web assembly lecture @AngularUP 2017Ziv Birer
 
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...PHP Conference Argentina
 
企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用
企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用
企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用Akira Kitauchi
 
Front End Development Automation with Grunt
Front End Development Automation with GruntFront End Development Automation with Grunt
Front End Development Automation with GruntLadies Who Code
 
Webpack: What it is, What it does, Whether you need it
Webpack: What it is, What it does, Whether you need itWebpack: What it is, What it does, Whether you need it
Webpack: What it is, What it does, Whether you need itMike Wilcox
 
Woo: Writing a fast web server
Woo: Writing a fast web serverWoo: Writing a fast web server
Woo: Writing a fast web serverfukamachi
 
Sphinx at Craigslist in 2012
Sphinx at Craigslist in 2012Sphinx at Craigslist in 2012
Sphinx at Craigslist in 2012Jeremy Zawodny
 
Improving Game Performance in the Browser
Improving Game Performance in the BrowserImproving Game Performance in the Browser
Improving Game Performance in the BrowserFITC
 
GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...
GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...
GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...DevOpsDays Tel Aviv
 
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)Grant Norwood
 
Shell Tips and Tricks
Shell Tips and TricksShell Tips and Tricks
Shell Tips and TricksMongoDB
 
Build your own RasPiTV with Node.js & Socket.io
Build your own RasPiTV with Node.js & Socket.ioBuild your own RasPiTV with Node.js & Socket.io
Build your own RasPiTV with Node.js & Socket.ioDonald Derek Haddad
 
Building a Dev/Test Cloud with Apache CloudStack
Building a Dev/Test Cloud with Apache CloudStackBuilding a Dev/Test Cloud with Apache CloudStack
Building a Dev/Test Cloud with Apache CloudStackke4qqq
 
Clack: glue for web apps
Clack: glue for web appsClack: glue for web apps
Clack: glue for web appsfukamachi
 

Tendances (20)

Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
 
Web assembly lecture @AngularUP 2017
Web assembly lecture @AngularUP 2017Web assembly lecture @AngularUP 2017
Web assembly lecture @AngularUP 2017
 
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
 
企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用
企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用
企業・業界情報プラットフォームSPEEDAにおけるElasticsearchの活用
 
Front End Development Automation with Grunt
Front End Development Automation with GruntFront End Development Automation with Grunt
Front End Development Automation with Grunt
 
Webpack: What it is, What it does, Whether you need it
Webpack: What it is, What it does, Whether you need itWebpack: What it is, What it does, Whether you need it
Webpack: What it is, What it does, Whether you need it
 
WebWorkersCamp 2010
WebWorkersCamp 2010WebWorkersCamp 2010
WebWorkersCamp 2010
 
web optimizations
web optimizationsweb optimizations
web optimizations
 
Woo: Writing a fast web server
Woo: Writing a fast web serverWoo: Writing a fast web server
Woo: Writing a fast web server
 
Sphinx at Craigslist in 2012
Sphinx at Craigslist in 2012Sphinx at Craigslist in 2012
Sphinx at Craigslist in 2012
 
Improving Game Performance in the Browser
Improving Game Performance in the BrowserImproving Game Performance in the Browser
Improving Game Performance in the Browser
 
GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...
GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...
GRU: Taming a Herd of Wild Servers - Oz Katz, Similarweb - DevOpsDays Tel Avi...
 
Dangerous CSS
Dangerous CSSDangerous CSS
Dangerous CSS
 
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
 
Shell Tips and Tricks
Shell Tips and TricksShell Tips and Tricks
Shell Tips and Tricks
 
Node
NodeNode
Node
 
Go & WebAssembly
Go & WebAssembly Go & WebAssembly
Go & WebAssembly
 
Build your own RasPiTV with Node.js & Socket.io
Build your own RasPiTV with Node.js & Socket.ioBuild your own RasPiTV with Node.js & Socket.io
Build your own RasPiTV with Node.js & Socket.io
 
Building a Dev/Test Cloud with Apache CloudStack
Building a Dev/Test Cloud with Apache CloudStackBuilding a Dev/Test Cloud with Apache CloudStack
Building a Dev/Test Cloud with Apache CloudStack
 
Clack: glue for web apps
Clack: glue for web appsClack: glue for web apps
Clack: glue for web apps
 

Similaire à Php johannesburg meetup - talk 2014 - scaling php in the enterprise

First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNATomas Cervenka
 
Your backend architecture is what matters slideshare
Your backend architecture is what matters slideshareYour backend architecture is what matters slideshare
Your backend architecture is what matters slideshareColin Charles
 
DevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeDevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeMichael Ducy
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdbjixuan1989
 
Systems Monitoring with Prometheus (Devops Ireland April 2015)
Systems Monitoring with Prometheus (Devops Ireland April 2015)Systems Monitoring with Prometheus (Devops Ireland April 2015)
Systems Monitoring with Prometheus (Devops Ireland April 2015)Brian Brazil
 
Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Brian Ritchie
 
Blazing Data With Redis (and LEGOS!)
Blazing Data With Redis (and LEGOS!)Blazing Data With Redis (and LEGOS!)
Blazing Data With Redis (and LEGOS!)Justin Carmony
 
ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)Steve Elliott
 
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_SummaryHiram Fleitas León
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP LondonRicard Clau
 
Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)Oren Eini
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Aaron Blythe
 
Keeping MongoDB Data Safe
Keeping MongoDB Data SafeKeeping MongoDB Data Safe
Keeping MongoDB Data SafeTony Tam
 
Avoiding big data antipatterns
Avoiding big data antipatternsAvoiding big data antipatterns
Avoiding big data antipatternsgrepalex
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at nightMichael Yarichuk
 
Hadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerHadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerIke Ellis
 
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)Nexcess.net LLC
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRicard Clau
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkTomas Doran
 

Similaire à Php johannesburg meetup - talk 2014 - scaling php in the enterprise (20)

First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
 
Your backend architecture is what matters slideshare
Your backend architecture is what matters slideshareYour backend architecture is what matters slideshare
Your backend architecture is what matters slideshare
 
DevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeDevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as Code
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdb
 
Systems Monitoring with Prometheus (Devops Ireland April 2015)
Systems Monitoring with Prometheus (Devops Ireland April 2015)Systems Monitoring with Prometheus (Devops Ireland April 2015)
Systems Monitoring with Prometheus (Devops Ireland April 2015)
 
Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011
 
Blazing Data With Redis (and LEGOS!)
Blazing Data With Redis (and LEGOS!)Blazing Data With Redis (and LEGOS!)
Blazing Data With Redis (and LEGOS!)
 
ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)
 
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
 
RavenDB in the wild
RavenDB in the wildRavenDB in the wild
RavenDB in the wild
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
 
Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013
 
Keeping MongoDB Data Safe
Keeping MongoDB Data SafeKeeping MongoDB Data Safe
Keeping MongoDB Data Safe
 
Avoiding big data antipatterns
Avoiding big data antipatternsAvoiding big data antipatterns
Avoiding big data antipatterns
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at night
 
Hadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerHadoop for the Absolute Beginner
Hadoop for the Absolute Beginner
 
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 

Dernier

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Dernier (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Php johannesburg meetup - talk 2014 - scaling php in the enterprise

  • 1. Scaling PHP … in an “Enterprise” environment (what’s that?) Sarel van der Walt - I’m from the Internet … a.k.a. afrihost.com facebook.com/sarelvdwalt twitter.com/sfvdwalt
  • 2. – Dustin Whittle “Scalability is about the entire architecture, not some minor code optimisations”
  • 3. Is PHP really the problem? • Have you looked at your DB? • Have you looked at your network? • Have you looked at your assets? That’s but to name a few!
  • 4. versus… Vertical = expensive Horizontal = inexpensive, but complex
  • 5. Why Afrihost cared (suddenly!) From this… …to this!
  • 6. Our architecture, more/less (actually very high level) haproxy haproxy Internet CZ4 CZ5 CZ6 CZ7 CZ8 CZ... MySQL Master MySQL Slave 0 MySQL Slave 24h LogStash
  • 7. $_SESSION • File system is bad :: you can only use ONE server! • Database (MySQL, Postgres) is ok :: vertical scaling needed
  • 8. $_SESSION • IN-Memory Cache is better - think memcached / redis • You could also put it in mongodb, or casandra…
 …session data nicely lend itself to serialisation • Browser based is the BEST - but be careful of the 4k limit of older browsers (and security)
  • 9. IN-Memory Cache • File-System Cache - old, but trusted - vertical • memcached is better :: multiple servers through sharding
  • 10. IN-Memory Cache [continued] • redis is awesome (but more complicated) :: also has sharding
 /* redis can do so much more */
  • 11. … more redis (I love redis!) #atomic #fancy_replacing_your_auto_increments_with_this??
  • 12. … more redis (I love redis!)
  • 13. … more redis (I love redis!) #wondering_about_message_queues
  • 14. … more redis (I love redis!)
  • 15. Background Work (non-blocking) • 3rd Party Calls (tweeting, api-calls, emailing, etc) • Expensive DB (or any other) work - especially unimportant ones • Q: What’s “expensive” ?? 
 A: 150+ milliseconds • Ask yourself: Is it important for the next request?! • Q: So what do I do?
 A: Queue it!!
 Q: How?
 A: Why with REDIS, off course?! :)
 … or something else… like MySQL… or not?
  • 16. During billing run (25th to 2nd) Afrihost runs… 550 000 background CLI's - broken up over 253 scripts Some of these actions, are called... 75k times during a month, consuming... 9.7 days of server time !!!
  • 17. > composer.phar install chrisboulton/php-resque
  • 18. 40million records added in 42 minutes ... that's 954k in a minute... ... that's 15906 in a second!! (MySQL took 34 seconds to do this) ... that's 35 seconds (rounded up, lol) to insert the entire billing-run to Afrihost Job Queue!! MySQL didn’t stand a chance!! (1177 seconds = 19.6 minutes!!)
  • 19. HTTP Caching • Are you caching assets on the browsers? • Should they really download new CSS that often? • How do you cache-bust? • eTag much? No, it’s not this…
  • 20. Reverse Proxy • varnish - varnish-cache.org • nginx - nginx.org • haproxy - haproxy.org • squid - squid-cache.org • PS: Most Frameworks has reverse proxy built in!!
  • 21. Reverse Proxy - haproxy
  • 22. Database Optimisation • SQL Slow Query Log - look at it regularly! • Add slaves for read-scaling! • Side-line: Disaster Recovery :: Slave 0-seconds + Slave 24-hour! • Archive!! - makes reading AND writing faster • Offload!! - perhaps relational DB isn’t the right place for data?
  • 23. Database Optimisation [continued…] id username in_bytes out_bytes created_at 123 sarel@afrihost.co.za 1024 2048 2014-07-15 10:01:15 124 dude@afrihost.co.za 971826 12823 2014-07-15 10:01:23 125 geek@afrihost.co.za 17263712 7126373 2014-07-15 10:01:58 126 27838127372@afrihost 12382 9563 2014-07-15 10:02:07 2009-06 :: 3110 records 2009-10 :: 1.7 million records 2010-10 :: 11.9 million records 2011-10 :: 17.4 million records 2012-10 :: 26.6 million records 2013-10 :: 59.6 million records 2014-06 :: 101.1 million records
  • 24. Database Optimisation [continued…] • A good strategy that worked for us was ztableYYYYMM! • You could use any strategy you like, the basics of it: • Select a bunch of rows • Insert them into the applicable archive table • Delete original • Check out: https://github.com/sarelvdwalt/SFDatabaseArchiveBundle
  • 25. Framework Optimisation • Did you just install it and leave? #default_install! • Go through your configs, switch things on and off for production • PRO Hint :: Switch debugging off in production • PRO Hint #2 :: Switch APC / OpCache on INSIDE your Framework (if it has it) for things like Doctrine / ORM
  • 26. Doing Essential work Up-Front • Pre-cache data - hey, Redis / Casandra might be a good place to put this?? :) • Warm up your cache during rollouts • Careful about rollout cache busting!
  • 27. Move work to the client • The math is simple: 100k clients times 4 cores = 400 000 CPU cores! Use them … use them ALL!!!! • Seriously, render calculations belong on the browser. CSS3, JavaScript • Do you have an IF statement in your HTML generation (on server)? Now you have two problems! • Send data via API, with templates - can utilise CDN for templates - SOA (Service Oriented Architecture) • AngularJS, BackboneJS, check out TodoMVC.com
  • 28. Learn to debug… LIVE! • xdebug + webgrind - this will hurt, it’s slow and eats CPU’s (and HDD space) • xhprof + xhprofGUI - fast, can run on production (best to keep it off until you need it) • Sometimes logging is good enough! Use LogStash for history and trend… which brings me to monitoring…
  • 29. Learn to debug… LIVE! Have you tried: Don’t lie… you echo’d in your wetsuit, didn’t you? Perhaps better to wrap that…
  • 30. Monitoring! LogStash - aggregate logs from multiple servers into central location. … let’s zoom and see WTF…
  • 31. Monitoring… looking closer… … hmmmm… what started around 18:08 on the 25th?
  • 32. Monitoring… looking closer… … hmmmm… what started around 18:08 on the 25th? TURNS OUT FALSE ALARM, BUT STILL… USEFUL!
  • 34. Monitoring… DevOps Board… SMS’s (Texts)… … lots and lots of notifications! ON-Call Much?
  • 35. Accessibility • How close are you to your servers? • Do you NEED to log in to see logs? • Catch-22 :: Developers should be able to access anything (or close to) without having to log into the servers… but don’t deny them access.
  • 36. Side-line… The most junior developer should do the rollouts!
  • 37. Let’s look at something practical… the Afrihost order form.
  • 38. Each click, does: 1. HTTP request (hits apache, hits symfony) 2. Asks the DB for the next products in the category 3. Returns the value, and renders it Let’s go look at it live: clientzone.afrihost.com/get-connected Remember this?
  • 39. Final thoughts… … but sometimes it’s not so elementary.
  • 40. Thank you. Charging beer… 36% github.com/sarelvdwalt/php-jhb