SlideShare une entreprise Scribd logo
1  sur  52
Télécharger pour lire hors ligne
Reducing load with
RabbitMQ
Vilnius PHP 0x20
I’m Povilas Balzaravičius
● PHP developer over 10 years
● Software Engineer at Uber
● Before: developer at Boozt.com (Estina)
● Organizer of Vilnius PHP UG
● Not professional speaker but professional
developer :-)
What will be this talk about?
● The Problem
● RabbitMQ fundamentals
● How Problem was solved
● How we use messaging in general
What is Boozt.com?
● One of top clothes e-
store in Scandinavia
● Over 300 brands &
10000 styles online
● Over 700 categories
The Problem
(or task)
Many items in categories
Many items in categories
Possibly products at the top of page are selling
better.
When customer navigates to category page,
how products must be ordered?
Many items in categories
Items can not be sorted:
● Manually
● Randomly (or how they are stored on db)
● By one of sorting options (price, arrival date,
items on sale, etc.)
Autosort
was implemented
What is Autosort?
● Splits page into segments by number of
items
● Each segment defined by rules
● Segments can be sorted and shuffled
● Collection of segments is called “Autosort”
● “Autosorts” are assigned to categories
Content managers ♥ Autosort...
● Segment sizes shrinked from 200 to 4-20
products - more queries
● Implemented autosort inheritance for
categories - increased sorted categories
count 20-40 times
● Job time increased from 0.25-0.5 to 6-8
hours. Here was our problem :-)
Looking for bottlenecks
● Optimized few code parts - performance
increased ~10%
● Tried tune MySQL indexes - no significant
impact
Bottleneck found!
Saving products positions to database:
UPDATE `product_category` SET `position` = CASE
WHEN product_id = 123 THEN 1
WHEN product_id = 456 THEN 2
WHEN product_id = 789 THEN 3
...
END
WHERE category_id = 1001 AND product_id IN (123, 456, 789)
Getting rid of bottleneck
● Update performed on single category only
● Other categories can be sorted during
update
● Need parallelize sorting1
!
1
With RabbitMQ of course!
RabbitMQ?
● Multi Protocol Messaging Server
● Open source
● Commercial support
● Messaging via AMQP (Advanced Message
Queuing Protocol)
● Supports many programming languages
Why we need messaging?
● Separates Job request from the Job
● Jobs can be performed on separate
processes and machines
● Workers can be added or removed easily
● Messaging is asynchronous
RabbitMQ Basics
● Producer - sends messages
● Consumer - Running process and waiting
for messages
● Queue - a buffer that stores messages
● Exchange - distributes messages
Simple queue example
1. Producer sends message
to named queue
2. Message is stored in
queue
3. Consumer takes message
from named queue
4. Message removed from
queue immediately
5. Consumer “consumes” the
message
Consumer becoming slow?
● Just run additional
consumer
● Round-robin
dispatching by
default
● Jobs are processed
in parallel!
What happens if consumer dies?
● Message is lost if worker dies
● The task should be delivered to another
worker
● RabbitMQ supports message ACKs
● Message is removed when consumer sends
ACK
● ACKs are disabled by default
What happens if server dies?
● Messages in queues will be lost
● RabbitMQ supports durable queues
● Queue needs to be re-created as durable if
was defined before
● Messages should be sent in “persistent”
mode
● RabbitMQ doesn't do fsync(2) for every
message - not 100% durable :-)
Fair dispatch
● If consumer C1 will get more complex jobs
than C2, C1 will be busier all the time.
● Set prefetch_count = 1 property to not to
give more than one message to a worker at
a time.
● Requires ACKing
Let’s think about logging
system
This will help us understand examples
Publish & Subscribe pattern
Deliver same message for multiple consumers
RabbitMQ Exchanges
● RabbitMQ dogma - producer never sends
any messages directly to a queue
● Producer sends messages to an exchange
● A routing_key must be used with messages
● Exchange type describes behavior:
○ Append the message to one/few/all queues
○ Discard the message
○ Types: fanout, direct, topic, headers
Temporary Queues
● If no queue is bounded to exchange,
messages will be lost.
● Temporary queues are deleted after
consumer disconnects.
● Created by consumer when only new
messages should be retrieved.
● RabbitMQ supports temporary queues.
Listening all messages: Fanout
● Fanout exchange type -
send messages to every
connected queue
● Temporary queues
used
● Routing key ignored by
fanout
Listening messages subset: Direct
● Direct exchange type -
deliver msg to queues
with same routing key
● Routing key not ignored
anymore
● Multiple bindings can
be defined for same
queue
● Multiple queues can use
same binding key
Listening messages by Topic
● Topic exchange type - filter messages by
patterns
● Topic is a list of words separated.by.dots
● Subscribing topic patterns:
○ * (asterisk) substitute one word - cron.*.error
○ # (hash) substitute 0 or more words - cron.#
● Topic exchange can behave as fanout or
direct
Listening messages by Topic
Topic pattern: <speed>.<colour>.<species>
● Create and provide callback queue from
provider
● Response will be sent to callback queue
● If single callback queue is used per provider,
use correlation_id to match request with
response
● It is slow and blocking
Receiving results: RPC
Receiving results: RPC
Now you are Ready to
work with RabbitMQ
Let’s get back to Autosort
Scaling Autosort
Scaling Autosort
● Producer sends categories which needs to
be sorted
● Exchange type is direct
● Single named queue with ACK and fair
dispatch is used
● Consumers are calling CLI commands (can
be used for other tasks too)
Scaling achievements
BEFORE
● 6-8 hours
● Single machine
● Single table for all
stores
AFTER
● 2-3 hours
● Separate machines
● 10 separate stores!
~28 times faster!
RabbitMQ in Boozt.com
Services platform
& RabbitMQ
Boozt store
ECCO store
Other store
Warehouse
Accounting
Admin system
Customer
service
Messages DB Calls
MySQL&Redisclusters
Sendgrid
Messaging use case #1
Order completed on Store
1. Message sent to Services platform from
Store
2. Services sends message to:
a. Warehouse to mark products as reserved
b. Accounting to register an order
c. Sendgrid to send an email
Messaging use case #2
Order confirmed on Accounting system
1. Message sent to Services from Accounting
2. Services sends message to:
a. Store to mark order as confirmed
b. Sendgrid to send an email
RabbitMQ ♥ PHP = php-amqplib
● Created by RabbitMQ developer - Alvaro
Videla
● Install via composer videlalvaro/php-
amqplib or
https://github.com/videlalvaro/php-amqplib
Dark side of php-amqplib
<?php
// ...
$channel->exchange_declare(
'topic_logs', 'topic', false, false, false);
list($queue_name, ,) = $channel->queue_declare(
"", false, false, true, false);
// Any comments required?
How to make sure my
consumers are running?
Supervisor
● Supervisor is a client/server system that
allows its users to monitor and control a
number of processes on UNIX-like operating
systems.
● Observes if consumers are running and
reloads them if they died
/etc/supervisor/conf.d/demo.conf
[program:demo]
command=/usr/bin/php /home/pawka/Desktop/rabbitmq-tutorials/php/receive.php
process_name=%(program_name)s
numprocs=1
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=true
stdout_logfile=/tmp/worker.log
user=pawka
Tips for messaging
● Think about using unified workers
● And use priority queues for important tasks
(available since v3.5.0)
● Workers as P2P clients
● Use correlation_id for messages
Tips for messaging
● Manage your workers with supervisor or
similar tool
● Set lifetime for workers (eg. 15 mins)
● Use separate exchanges for separate apps
Resources
● https://www.rabbitmq.com - official site and
great tutorial
● http://tryrabbitmq.com - RabbitMQ simulator
● https://github.com/rabbitmq/rabbitmq-
tutorials/ - Source code of examples
● http://supervisord.org - supervisor
?
Thank You!
twitter.com/@Pawka github.com/Pawka

