SlideShare a Scribd company logo
The Integration of
Laravel with Swoole
@ L a r a v e l C o n f Ta i w a n 2 0 1 8
B y A l b e r t C h e n
About Me
{
"data": {
"human": {
"name": "Albert Chen",
"occupation": "Software Engineer",
"company": "Unisharp Techonology",
"website": "https://albert-chen.com",
"interests": [
"traveling",
"programming",
"cooking"
],
"age": 26
}
}
}
The Integration of Laravel with Swoole
What is Swoole?
Swoole is…
a C extension for
Open Source
Based on Apache2.0 License
Naming of Swoole
+ =
Features
• Written in C, extremely high performance
• Event driven, non-blocking I/O
• Supports TCP / UDP / UnixSock
• Supports Async / Sync / Coroutine
• Supports IPv4 / IPv6 Network
• Multi-process, multi-thread structure
• Supports daemon
Laravel is awesome
But can it be even faster?
PHP’s Lifecycle
Request
PHP File
PHP File
PHP File
PHP File
PHP File
Check
Parse
Compile
Execute
(Zend Engine)
How many files are required
for one request in Laravel?
218
Laravel’s Lifecycle
Autoload Load App Bootstrap
Register
Service
Providers
Boot
Service
Providers
Http
Kernel
Middleware
Dispatch
by Router
Routes
Match
ControllerResponse
Terminate

Middleware
Request
public/
index.php
What Makes Laravel Slow?
• A large amount of files are required.
• Each file needs its parsing and compiling.
• Compiled results will be destroyed after the request.
• The default session driver of Laravel is file.
• Laravel is a full-stack framework.
• All the resource can not be reused.
Why try to integrate
with ?
Swoole Frameworks
Swoole Framework
Swoole Distributed
Easy Swoole
Blink
FastD
TSF
zhttp
MixPHP
GroupCo
Swoole’s Model
Integrating Solutions
① Only use Swoole like PHP-FPM.
② Preload and share single Laravel application.
③ Reset necessary classes/variables based on ②.
④ Build sandbox app for request process based on ③.
Running on Package
Integrating Solutions
① Only use Swoole like PHP-FPM.
Integrating Solutions
② Preload and share one Laravel application.
Integrating Solutions
Autoload Load App Bootstrap
Register
Service
Providers
Boot
Service
Providers
Http
Kernel
Middleware
Dispatch
by Router
Routes
Match
ControllerResponse
Terminate

Middleware
Request
public/
Laravel will be only booted at the first time.
② Preload and share one Laravel application.
Integrating Solutions
② Preload and share one Laravel application.
Login Access
Protected
Resource
Authenticate
User A
? ?
Protected
Resource
?
User B
Integrating Solutions
Integrating Issues
① Laravel application will be booted only at the first time.
② All the singleton classes, global or static properties
will be preserved in the memory.
③ Developers need to reset these polluted variables
manually.
Integrating Issues
③ Reset necessary variables based on ②.
Integrating Issues
From dingo package
Integrating Issues
① There are too many unpredictable singleton instances.
② Some code will make app become dirty.
③ Some dependency properties are not easy to reset.
④ Damned static variables…
Laravel’s Service Container
Illuminate Container
$resolved = [];
$aliases = [];
$bindings = [];
$instances = [];
$serviceProviders = [];
$loadedProviders = [];
Laravel’s Facades
protected static $app;
protected static
$resolvedInstance;
Facades
Service Container
• $app->singleton(‘event’, …)
• $app->singleton(‘db’, …)
• $app->singleton(‘auth’, …)
Service Provider
event db auth
Sandbox App Container
Illuminate
Container
$resolved = [];
$aliases = [];
$bindings = [];
$instances = [];
$serviceProviders = [];
$loadedProviders = [];
Sandbox
ContainerClone
Instances Outside of Sandbox
Shared Instances
view db session routes
cache config cookie encrypt
hash
router
url log event
Sandbox App Container
Request
Sandbox
Reset Config
Clear Instances
Bind Request
Rebind Router’s
Container
Reset Service Providers
Redirect Container and
Facades
Dispatch
Integrating Issues
Http Kernel
App
Router
Container
Routes Collection
Route
Container
Route
Container
Integrating Issues
From pagination service provider
Integrating Issues
Integrating Issues
Laravel’s New Lifecycle
Autoload Load App Bootstrap
Sandbox

