SlideShare a Scribd company logo
High Concurrency Web Architecture
and Laravel Performance Tuning
@LaravelConf Taiwan 2019
By Albert Chen
About Me
• Albert Chen
• Software Engineer
• M17 HandsUp
• Open Source Maintainer
What Is High Concurrency?
What Is High Concurrency?
PV = 2,000,000 (200w)
QPS = (200w x 0.8) / (24 x 3600 x 0.2)
93 QPS 😀
What Is High Concurrency?
2,000,000 (200w) in 1 minute
QPS = 200w / 60
33333 QPS 😭
What Is High Concurrency?
Read in High Concurrency
• Vertical Scaling
• Horizontal Scaling
• Content Delivery Network
• Data Caching
• Single Point Optimization
Write in High Concurrency
• Message Queue
• Rate Limit
• Maximum Serving Limit
• Wait in Line
• Rules Optimization
Performance Tuning
in Laravel
Performance Tuning in Laravel
• Route and Config Files Cache
• Cache (Not Limited to Database)
• Async Event (Delayed Processing)
• Database Read/Write Separation
• OPCache
• Preloading in PHP 7.4
Route and Config Files Cache
php artisan route:cache
Route and Config Files Cache
Register
Route
Route
Register
Route
Route
Register
Route
Route
Route
Collection
• Lifecycle for Registering Routes
Route and Config Files Cache
Unserialize
Cached
Serialized
Route Collection
Route
Collection
• Lifecycle for Routes Caching
Route and Config Files Cache
Route Numbers No cache (ms) Cache (ms) Speed-up
1 2.5 1.9 1.3x
10 5.2 2.6 2.0x
100 22.5 4.3 5.3x
1,000 166 32 5.1x
10,000 1,513 334 4.5x
https://voltagead.com/laravel-route-caching-for-improved-performance/
Route and Config Files Cache
https://voltagead.com/laravel-route-caching-for-improved-performance/
Route and Config Files Cache
php artisan config:cache
Route and Config Files Cache
Merged
Config File
• Lifecycle for Config Caching
Config

Files
Benchmark Comparison
• Provider: Google Cloud Platform
• Instance Type: n1-standard-8
• CPUs: 8 vCPU Cores (Skylake)
• Memory: 30 G
• Disk: 20 G SSD
• OS: Ubuntu 18.04 LTS
• PHP Version: 7.3
Benchmark Comparison
• Benchmark without Cache
Benchmark Comparison
• Benchmark with Routes and Config Cache
Cache (Not Limited to Database)
• Discover Hotspot Data (Hit Rate)
• Proper TTL for Cached Data
• Avoid Expiring Cache at The Same Time
• Revoke Cache when Data Changes
• Avoid Cache Missing
• Hierarchical Cache Design
• High Available Cache System
• Warm Up the Cache
Cache (Not Limited to Database)
• Revoke Cache when Data Changes
Cache (Not Limited to Database)
• Avoid Cache Missing
Cache (Not Limited to Database)
• Avoid Cache Missing
Client
Database
Cache Layer
Client Client
Cache (Not Limited to Database)
• Hierarchical Cache Design
Database
Local
Memory
Local
Memory
Local
Memory
Cache Layer
Cache
Revoke
Cache (Not Limited to Database)
• High Available Cache System
https://rancher.com/blog/2019/deploying-redis-cluster/
Cache (Not Limited to Database)
• Warm Up the Cache
Request
Request
Request
Request
Cache
Layer
Database
Time Consuming Query(Warm Up)
Async Event (Delayed Processing)
Producer
Kafka
Rabbit MQ
Queue Driver
Consumer
Producer
Producer
Producer
Consumer
Consumer
Consumer
(Laravel Event) (Laravel Queue Worker)
Database Read/Write Separation
20% on Write
80% on Read
Master
Slave Slave Slave
Read Replicas
Database Read/Write Separation
Database Read/Write Separation
App
Master
Slave Slave Slave
Read Replicas
Write
Read
Database Read/Write Separation
Database Read/Write Separation
Database Read/Write Separation
Master Slave Slave Slave
Read Replicas
SQL Proxy
Slave
Write
Read Read Read Read
OPCache
PHP

