SlideShare uma empresa Scribd logo
1 de 59
High performance app in ruby
                                        It works




                                    alexander.mishyn@railsware.com
                                               @omishyn
Wednesday, October 26, 2011
Email Marketing




Wednesday, October 26, 2011
Email Template
               • Custom Fields




Wednesday, October 26, 2011
Email is a personalized template
               • Custom Fields
               • Open Tracking
               • Click Tracking




Wednesday, October 26, 2011
Schema


                                                 Message Transfer
                                                     Agent
                                    Email
                                                  (SMTP server)


                       Database   ActionMailer       Postfix


Wednesday, October 26, 2011
Satisfaction drops down
                              Email   Customer Satisfaction




Wednesday, October 26, 2011
Satisfaction drops down
                                 Email       Customer Satisfaction




                              80000 emails per hour - max
Wednesday, October 26, 2011
Business driven solution
                • Home made Java tool to compose emails
                • Proprietary Message Transfer Agent(MTA)
                  • Momentum




Wednesday, October 26, 2011
Changes


                                              Message Transfer
                                   Email          Agent



                       Database   Java tool     Momentum
                                              Message Systems

Wednesday, October 26, 2011
Changes
                                  Problem




                                              Message Transfer
                                   Email          Agent



                       Database   Java tool     Momentum
                                              Message Systems

Wednesday, October 26, 2011
Road to hell
                • Unable to handle peak load
                • Unable to scale because it kills database
                • Hard to support




Wednesday, October 26, 2011
It doesn’t scale




Wednesday, October 26, 2011
Business needs stability
                              Email   Customer Satisfaction   Desired




Wednesday, October 26, 2011
Requirements
                •      one million emails per hour
                •      horizontal scaling
                •      ability to handle peak load
                •      durability




Wednesday, October 26, 2011
Ruby
                      ruby 1.8.7 REE
               • achieve parallelism by forks
               • daemon-kit gem



                ruby 1.9.2 was unreleased yet
Wednesday, October 26, 2011
Queues
               • RabbitMQ
                 - clients
                   - Bunny
                   - AMQP
                     - uses EventMachine


Wednesday, October 26, 2011
Queues
                  Dispatcher

                               Tasks


                                                Recipients
                               Poller daemons




                                                             Sender daemons
Wednesday, October 26, 2011
Sent emails statistics
               • 1 email produce 2 updates
               • 1_000_000 emails produce 2_000_000 updates
               • Definitely kills Database




Wednesday, October 26, 2011
Aggregate counters

                              Increment key:

         "#{email_campaign_id}_#{email_queue_id}"




Wednesday, October 26, 2011
Use aggregated counts

                                 Extract key:

         "#{email_campaign_id}_#{email_queue_id}"

                              Update counters for:
                               email_campaign_id
                               email_queue_id

Wednesday, October 26, 2011
Less updates

                              1_000_000 emails produce 8_000 updates

                                     ~250x less updates



Wednesday, October 26, 2011
Key Value store
               Tokyo Tyrant
               as persistent storage for precaching




Wednesday, October 26, 2011
Coding
              2 weeks of pair programming




Wednesday, October 26, 2011
And the show begins...




Wednesday, October 26, 2011
Test experiment
               Benchmark:
                    • Test throughput

              Stress test:
                    •Test high load handling




Wednesday, October 26, 2011
Count Size(Kbytes)


              Test data                                                                     151 | 15
                                                                                            120 | 68
                                                                                            109 | 30
                                                                                             13 | 61
                                                                                            8 |116




                Select proper size of email                                68Kb
                to have representative                      30Kb
                results
                                                                         61Kb

                                                     15Kb
                                                                                       116Kb


                 Average email length is 30Kb                Email length clustering


                                    Selected email length is 60Kb
Wednesday, October 26, 2011
Testing

                              throughput
                   high load handling




Wednesday, October 26, 2011
Issues
               • Tokyo Tyrant fails under concurrent key updates
               • RabbitMQ fails on 500_000 messages in queue




Wednesday, October 26, 2011
Solution
               • Redis instead of Tokyo Tyrant
               • RabbitMQ
                 - Queue limited to 300_000 messages
                 - AMQP
                   - Disable routing from broker

Wednesday, October 26, 2011
Testing

                              throughput
                   high load handling