Reset
Reset
Service
Providers
Http
Kernel
Middleware
Dispatch
by Router
Routes
Match
ControllerResponse
Terminate

Middleware
Request
public/
index.php
• Save I/O for requiring files.
• Make app container isolated.
Laravel Swoole
940+ Stars
on Github
swooletw/laravel-swoole
Laravel Swoole
• Run Laravel/Lumen application on top of Swoole.
• Outstanding performance boosting up to 5x faster.
• Sandbox mode to isolate app container.
• Support running websocket server in Laravel.
• Support Socket.io protocol.
• Support Swoole table for cross-process data sharing.
• Support Coroutine (in develop).
Connection Pool
Database
Worker
Worker
Worker
Worker
• Persistent Connections
• Auto Reconnect
Websocket in Laravel
Broadcast
Event
Pub / Sub
Publish
Data
Emit
Broadcasted
Data
Websocket in Laravel Swoole
Emit Data
Parser Layer
2probe 42["add user","test"]
Websocket Server
Websocket Server
Benchmark
• Provider: AWS EC2
• Instance Type: General t2.2xlarge
• Hardware Specs: 8 CPUs / 32 G Memory
• OS: Ubuntu 16.04.4 x64
• PHP Version: 7.2
• Laravel Version: 5.6.3
• Benchmark Tool: wrk
Benchmark
wrk -t4 -c10 http://laravel-swoole.tw
Running 10s test @ http://laravel-swoole.tw
4 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.49ms 5.62ms 110.36ms 97.98%
Req/Sec 396.43 71.29 444.00 86.87%
15671 requests in 10.01s, 38.05MB read
Requests/sec: 1565.63
Transfer/sec: 3.80MB
Benchmark
wrk -t4 -c10 http://laravel-swoole.tw:1215
Running 10s test @ http://laravel-swoole.tw:1215
4 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 0.87ms 1.59ms 40.76ms 98.57%
Req/Sec 2.71k 140.31 2.89k 88.09%
108606 requests in 10.10s, 261.53MB read
Requests/sec: 10753.42
Transfer/sec: 25.89MB
Coroutine
Swoole Swoole 2.0 Swoole 4.0
• async clients
• PHP yield + generator
• coroutine clients
• setjmp/longjmp
• limited use cases
• call_user_func
• array_map
• _destruct
• coroutine clients
• boost.context 1.60
• support all use cases
Coroutine
Coroutine
hello go1
hello man
hello go2
Coroutine Clients in Swoole
• TCP / UDP Client
• Http Client
• Http2 Client
• Redis Client
• MySQL Client
• PostgreSQL Client
Connection Pool for Coroutine
• Each pool maintains several connections.
Connection Connection
Connection Connection
Connection Connection
Connection Pool
Worker Database
Connection Pool for Coroutine
Database
Worker
Worker
Worker
Worker
Pool
Pool
Pool
Pool
• Each worker has its own connection pool.
MySQL Coroutine
Swoole Mysql Connector
Eloquent ORM
Swoole PDO
Swoole PDO
Statement
MySQL Coroutine
Benchmark
wrk -t4 -c10 http://laravel-swoole.tw:1215/sync
Running 10s test @ http://laravel-swoole.tw:1215/sync
4 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.08s 0.00us 1.08s 100.00%
Req/Sec 0.11 0.33 1.00 88.89%
9 requests in 10.10s, 8.14KB read
Socket errors: connect 0, read 0, write 0, timeout 8
Requests/sec: 0.89
Transfer/sec: 825.20B
Benchmark
wrk -t4 -c10 http://laravel-swoole.tw:1215/coro
Running 10s test @ http://laravel-swoole.tw:1215/coro
4 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.03s 7.91ms 1.05s 72.22%
Req/Sec 2.17 2.84 9.00 85.71%
72 requests in 10.10s, 65.00KB read
Requests/sec: 7.13
Transfer/sec: 6.43KB
Q&A
Ad

More Related Content

What's hot (20)

Resilience4j with Spring Boot
Resilience4j with Spring BootResilience4j with Spring Boot
Resilience4j with Spring Boot
Knoldus Inc.
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
Dale Lane
 
Introduction and Deep Dive Into Containerd
Introduction and Deep Dive Into ContainerdIntroduction and Deep Dive Into Containerd
Introduction and Deep Dive Into Containerd
Kohei Tokunaga
 
이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정
Arawn Park
 
