MICRO-SERVICES
MAGENTO 2.0 PERFORMANCE
by Ivan Chepurnyi
 
 
 
 
 
 
ABOUT ME
One of lucky former members of Magento 1.x Core Team
I love to optimize performance
I give trainings and independent consultancy
Let's talk about PHP APP evolution
All started from the good old Apache's
mod_php
mod_php
Spawns 
 new PHP process
Server 
Thread
Executes 
PHP script
PHP
 Initialization
Executes 
Business Logic
Application
 Bootstrap
Rendering the
Page
DRAWBACKS
Dynamic server processes was not limited
PHP process is alive unless all bytes transfered to a
remote connection
Every new PHP process takes time to start
Who is still running mod_php on production?
Then started an era of PHP-FPM
PHP-FPM
Waits 
for Response
Server 
Thread
Executes 
PHP File
Takes running
process
FPM
FastCGI Process
Manager
Process Pool
1..n
Executes 
Business Logic
Application
 Bootstrap
Rendering the
Page
DRAWBACK
Not controlling your memory usage, might results in
memory over-usage by one of the processes
Now the era of async I/O PHP apps is
emerging...
Application Process Manager
Waits 
for Response
Server 
Thread
Fork/Re-use Process 
with Business Logic
Application
Master Process
Rendering the
Page
DRAWBACKS
You have to control used memory
You have to ensure async IO on any operation
If single line of code fails, all app crashes
Is it possible with Magento 2?
The answer is micro-services...
What is a micro-service?
Micro-service is a component that runs as a separate
application
MICRO-SERVICE CANDIDATES IN MAGENTO 2.0
SESSIONS
Every page load requires I/O operation to cache storage
Dynamic requests in Varnish bootstrap full application
SESSION APPLICATION
Start Server
GC Inactive
Sessions every 5
minutes
Stop Server
IO to Redis IO to Redis
Lazy Load a
Session 
IO to Redis
STOCK PROCESSING
Every order place request requires database lock on stock
table
You usually sacrifice stock integrity for performance
reasons
STOCK APPLICATION
Live proof of concept demo
QUOTE (SHOPPING CARTS)
Every change shopping cart is a write DB operation
QUOTE APPLICATION
Store quotes in memory
Delayed DB syncronization
Endless BI possibilities
IMAGE RESIZE
Images has to be resized sequentially
Cold image cache perfromance hit
IMAGE MICROSERVICE
Image can be resized in parallel
Main Application can utilize Async I/O
LEARN MORE
ReactPHP:
PHPFastCGI:
Sample counter server:
http://reactphp.org/
http://phpfastcgi.github.io/
http://bit.ly/counter-sample
Q&A
@IvanChepurnyi
ivan@ecomdev.org

Mage Titans USA 2016 - Ivan Chepurnyi - Creating Micro-Services for Magento 2.0 Performance