Wednesday, October 26, 2011
Optimize Code
                String        gsub   =>   gsub!
                String        sub    =>   sub!
                String        +=     =>   <<
                Array         map    =>   map!
                ...




               C’mon you know all this, right?
Wednesday, October 26, 2011
Optimize Code

               extra.each do |field, value|          body.gsub!(/__(.*?)__/) do |match|
                 body.gsub!("__#{field}__", value)     extra[$1.to_sym]||''
               end                                   end
               body.gsub!(/__([0-9a-z_-]+)__/, '')

               100000 messages @ 11.8556471347809    100000 messages @ 4.43633253574371




                                                          2.6 times faster

Wednesday, October 26, 2011
Testing

                              throughput
                   high load handling




Wednesday, October 26, 2011
You should see the light
               at the end of tunnel




Wednesday, October 26, 2011
SMTP is slow
               Synchronous execution
               S: 220 smtp.example.com ESMTP Postfix
               C: HELO relay.example.org
               S: 250 Hello relay.example.org, I am glad to meet you


               C: MAIL FROM:<bob@example.org>
               S: 250 Ok
               C: RCPT TO:<alice@example.com>
               S: 250 Ok
               C: DATA
               S: 354 End data with <CR><LF>.<CR><LF>
               C: From: "Bob Example" <bob@example.org>
               C: To: "Alice Example" <alice@example.com>
               C: Cc: theboss@example.com
               C: Date: Tue, 15 Jan 2008 16:02:43 -0500
               C: Subject: Test message
               C:
               C: Hello Alice.
               C: This is a test message with 5 header fields and 4 lines in the message body.
               C: Your friend,
               C: Bob
               C: .
               S: 250 Ok: queued as 12345
               C: QUIT
               S: 221 Bye
               {The server closes the connection}




Wednesday, October 26, 2011
ECStream
                 Internal protocol of our Momentum MTA
                 “Just send C structure to the socket”


                 Wrote C native extension using FFI

                 5-10x faster than SMTP

Wednesday, October 26, 2011
Testing

                              throughput
                   high load handling




Wednesday, October 26, 2011
Launch Planning
                • Delivery
                • Switching
                • Monitoring




Wednesday, October 26, 2011
Parallel systems

                                       Email


                                        Java tool
                                                          Message Transfer
                                                              Agent


                                        Email
                       Database                             Momentum
                                  Email Handling System
Wednesday, October 26, 2011
Production delivery steps
                • Blackhole sending
                • A few customers switch
                • Full switch




Wednesday, October 26, 2011
Got issues




Wednesday, October 26, 2011
Got issues
               We got claims about broken emails

              http://eimages.ratepoint.com => http://eimagesratepoint.com


               •Switch to previous system
               •Figure out the issue
               •The problem is at the Email Providers
Wednesday, October 26, 2011
back to slow SMTP
               CPU is bottle neck




Wednesday, October 26, 2011
back to slow SMTP
               CPU is bottle neck
               Optimize more




Wednesday, October 26, 2011
back to slow SMTP
               CPU is bottle neck
               Optimize more
               Stop




Wednesday, October 26, 2011
back to slow SMTP
               CPU is bottle neck
               Optimize more
               Stop

               Change point of view


Wednesday, October 26, 2011
back to slow SMTP
               CPU is bottle neck
               Optimize more
               Stop

               Change point of view
               Change servers to have
               more CPU and less RAM
Wednesday, October 26, 2011
back to slow SMTP
               CPU is bottle neck
               Optimize more
               Stop

               Change point of view
               Change servers to have
               more CPU and less RAM
Wednesday, October 26, 2011
Testing

                              throughput
                   high load handling




Wednesday, October 26, 2011
Switch to new system



Wednesday, October 26, 2011
Monitoring
               • Scout app
                   - process usage plugin
                   - redis monitoring
                   - server overview
                              more at: https://github.com/railsware/scout-app-plugins
               • Home made realtime monitor


Wednesday, October 26, 2011
Summary



Wednesday, October 26, 2011
Estimation

                              Engineering
               week1                          week8



          Analyzing                         Launching




Wednesday, October 26, 2011
Hosting
                                    2 Quad-core           3 Quad-core
                                    Xeon 2.83GHz          Xeon 2.00GHz



                                                          Message Transfer
                                         Email                Agent



                       Database   Email Handling system     Momentum
                                                          Message Systems