Files
Tokenizing
Semantic
Parsing
AST
Generate
Bytecode
Execute
Bytecode
Output
• Lifecycle in PHP
OPCache
PHP

Files
Tokenizing
Semantic
Parsing
AST
Generate
Bytecode
Execute
Bytecode
Output
• Lifecycle in PHP with OPCache
Load Bytecode
From Memory
Check
Bytecode Cache
Benchmark Comparison
• Benchmark with OPCache
Benchmark Comparison
• Benchmark without OPCache
Preloading in PHP 7.4
Preloading in PHP 7.4
PHP

Files
Tokenizing
Semantic
Parsing
AST
Generate
Bytecode
Execute
Bytecode
Output
Load Bytecode
From Memory
Check
Bytecode Cache
Preload
in Memory
• Lifecycle in PHP with Preloading
Preloading in PHP 7.4
composer require ayesh/composer-preload
Benchmark Comparison
• Benchmark with Preloading
Benchmark
Preloaded
files
Server
startup time
Opcache
memory used
Per request
memory used
QPS
No
preloading
0 0.06 s
16 MB after
warmup
1,825 KB 596 rq/s
Preload hot
classes
878 0.26 s 21 MB 869 KB 695 rq/s
Preload
everything
14541 1.56 s 105 MB 881 KB 675 rq/s
https://github.com/composer/composer/issues/7777
Use Case Analysis
Banana News
• PV is around 200w
• Large amount of content resource
• Fuzzy search support
• Changeable news rank by topics
• 99% read, 1% write
Banana News
Server Database
Images
Server
(CDN)
Banana News
Database
Images
Server
(CDN)
Server
Server
Server
Load
Balancer
Banana News
Images
Server
(CDN)
Load
Balancer
Master
Slave Slave Slave
Read
Server
Server
Server
Banana News
Images
Server
(CDN)
Load
Balancer
Master
Slave Slave Slave
Read
Redis
Cache
Server
Server
Server
Banana News
Images
Server
Load
Balancer
Master
Slave Slave Slave
Read
Redis
Cache
CDN
Elastic Search
Server
Server
Server
eg. Cloudflare
AATIX
• High concurrency in short period
• Limited tickets for selling
• High available service
AATIX
Images
Server
Load
Balancer
Master
Slave Slave Slave
Read
Redis
Cache
CDN
Server
Server
Server
AATIX
Images
Server
Load
Balancer
Master
Slave Slave Slave
Read
Redis
Cache
CDN
Server
Server
Server
😱
AATIX
Read
HTTP Request
CDN
Queue
Write
DB
AATIX
Images
Server
Load
Balancer
Master
Slave Slave Slave
Read
Redis
Cache
CDN
Server
Server
Server
Queue
AATIX
Master
Slave Slave Slave
Read
Redis
Cache
Server
Server
Server
Queue
Local Cache
Atomic Counter
Rate Limit
Circuit Breaking
AATIX
• Avoid large amount of write requests at the same time
• Queue
• Rate Limit
• Reduce repeated requests from clients
• Service isolation for hotspot data
• Circuit breaking for high availability
• Large amount of webhook calls
• High availability for webhooks
• Instant response time
• Chat service for live streaming
HandsUp
HandsUp
Facebook
Webhooks
Message
Load
Balancer
Server
Server
Server
Queue
PubNub

Service
Analysis
Service
Swoole Service
PubSub
Many to Many
Queue Workers
The Last
But Not the Least
Q&A

More Related Content

What's hot (20)

PDF
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
OpenStack Korea Community
 
PPTX
Vitess VReplication: Standing on the Shoulders of a MySQL Giant
Matt Lord
 
PDF
SQOOP PPT
Dushhyant Kumar
 
PDF
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Edureka!
 
PPTX
4. 대용량 아키텍쳐 설계 패턴
Terry Cho
 
PDF
Introduction to HBase
Avkash Chauhan
 
PPTX
mongodb와 mysql의 CRUD 연산의 성능 비교
Woo Yeong Choi
 
PPTX
A simple introduction to redis
Zhichao Liang
 
PDF
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...
Edureka!
 
PPTX
Kubernetes #1 intro
Terry Cho
 