Instana - ClickHouse presentation
Instana - ClickHouse presentationInstana - ClickHouse presentation
Instana - ClickHouse presentation
Miel Donkers
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at Square
Apigee | Google Cloud
 
Postman: An Introduction for Testers
Postman: An Introduction for TestersPostman: An Introduction for Testers
Postman: An Introduction for Testers
Postman
 
[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자
Oracle Korea
 
Ansible
AnsibleAnsible
Ansible
Knoldus Inc.
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud
VMware Tanzu
 
Being Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring ReactorBeing Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring Reactor
Max Huang
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
Tricode (part of Dept)
 
Prometheus Overview
Prometheus OverviewPrometheus Overview
Prometheus Overview
Brian Brazil
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Manav Prasad
 
Kafka: Internals
Kafka: InternalsKafka: Internals
Kafka: Internals
Knoldus Inc.
 
Extreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and TuningExtreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and Tuning
Milind Koyande
 
Introduction to Docker - 2017
Introduction to Docker - 2017Introduction to Docker - 2017
Introduction to Docker - 2017
Docker, Inc.
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
Jonathan Holloway
 
Resilience4j with Spring Boot
Resilience4j with Spring BootResilience4j with Spring Boot
Resilience4j with Spring Boot
Knoldus Inc.
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
Dale Lane
 
Introduction and Deep Dive Into Containerd
Introduction and Deep Dive Into ContainerdIntroduction and Deep Dive Into Containerd
Introduction and Deep Dive Into Containerd
Kohei Tokunaga
 
이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정
Arawn Park
 
Instana - ClickHouse presentation
Instana - ClickHouse presentationInstana - ClickHouse presentation
Instana - ClickHouse presentation
Miel Donkers
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at Square
Apigee | Google Cloud
 
Postman: An Introduction for Testers
Postman: An Introduction for TestersPostman: An Introduction for Testers
Postman: An Introduction for Testers
Postman
 
[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자
Oracle Korea
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud
VMware Tanzu
 
Being Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring ReactorBeing Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring Reactor
Max Huang
 
Prometheus Overview
Prometheus OverviewPrometheus Overview
Prometheus Overview
Brian Brazil
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
Extreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and TuningExtreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and Tuning
Milind Koyande
 
Introduction to Docker - 2017
Introduction to Docker - 2017Introduction to Docker - 2017
Introduction to Docker - 2017
Docker, Inc.
 

Similar to The Integration of Laravel with Swoole (20)

Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
Viral Solani
 
Eugene PHP June 2015 - Let's Talk Laravel
Eugene PHP June 2015 - Let's Talk LaravelEugene PHP June 2015 - Let's Talk Laravel
Eugene PHP June 2015 - Let's Talk Laravel
anaxamaxan
 
About Clack
About ClackAbout Clack
About Clack
fukamachi
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
Amazon Web Services Japan
 
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Docker, Inc.
 
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to YouHTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
David Delabassee
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
Soheil Khodayari
 
Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?
John Blackmore
 
Hidden things uncovered about laravel development
Hidden things uncovered about laravel developmentHidden things uncovered about laravel development
Hidden things uncovered about laravel development
Katy Slemon
 
DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...
DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...
DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...
Felipe Prado
 
What is NetDevOps? How? Leslie Carr PuppetConf 2015
What is NetDevOps? How? Leslie Carr PuppetConf 2015What is NetDevOps? How? Leslie Carr PuppetConf 2015
What is NetDevOps? How? Leslie Carr PuppetConf 2015
Leslie Carr
 
Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014
Barney Hanlon
 
Function as a Service
Function as a ServiceFunction as a Service
Function as a Service
rich fernandez
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Priyanka Aash
 
Lares from LOW to PWNED
Lares from LOW to PWNEDLares from LOW to PWNED
Lares from LOW to PWNED
Chris Gates
 
Appenginejs (old presentation)
Appenginejs (old presentation)Appenginejs (old presentation)
Appenginejs (old presentation)
Panagiotis Astithas
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
Hiroshi SHIBATA
 
Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web Framework
Daniel Woods
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
Akshaya Mahapatra
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
Viral Solani
 
Eugene PHP June 2015 - Let's Talk Laravel
Eugene PHP June 2015 - Let's Talk LaravelEugene PHP June 2015 - Let's Talk Laravel
Eugene PHP June 2015 - Let's Talk Laravel
anaxamaxan
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
Amazon Web Services Japan
 
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Docker, Inc.
 
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to YouHTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
David Delabassee
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
Soheil Khodayari
 
Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?
John Blackmore
 
Hidden things uncovered about laravel development
Hidden things uncovered about laravel developmentHidden things uncovered about laravel development
Hidden things uncovered about laravel development
Katy Slemon
 
DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...
DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...
DEF CON 27 - ORANGE TSAI and MEH CHANG - infiltrating corporate intranet like...
Felipe Prado
 
What is NetDevOps? How? Leslie Carr PuppetConf 2015
What is NetDevOps? How? Leslie Carr PuppetConf 2015What is NetDevOps? How? Leslie Carr PuppetConf 2015
What is NetDevOps? How? Leslie Carr PuppetConf 2015
Leslie Carr
 
Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014
Barney Hanlon
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Priyanka Aash
 
Lares from LOW to PWNED
Lares from LOW to PWNEDLares from LOW to PWNED
Lares from LOW to PWNED
Chris Gates
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
Hiroshi SHIBATA
 
Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web Framework
Daniel Woods
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
Akshaya Mahapatra
 
Ad

Recently uploaded (20)

Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Ad

The Integration of Laravel with Swoole

  • 1. The Integration of Laravel with Swoole @ L a r a v e l C o n f Ta i w a n 2 0 1 8 B y A l b e r t C h e n
  • 2. About Me { "data": { "human": { "name": "Albert Chen", "occupation": "Software Engineer", "company": "Unisharp Techonology", "website": "https://albert-chen.com", "interests": [ "traveling", "programming", "cooking" ], "age": 26 } } }
  • 5. Swoole is… a C extension for Open Source Based on Apache2.0 License
  • 7. Features • Written in C, extremely high performance • Event driven, non-blocking I/O • Supports TCP / UDP / UnixSock • Supports Async / Sync / Coroutine • Supports IPv4 / IPv6 Network • Multi-process, multi-thread structure • Supports daemon
  • 9. PHP’s Lifecycle Request PHP File PHP File PHP File PHP File PHP File Check Parse Compile Execute (Zend Engine)
  • 10. How many files are required for one request in Laravel? 218
  • 11. Laravel’s Lifecycle Autoload Load App Bootstrap Register Service Providers Boot Service Providers Http Kernel Middleware Dispatch by Router Routes Match ControllerResponse Terminate
 Middleware Request public/ index.php
  • 12. What Makes Laravel Slow? • A large amount of files are required. • Each file needs its parsing and compiling. • Compiled results will be destroyed after the request. • The default session driver of Laravel is file. • Laravel is a full-stack framework. • All the resource can not be reused.
  • 13. Why try to integrate with ?
  • 14. Swoole Frameworks Swoole Framework Swoole Distributed Easy Swoole Blink FastD TSF zhttp MixPHP GroupCo
  • 16. Integrating Solutions ① Only use Swoole like PHP-FPM. ② Preload and share single Laravel application. ③ Reset necessary classes/variables based on ②. ④ Build sandbox app for request process based on ③. Running on Package
  • 17. Integrating Solutions ① Only use Swoole like PHP-FPM.
  • 18. Integrating Solutions ② Preload and share one Laravel application.
  • 19. Integrating Solutions Autoload Load App Bootstrap Register Service Providers Boot Service Providers Http Kernel Middleware Dispatch by Router Routes Match ControllerResponse Terminate
 Middleware Request public/ Laravel will be only booted at the first time. ② Preload and share one Laravel application.
  • 20. Integrating Solutions ② Preload and share one Laravel application. Login Access Protected Resource Authenticate User A ? ? Protected Resource ? User B
  • 22. Integrating Issues ① Laravel application will be booted only at the first time. ② All the singleton classes, global or static properties will be preserved in the memory. ③ Developers need to reset these polluted variables manually.
  • 23. Integrating Issues ③ Reset necessary variables based on ②.
  • 25. Integrating Issues ① There are too many unpredictable singleton instances. ② Some code will make app become dirty. ③ Some dependency properties are not easy to reset. ④ Damned static variables…
  • 26. Laravel’s Service Container Illuminate Container $resolved = []; $aliases = []; $bindings = []; $instances = []; $serviceProviders = []; $loadedProviders = [];
  • 27. Laravel’s Facades protected static $app; protected static $resolvedInstance; Facades Service Container • $app->singleton(‘event’, …) • $app->singleton(‘db’, …) • $app->singleton(‘auth’, …) Service Provider event db auth
  • 28. Sandbox App Container Illuminate Container $resolved = []; $aliases = []; $bindings = []; $instances = []; $serviceProviders = []; $loadedProviders = []; Sandbox ContainerClone
  • 29. Instances Outside of Sandbox Shared Instances view db session routes cache config cookie encrypt hash router url log event
  • 30. Sandbox App Container Request Sandbox Reset Config Clear Instances Bind Request Rebind Router’s Container Reset Service Providers Redirect Container and Facades Dispatch
  • 31. Integrating Issues Http Kernel App Router Container Routes Collection Route Container Route Container
  • 35. Laravel’s New Lifecycle Autoload Load App Bootstrap Sandbox
 Reset Reset Service Providers Http Kernel Middleware Dispatch by Router Routes Match ControllerResponse Terminate
 Middleware Request public/ index.php • Save I/O for requiring files. • Make app container isolated.
  • 38. Laravel Swoole • Run Laravel/Lumen application on top of Swoole. • Outstanding performance boosting up to 5x faster. • Sandbox mode to isolate app container. • Support running websocket server in Laravel. • Support Socket.io protocol. • Support Swoole table for cross-process data sharing. • Support Coroutine (in develop).
  • 40. Websocket in Laravel Broadcast Event Pub / Sub Publish Data Emit Broadcasted Data
  • 41. Websocket in Laravel Swoole Emit Data Parser Layer 2probe 42["add user","test"]
  • 44. Benchmark • Provider: AWS EC2 • Instance Type: General t2.2xlarge • Hardware Specs: 8 CPUs / 32 G Memory • OS: Ubuntu 16.04.4 x64 • PHP Version: 7.2 • Laravel Version: 5.6.3 • Benchmark Tool: wrk
  • 45. Benchmark wrk -t4 -c10 http://laravel-swoole.tw Running 10s test @ http://laravel-swoole.tw 4 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.49ms 5.62ms 110.36ms 97.98% Req/Sec 396.43 71.29 444.00 86.87% 15671 requests in 10.01s, 38.05MB read Requests/sec: 1565.63 Transfer/sec: 3.80MB
  • 46. Benchmark wrk -t4 -c10 http://laravel-swoole.tw:1215 Running 10s test @ http://laravel-swoole.tw:1215 4 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 0.87ms 1.59ms 40.76ms 98.57% Req/Sec 2.71k 140.31 2.89k 88.09% 108606 requests in 10.10s, 261.53MB read Requests/sec: 10753.42 Transfer/sec: 25.89MB
  • 47. Coroutine Swoole Swoole 2.0 Swoole 4.0 • async clients • PHP yield + generator • coroutine clients • setjmp/longjmp • limited use cases • call_user_func • array_map • _destruct • coroutine clients • boost.context 1.60 • support all use cases
  • 50. Coroutine Clients in Swoole • TCP / UDP Client • Http Client • Http2 Client • Redis Client • MySQL Client • PostgreSQL Client
  • 51. Connection Pool for Coroutine • Each pool maintains several connections. Connection Connection Connection Connection Connection Connection Connection Pool Worker Database
  • 52. Connection Pool for Coroutine Database Worker Worker Worker Worker Pool Pool Pool Pool • Each worker has its own connection pool.
  • 53. MySQL Coroutine Swoole Mysql Connector Eloquent ORM Swoole PDO Swoole PDO Statement
  • 55. Benchmark wrk -t4 -c10 http://laravel-swoole.tw:1215/sync Running 10s test @ http://laravel-swoole.tw:1215/sync 4 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.08s 0.00us 1.08s 100.00% Req/Sec 0.11 0.33 1.00 88.89% 9 requests in 10.10s, 8.14KB read Socket errors: connect 0, read 0, write 0, timeout 8 Requests/sec: 0.89 Transfer/sec: 825.20B
  • 56. Benchmark wrk -t4 -c10 http://laravel-swoole.tw:1215/coro Running 10s test @ http://laravel-swoole.tw:1215/coro 4 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.03s 7.91ms 1.05s 72.22% Req/Sec 2.17 2.84 9.00 85.71% 72 requests in 10.10s, 65.00KB read Requests/sec: 7.13 Transfer/sec: 6.43KB
  • 57. Q&A