Wednesday, October 26, 2011
Email Handling System
                • Horizontally scalable
                  • 1 million emails per/hour (one server)
                    • RabbitMQ (Clustered)
                    • Redis
                    • 17 ruby daemons



Wednesday, October 26, 2011
Distribution
                                                               Sent emails

                              6000000



                              4500000



                              3000000



                              1500000



                                   0
                                   Sunday   Monday   Tuesday   Wednesday     Thursday   Friday   Saturday


Wednesday, October 26, 2011
So that ...


Wednesday, October 26, 2011
1_000_000_000
                                emails in 2010

Wednesday, October 26, 2011
Questions

Wednesday, October 26, 2011

Mais conteúdo relacionado

Último

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Último (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

High performance app in ruby

  • 1. High performance app in ruby It works alexander.mishyn@railsware.com @omishyn Wednesday, October 26, 2011
  • 3. Email Template • Custom Fields Wednesday, October 26, 2011
  • 4. Email is a personalized template • Custom Fields • Open Tracking • Click Tracking Wednesday, October 26, 2011
  • 5. Schema Message Transfer Agent Email (SMTP server) Database ActionMailer Postfix Wednesday, October 26, 2011
  • 6. Satisfaction drops down Email Customer Satisfaction Wednesday, October 26, 2011
  • 7. Satisfaction drops down Email Customer Satisfaction 80000 emails per hour - max Wednesday, October 26, 2011
  • 8. Business driven solution • Home made Java tool to compose emails • Proprietary Message Transfer Agent(MTA) • Momentum Wednesday, October 26, 2011
  • 9. Changes Message Transfer Email Agent Database Java tool Momentum Message Systems Wednesday, October 26, 2011
  • 10. Changes Problem Message Transfer Email Agent Database Java tool Momentum Message Systems Wednesday, October 26, 2011
  • 11. Road to hell • Unable to handle peak load • Unable to scale because it kills database • Hard to support Wednesday, October 26, 2011
  • 12. It doesn’t scale Wednesday, October 26, 2011
  • 13. Business needs stability Email Customer Satisfaction Desired Wednesday, October 26, 2011
  • 14. Requirements • one million emails per hour • horizontal scaling • ability to handle peak load • durability Wednesday, October 26, 2011
  • 15. Ruby ruby 1.8.7 REE • achieve parallelism by forks • daemon-kit gem ruby 1.9.2 was unreleased yet Wednesday, October 26, 2011
  • 16. Queues • RabbitMQ - clients - Bunny - AMQP - uses EventMachine Wednesday, October 26, 2011
  • 17. Queues Dispatcher Tasks Recipients Poller daemons Sender daemons Wednesday, October 26, 2011
  • 18. Sent emails statistics • 1 email produce 2 updates • 1_000_000 emails produce 2_000_000 updates • Definitely kills Database Wednesday, October 26, 2011
  • 19. Aggregate counters Increment key: "#{email_campaign_id}_#{email_queue_id}" Wednesday, October 26, 2011
  • 20. Use aggregated counts Extract key: "#{email_campaign_id}_#{email_queue_id}" Update counters for: email_campaign_id email_queue_id Wednesday, October 26, 2011
  • 21. Less updates 1_000_000 emails produce 8_000 updates ~250x less updates Wednesday, October 26, 2011
  • 22. Key Value store Tokyo Tyrant as persistent storage for precaching Wednesday, October 26, 2011
  • 23. Coding 2 weeks of pair programming Wednesday, October 26, 2011
  • 24. And the show begins... Wednesday, October 26, 2011
  • 25. Test experiment Benchmark: • Test throughput Stress test: •Test high load handling Wednesday, October 26, 2011
  • 26. Count Size(Kbytes) Test data 151 | 15 120 | 68 109 | 30 13 | 61 8 |116 Select proper size of email 68Kb to have representative 30Kb results 61Kb 15Kb 116Kb Average email length is 30Kb Email length clustering Selected email length is 60Kb Wednesday, October 26, 2011
  • 27. Testing throughput high load handling Wednesday, October 26, 2011
  • 28. Issues • Tokyo Tyrant fails under concurrent key updates • RabbitMQ fails on 500_000 messages in queue Wednesday, October 26, 2011
  • 29. Solution • Redis instead of Tokyo Tyrant • RabbitMQ - Queue limited to 300_000 messages - AMQP - Disable routing from broker Wednesday, October 26, 2011
  • 30. Testing throughput high load handling Wednesday, October 26, 2011
  • 31. Optimize Code String gsub => gsub! String sub => sub! String += => << Array map => map! ... C’mon you know all this, right? Wednesday, October 26, 2011
  • 32. Optimize Code extra.each do |field, value| body.gsub!(/__(.*?)__/) do |match| body.gsub!("__#{field}__", value) extra[$1.to_sym]||'' end end body.gsub!(/__([0-9a-z_-]+)__/, '') 100000 messages @ 11.8556471347809 100000 messages @ 4.43633253574371 2.6 times faster Wednesday, October 26, 2011
  • 33. Testing throughput high load handling Wednesday, October 26, 2011
  • 34. You should see the light at the end of tunnel Wednesday, October 26, 2011
  • 35. SMTP is slow Synchronous execution S: 220 smtp.example.com ESMTP Postfix C: HELO relay.example.org S: 250 Hello relay.example.org, I am glad to meet you C: MAIL FROM:<bob@example.org> S: 250 Ok C: RCPT TO:<alice@example.com> S: 250 Ok C: DATA S: 354 End data with <CR><LF>.<CR><LF> C: From: "Bob Example" <bob@example.org> C: To: "Alice Example" <alice@example.com> C: Cc: theboss@example.com C: Date: Tue, 15 Jan 2008 16:02:43 -0500 C: Subject: Test message C: C: Hello Alice. C: This is a test message with 5 header fields and 4 lines in the message body. C: Your friend, C: Bob C: . S: 250 Ok: queued as 12345 C: QUIT S: 221 Bye {The server closes the connection} Wednesday, October 26, 2011
  • 36. ECStream Internal protocol of our Momentum MTA “Just send C structure to the socket” Wrote C native extension using FFI 5-10x faster than SMTP Wednesday, October 26, 2011
  • 37. Testing throughput high load handling Wednesday, October 26, 2011
  • 38. Launch Planning • Delivery • Switching • Monitoring Wednesday, October 26, 2011
  • 39. Parallel systems Email Java tool Message Transfer Agent Email Database Momentum Email Handling System Wednesday, October 26, 2011
  • 40. Production delivery steps • Blackhole sending • A few customers switch • Full switch Wednesday, October 26, 2011
  • 42. Got issues We got claims about broken emails http://eimages.ratepoint.com => http://eimagesratepoint.com •Switch to previous system •Figure out the issue •The problem is at the Email Providers Wednesday, October 26, 2011
  • 43. back to slow SMTP CPU is bottle neck Wednesday, October 26, 2011
  • 44. back to slow SMTP CPU is bottle neck Optimize more Wednesday, October 26, 2011
  • 45. back to slow SMTP CPU is bottle neck Optimize more Stop Wednesday, October 26, 2011
  • 46. back to slow SMTP CPU is bottle neck Optimize more Stop Change point of view Wednesday, October 26, 2011
  • 47. back to slow SMTP CPU is bottle neck Optimize more Stop Change point of view Change servers to have more CPU and less RAM Wednesday, October 26, 2011
  • 48. back to slow SMTP CPU is bottle neck Optimize more Stop Change point of view Change servers to have more CPU and less RAM Wednesday, October 26, 2011
  • 49. Testing throughput high load handling Wednesday, October 26, 2011
  • 50. Switch to new system Wednesday, October 26, 2011
  • 51. Monitoring • Scout app - process usage plugin - redis monitoring - server overview more at: https://github.com/railsware/scout-app-plugins • Home made realtime monitor Wednesday, October 26, 2011
  • 53. Estimation Engineering week1 week8 Analyzing Launching Wednesday, October 26, 2011
  • 54. Hosting 2 Quad-core 3 Quad-core Xeon 2.83GHz Xeon 2.00GHz Message Transfer Email Agent Database Email Handling system Momentum Message Systems Wednesday, October 26, 2011
  • 55. Email Handling System • Horizontally scalable • 1 million emails per/hour (one server) • RabbitMQ (Clustered) • Redis • 17 ruby daemons Wednesday, October 26, 2011
  • 56. Distribution Sent emails 6000000 4500000 3000000 1500000 0 Sunday Monday Tuesday Wednesday Thursday Friday Saturday Wednesday, October 26, 2011
  • 57. So that ... Wednesday, October 26, 2011
  • 58. 1_000_000_000 emails in 2010 Wednesday, October 26, 2011