PDF
ProxySQL High Avalability and Configuration Management Overview
René Cannaò
 
PDF
Intro to HBase
alexbaranau
 
PDF
Spring Cloud Gateway
VMware Tanzu
 
PDF
Apache pulsar - storage architecture
Matteo Merli
 
PDF
Solving Enterprise Data Challenges with Apache Arrow
Wes McKinney
 
PPTX
ELK Stack
Phuc Nguyen
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
PPTX
Spring Boot Tutorial
Naphachara Rattanawilai
 
PPTX
Apache Kafka - Patterns anti-patterns
Florent Ramiere
 
PPTX
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
Aldrin Piri
 
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
OpenStack Korea Community
 
Vitess VReplication: Standing on the Shoulders of a MySQL Giant
Matt Lord
 
SQOOP PPT
Dushhyant Kumar
 
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Edureka!
 
4. 대용량 아키텍쳐 설계 패턴
Terry Cho
 
Introduction to HBase
Avkash Chauhan
 
mongodb와 mysql의 CRUD 연산의 성능 비교
Woo Yeong Choi
 
A simple introduction to redis
Zhichao Liang
 
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...
Edureka!
 
Kubernetes #1 intro
Terry Cho
 
ProxySQL High Avalability and Configuration Management Overview
René Cannaò
 
Intro to HBase
alexbaranau
 
Spring Cloud Gateway
VMware Tanzu
 
Apache pulsar - storage architecture
Matteo Merli
 
Solving Enterprise Data Challenges with Apache Arrow
Wes McKinney
 
ELK Stack
Phuc Nguyen
 
Introduction to spring boot
Santosh Kumar Kar
 
Spring Boot Tutorial
Naphachara Rattanawilai
 
Apache Kafka - Patterns anti-patterns
Florent Ramiere
 
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
Aldrin Piri
 

Similar to High Concurrency Architecture and Laravel Performance Tuning (20)

ODP
Caching and tuning fun for high scalability
Wim Godden
 
ODP
Caching and tuning fun for high scalability
Wim Godden
 
ODP
Clug 2011 March web server optimisation
grooverdan
 
ODP
Caching and tuning fun for high scalability
Wim Godden
 
PDF
Optimizing Laravel for Production
Krisna Fathurahman
 
PDF
Clug 2012 March web server optimisation
grooverdan
 
ODP
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
PPTX
Boost your website by running PHP on Nginx
Harald Zeitlhofer
 
PPTX
Silverstripe at scale - design & architecture for silverstripe applications
BrettTasker
 
PDF
10 Million hits a day with WordPress using a $15 VPS
Paolo Tonin
 
PDF
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Grant Norwood
 
PDF
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
grantnorwood
 
PPT
Zend Con 2008 Slides
mkherlakian
 
PDF
Bottom to Top Stack Optimization with LAMP
katzgrau
 
PDF
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
PPTX
Performance out
Andrea Martinez
 
KEY
Introduction to memcached
Jurriaan Persyn
 
ODP
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
PPTX
Performance out
Jack Huang
 
PPTX
Performance out
Jack Huang
 
Caching and tuning fun for high scalability
Wim Godden
 
Caching and tuning fun for high scalability
Wim Godden
 
Clug 2011 March web server optimisation
grooverdan
 
Caching and tuning fun for high scalability
Wim Godden
 
Optimizing Laravel for Production
Krisna Fathurahman
 
Clug 2012 March web server optimisation
grooverdan
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
Boost your website by running PHP on Nginx
Harald Zeitlhofer
 
Silverstripe at scale - design & architecture for silverstripe applications
BrettTasker
 
10 Million hits a day with WordPress using a $15 VPS
Paolo Tonin
 
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Grant Norwood
 
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
grantnorwood
 
Zend Con 2008 Slides
mkherlakian
 
Bottom to Top Stack Optimization with LAMP
katzgrau
 
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
Performance out
Andrea Martinez
 
Introduction to memcached
Jurriaan Persyn
 
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
Performance out
Jack Huang
 
Performance out
Jack Huang
 
Ad

Recently uploaded (20)

PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
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
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
“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
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Ad

High Concurrency Architecture and Laravel Performance Tuning