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

PDF
A comprehensive guide to Agentic AI Systems
PPTX
Operations and Supply Chain Toolkit - Framework, Best Practices and Templates
PPTX
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
PPTX
Carbon footprint
PPT
Data power use cases
PPTX
What does net-zero emissions mean?
PPTX
Diabetes Mellitus
PPTX
Hypertension
A comprehensive guide to Agentic AI Systems
Operations and Supply Chain Toolkit - Framework, Best Practices and Templates
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
Carbon footprint
Data power use cases
What does net-zero emissions mean?
Diabetes Mellitus
Hypertension

What's hot (20)

PPTX
Thrift vs Protocol Buffers vs Avro - Biased Comparison
PDF
Introduction to Kubernetes Workshop
PDF
Atomicity In Redis: Thomas Hunter
PDF
Introducing the Apache Flink Kubernetes Operator
PDF
Grafana introduction
PDF
AOT and Native with Spring Boot 3.0
PDF
Kubernetes in Docker
PDF
Dataflow with Apache NiFi
PPTX
Apache Knox Gateway "Single Sign On" expands the reach of the Enterprise Users
PPTX
PDF
Jenkins-CI
PDF
Producer Performance Tuning for Apache Kafka
PDF
Consumer offset management in Kafka
PPTX
Monitoring Apache Kafka
PPTX
Introduction to kubernetes
PPTX
HBaseConEast2016: How yarn timeline service v.2 unlocks 360 degree platform i...
PDF
The Integration of Laravel with Swoole
PPTX
Kafka presentation
PDF
Productizing Structured Streaming Jobs
PDF
Apache Kafka Architecture & Fundamentals Explained
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Introduction to Kubernetes Workshop
Atomicity In Redis: Thomas Hunter
Introducing the Apache Flink Kubernetes Operator
Grafana introduction
AOT and Native with Spring Boot 3.0
Kubernetes in Docker
Dataflow with Apache NiFi
Apache Knox Gateway "Single Sign On" expands the reach of the Enterprise Users
Jenkins-CI
Producer Performance Tuning for Apache Kafka
Consumer offset management in Kafka
Monitoring Apache Kafka
Introduction to kubernetes
HBaseConEast2016: How yarn timeline service v.2 unlocks 360 degree platform i...
The Integration of Laravel with Swoole
Kafka presentation
Productizing Structured Streaming Jobs
Apache Kafka Architecture & Fundamentals Explained
Ad

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

PPTX
How does Apache Pegasus (incubating) community develop at SensorsData
PDF
Disaggregated Container Attached Storage - Yet Another Topology with What Pur...
PDF
Disaggregated Container Attached Storage - Yet Another Topology with What Pur...
PDF
4. (mjk) extreme performance 2
PPTX
Cost Effectively Run Multiple Oracle Database Copies at Scale
PDF
NAVER Ceph Storage on ssd for Container
PDF
A Tale of 2 Systems
PPTX
Dissecting Scalable Database Architectures
PDF
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
PDF
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
PPTX
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
PPTX
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
PDF
SPSUtah 2014 SharePoint 2013 Performance (Admin)
PDF
Boost the Performance of SharePoint Today!
PDF
SharePoint Saturday San Antonio: SharePoint 2010 Performance
PPTX
Work with hundred of hot terabytes in JVMs
PDF
haproxy-150423120602-conversion-gate01.pdf
PPTX
HAProxy
PDF
DrupalCampLA 2014 - Drupal backend performance and scalability
PPTX
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
How does Apache Pegasus (incubating) community develop at SensorsData
Disaggregated Container Attached Storage - Yet Another Topology with What Pur...
Disaggregated Container Attached Storage - Yet Another Topology with What Pur...
4. (mjk) extreme performance 2
Cost Effectively Run Multiple Oracle Database Copies at Scale
NAVER Ceph Storage on ssd for Container
A Tale of 2 Systems
Dissecting Scalable Database Architectures
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
SPSUtah 2014 SharePoint 2013 Performance (Admin)
Boost the Performance of SharePoint Today!
SharePoint Saturday San Antonio: SharePoint 2010 Performance
Work with hundred of hot terabytes in JVMs
haproxy-150423120602-conversion-gate01.pdf
HAProxy
DrupalCampLA 2014 - Drupal backend performance and scalability
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Ad

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
sap open course for s4hana steps from ECC to s4
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
A Presentation on Artificial Intelligence
PPTX
MYSQL Presentation for SQL database connectivity
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
sap open course for s4hana steps from ECC to s4
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Assigned Numbers - 2025 - Bluetooth® Document
A Presentation on Artificial Intelligence
MYSQL Presentation for SQL database connectivity
A comparative analysis of optical character recognition models for extracting...
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
gpt5_lecture_notes_comprehensive_20250812015547.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
MIND Revenue Release Quarter 2 2025 Press Release
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf

High Concurrency Architecture and Laravel Performance Tuning