Contenu connexe

En vedette

Maximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQPMaximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQPKenneth Peeples
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuningihji
 
Websockets: Pushing the web forward
Websockets: Pushing the web forwardWebsockets: Pushing the web forward
Websockets: Pushing the web forwardMark Roden
 
HTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListHTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListMainstreethost
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes EverythingLori MacVittie
 
The State of WebSockets in Django
The State of WebSockets in DjangoThe State of WebSockets in Django
The State of WebSockets in DjangoRami Sayar
 
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media ServerAWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media ServerAmazon Web Services
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...Frank Munz
 
Povilas Balzaravičius: Tinklaraščių spartos optimizavimas
Povilas Balzaravičius: Tinklaraščių spartos optimizavimasPovilas Balzaravičius: Tinklaraščių spartos optimizavimas
Povilas Balzaravičius: Tinklaraščių spartos optimizavimasPovilas Balzaravičius
 
Vilnius PHP: pirmųjų metų apžvalga
Vilnius PHP: pirmųjų metų apžvalgaVilnius PHP: pirmųjų metų apžvalga
Vilnius PHP: pirmųjų metų apžvalgaPovilas Balzaravičius
 
What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)James Titcumb
 
Prezentacijų kūrimas su LaTeX Beamer
Prezentacijų kūrimas su LaTeX BeamerPrezentacijų kūrimas su LaTeX Beamer
Prezentacijų kūrimas su LaTeX BeamerPovilas Balzaravičius
 
Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQAlvaro Videla
 
Asynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simpleAsynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simpleKirill Chebunin
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupKacper Gunia
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixBruce Snyder
 
physical file system in operating system
physical file system in operating systemphysical file system in operating system
physical file system in operating systemtittuajay
 
ServiceMix 4 -- Integrating OSGi with JBI
ServiceMix 4 -- Integrating OSGi with JBIServiceMix 4 -- Integrating OSGi with JBI
ServiceMix 4 -- Integrating OSGi with JBIGert Vanthienen
 
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0Cory Forsyth
 

En vedette (20)

Maximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQPMaximize information exchange in your enterprise with AMQP
Maximize information exchange in your enterprise with AMQP
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
Websockets: Pushing the web forward
Websockets: Pushing the web forwardWebsockets: Pushing the web forward
Websockets: Pushing the web forward
 
HTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive ListHTTP Status Codes Cheat Sheet: An Exhaustive List
HTTP Status Codes Cheat Sheet: An Exhaustive List
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes Everything
 
The State of WebSockets in Django
The State of WebSockets in DjangoThe State of WebSockets in Django
The State of WebSockets in Django
 
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media ServerAWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
AWS Webcast - Live Streaming using Amazon CloudFront and Wowza Media Server
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
 
Povilas Balzaravičius: Tinklaraščių spartos optimizavimas
Povilas Balzaravičius: Tinklaraščių spartos optimizavimasPovilas Balzaravičius: Tinklaraščių spartos optimizavimas
Povilas Balzaravičius: Tinklaraščių spartos optimizavimas
 
Vilnius PHP: pirmųjų metų apžvalga
Vilnius PHP: pirmųjų metų apžvalgaVilnius PHP: pirmųjų metų apžvalga
Vilnius PHP: pirmųjų metų apžvalga
 
What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)
 
Prezentacijų kūrimas su LaTeX Beamer
Prezentacijų kūrimas su LaTeX BeamerPrezentacijų kūrimas su LaTeX Beamer
Prezentacijų kūrimas su LaTeX Beamer
 
Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQ
 
Asynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simpleAsynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simple
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMix
 
physical file system in operating system
physical file system in operating systemphysical file system in operating system
physical file system in operating system
 
ServiceMix 4 -- Integrating OSGi with JBI
ServiceMix 4 -- Integrating OSGi with JBIServiceMix 4 -- Integrating OSGi with JBI
ServiceMix 4 -- Integrating OSGi with JBI
 
Digital jewellery ppt
Digital jewellery  pptDigital jewellery  ppt
Digital jewellery ppt
 
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
 

Similaire à Reducing load with RabbitMQ

Do More With Message Queue
Do More With Message QueueDo More With Message Queue
Do More With Message QueueHean Hong Leong
 
SOA Pattern-Asynchronous Queuing
SOA Pattern-Asynchronous QueuingSOA Pattern-Asynchronous Queuing
SOA Pattern-Asynchronous QueuingWSO2
 
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ Jitendra Bafna
 
Enterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdfEnterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdfOrtus Solutions, Corp
 
Patna_Meetup_MQ
Patna_Meetup_MQPatna_Meetup_MQ
Patna_Meetup_MQOm Prakash
 
Rate limits and Performance
Rate limits and PerformanceRate limits and Performance
Rate limits and Performancesupergigas
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafkavishnu rao
 
Hyderabad mule meetup_march_2022
Hyderabad mule meetup_march_2022Hyderabad mule meetup_march_2022
Hyderabad mule meetup_march_2022Sravan Lingam
 
Introduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalkIntroduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalkMahmoud Said
 
What we've learned from running thousands of production RabbitMQ clusters - L...
What we've learned from running thousands of production RabbitMQ clusters - L...What we've learned from running thousands of production RabbitMQ clusters - L...
What we've learned from running thousands of production RabbitMQ clusters - L...RabbitMQ Summit
 
Server fleet management using Camunda by Akhil Ahuja
Server fleet management using Camunda by Akhil AhujaServer fleet management using Camunda by Akhil Ahuja
Server fleet management using Camunda by Akhil Ahujacamunda services GmbH
 
WebCamp Ukraine 2016: Instant messenger with Python. Back-end development
WebCamp Ukraine 2016: Instant messenger with Python. Back-end developmentWebCamp Ukraine 2016: Instant messenger with Python. Back-end development
WebCamp Ukraine 2016: Instant messenger with Python. Back-end developmentViach Kakovskyi
 
WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...
WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...
WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...WebCamp
 
Big data @ Hootsuite analtyics
Big data @ Hootsuite analtyicsBig data @ Hootsuite analtyics
Big data @ Hootsuite analtyicsClaudiu Coman
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Storyvanphp
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaSteven Wu
 
Are you weak in the middle?
Are you weak in the middle?Are you weak in the middle?
Are you weak in the middle?FSCONS
 

Similaire à Reducing load with RabbitMQ (20)

Do More With Message Queue
Do More With Message QueueDo More With Message Queue
Do More With Message Queue
 
AMQP with RabbitMQ
AMQP with RabbitMQAMQP with RabbitMQ
AMQP with RabbitMQ
 
SOA Pattern-Asynchronous Queuing
SOA Pattern-Asynchronous QueuingSOA Pattern-Asynchronous Queuing
SOA Pattern-Asynchronous Queuing
 
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
MuleSoft Surat Virtual Meetup#33 - Unleash the power of Anypoint MQ and DLQ
 
Enterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdfEnterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdf
 
Patna_Meetup_MQ
Patna_Meetup_MQPatna_Meetup_MQ
Patna_Meetup_MQ
 
Rate limits and Performance
Rate limits and PerformanceRate limits and Performance
Rate limits and Performance
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Hyderabad mule meetup_march_2022
Hyderabad mule meetup_march_2022Hyderabad mule meetup_march_2022
Hyderabad mule meetup_march_2022
 
Introduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalkIntroduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalk
 
Building chat bot
Building chat botBuilding chat bot
Building chat bot
 
What we've learned from running thousands of production RabbitMQ clusters - L...
What we've learned from running thousands of production RabbitMQ clusters - L...What we've learned from running thousands of production RabbitMQ clusters - L...
What we've learned from running thousands of production RabbitMQ clusters - L...
 
Server fleet management using Camunda by Akhil Ahuja
Server fleet management using Camunda by Akhil AhujaServer fleet management using Camunda by Akhil Ahuja
Server fleet management using Camunda by Akhil Ahuja
 
WebCamp Ukraine 2016: Instant messenger with Python. Back-end development
WebCamp Ukraine 2016: Instant messenger with Python. Back-end developmentWebCamp Ukraine 2016: Instant messenger with Python. Back-end development
WebCamp Ukraine 2016: Instant messenger with Python. Back-end development
 
WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...
WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...
WebCamp 2016: Python. Вячеслав Каковский: Real-time мессенджер на Python. Осо...
 
Big data @ Hootsuite analtyics
Big data @ Hootsuite analtyicsBig data @ Hootsuite analtyics
Big data @ Hootsuite analtyics
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
 
Are you weak in the middle?
Are you weak in the middle?Are you weak in the middle?
Are you weak in the middle?
 

Dernier

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 

Dernier (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

Reducing load with RabbitMQ

  • 2. I’m Povilas Balzaravičius ● PHP developer over 10 years ● Software Engineer at Uber ● Before: developer at Boozt.com (Estina) ● Organizer of Vilnius PHP UG ● Not professional speaker but professional developer :-)
  • 3. What will be this talk about? ● The Problem ● RabbitMQ fundamentals ● How Problem was solved ● How we use messaging in general
  • 4.
  • 5. What is Boozt.com? ● One of top clothes e- store in Scandinavia ● Over 300 brands & 10000 styles online ● Over 700 categories
  • 7. Many items in categories
  • 8. Many items in categories Possibly products at the top of page are selling better. When customer navigates to category page, how products must be ordered?
  • 9. Many items in categories Items can not be sorted: ● Manually ● Randomly (or how they are stored on db) ● By one of sorting options (price, arrival date, items on sale, etc.)
  • 11. What is Autosort? ● Splits page into segments by number of items ● Each segment defined by rules ● Segments can be sorted and shuffled ● Collection of segments is called “Autosort” ● “Autosorts” are assigned to categories
  • 12.
  • 13. Content managers ♥ Autosort... ● Segment sizes shrinked from 200 to 4-20 products - more queries ● Implemented autosort inheritance for categories - increased sorted categories count 20-40 times ● Job time increased from 0.25-0.5 to 6-8 hours. Here was our problem :-)
  • 14. Looking for bottlenecks ● Optimized few code parts - performance increased ~10% ● Tried tune MySQL indexes - no significant impact
  • 15. Bottleneck found! Saving products positions to database: UPDATE `product_category` SET `position` = CASE WHEN product_id = 123 THEN 1 WHEN product_id = 456 THEN 2 WHEN product_id = 789 THEN 3 ... END WHERE category_id = 1001 AND product_id IN (123, 456, 789)
  • 16. Getting rid of bottleneck ● Update performed on single category only ● Other categories can be sorted during update ● Need parallelize sorting1 ! 1 With RabbitMQ of course!
  • 17.
  • 18. RabbitMQ? ● Multi Protocol Messaging Server ● Open source ● Commercial support ● Messaging via AMQP (Advanced Message Queuing Protocol) ● Supports many programming languages
  • 19. Why we need messaging? ● Separates Job request from the Job ● Jobs can be performed on separate processes and machines ● Workers can be added or removed easily ● Messaging is asynchronous
  • 20. RabbitMQ Basics ● Producer - sends messages ● Consumer - Running process and waiting for messages ● Queue - a buffer that stores messages ● Exchange - distributes messages
  • 21. Simple queue example 1. Producer sends message to named queue 2. Message is stored in queue 3. Consumer takes message from named queue 4. Message removed from queue immediately 5. Consumer “consumes” the message
  • 22. Consumer becoming slow? ● Just run additional consumer ● Round-robin dispatching by default ● Jobs are processed in parallel!
  • 23. What happens if consumer dies? ● Message is lost if worker dies ● The task should be delivered to another worker ● RabbitMQ supports message ACKs ● Message is removed when consumer sends ACK ● ACKs are disabled by default
  • 24. What happens if server dies? ● Messages in queues will be lost ● RabbitMQ supports durable queues ● Queue needs to be re-created as durable if was defined before ● Messages should be sent in “persistent” mode ● RabbitMQ doesn't do fsync(2) for every message - not 100% durable :-)
  • 25. Fair dispatch ● If consumer C1 will get more complex jobs than C2, C1 will be busier all the time. ● Set prefetch_count = 1 property to not to give more than one message to a worker at a time. ● Requires ACKing
  • 26. Let’s think about logging system This will help us understand examples
  • 27. Publish & Subscribe pattern Deliver same message for multiple consumers
  • 28. RabbitMQ Exchanges ● RabbitMQ dogma - producer never sends any messages directly to a queue ● Producer sends messages to an exchange ● A routing_key must be used with messages ● Exchange type describes behavior: ○ Append the message to one/few/all queues ○ Discard the message ○ Types: fanout, direct, topic, headers
  • 29. Temporary Queues ● If no queue is bounded to exchange, messages will be lost. ● Temporary queues are deleted after consumer disconnects. ● Created by consumer when only new messages should be retrieved. ● RabbitMQ supports temporary queues.
  • 30. Listening all messages: Fanout ● Fanout exchange type - send messages to every connected queue ● Temporary queues used ● Routing key ignored by fanout
  • 31. Listening messages subset: Direct ● Direct exchange type - deliver msg to queues with same routing key ● Routing key not ignored anymore ● Multiple bindings can be defined for same queue ● Multiple queues can use same binding key
  • 32. Listening messages by Topic ● Topic exchange type - filter messages by patterns ● Topic is a list of words separated.by.dots ● Subscribing topic patterns: ○ * (asterisk) substitute one word - cron.*.error ○ # (hash) substitute 0 or more words - cron.# ● Topic exchange can behave as fanout or direct
  • 33. Listening messages by Topic Topic pattern: <speed>.<colour>.<species>
  • 34. ● Create and provide callback queue from provider ● Response will be sent to callback queue ● If single callback queue is used per provider, use correlation_id to match request with response ● It is slow and blocking Receiving results: RPC
  • 36. Now you are Ready to work with RabbitMQ Let’s get back to Autosort
  • 38. Scaling Autosort ● Producer sends categories which needs to be sorted ● Exchange type is direct ● Single named queue with ACK and fair dispatch is used ● Consumers are calling CLI commands (can be used for other tasks too)
  • 39. Scaling achievements BEFORE ● 6-8 hours ● Single machine ● Single table for all stores AFTER ● 2-3 hours ● Separate machines ● 10 separate stores! ~28 times faster!
  • 40. RabbitMQ in Boozt.com Services platform & RabbitMQ Boozt store ECCO store Other store Warehouse Accounting Admin system Customer service Messages DB Calls MySQL&Redisclusters Sendgrid
  • 41. Messaging use case #1 Order completed on Store 1. Message sent to Services platform from Store 2. Services sends message to: a. Warehouse to mark products as reserved b. Accounting to register an order c. Sendgrid to send an email
  • 42. Messaging use case #2 Order confirmed on Accounting system 1. Message sent to Services from Accounting 2. Services sends message to: a. Store to mark order as confirmed b. Sendgrid to send an email
  • 43. RabbitMQ ♥ PHP = php-amqplib ● Created by RabbitMQ developer - Alvaro Videla ● Install via composer videlalvaro/php- amqplib or https://github.com/videlalvaro/php-amqplib
  • 44. Dark side of php-amqplib <?php // ... $channel->exchange_declare( 'topic_logs', 'topic', false, false, false); list($queue_name, ,) = $channel->queue_declare( "", false, false, true, false); // Any comments required?
  • 45. How to make sure my consumers are running?
  • 46. Supervisor ● Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems. ● Observes if consumers are running and reloads them if they died
  • 48. Tips for messaging ● Think about using unified workers ● And use priority queues for important tasks (available since v3.5.0) ● Workers as P2P clients ● Use correlation_id for messages
  • 49. Tips for messaging ● Manage your workers with supervisor or similar tool ● Set lifetime for workers (eg. 15 mins) ● Use separate exchanges for separate apps
  • 50. Resources ● https://www.rabbitmq.com - official site and great tutorial ● http://tryrabbitmq.com - RabbitMQ simulator ● https://github.com/rabbitmq/rabbitmq- tutorials/ - Source code of examples ● http://supervisord.org - supervisor
  • 51. ?