SlideShare a Scribd company logo
1 of 63
Download to read offline
Say YES to
premature
optimizations
@qcmaude
I work on
performance at
Slack.
> About me
> About me
1. Insights into the Slack backend
2. Small, easy performance improvements
3. Slightly larger, more difficult improvements
4. Thinking at scale
5. Developing a long term plan
> Table of contents
Once upon a time …
some folks created a messaging
platform called .
> Backend architecture overview
> Backend architecture overview
~ 2 GB
> Backend architecture overview
+ message server (Java)
+ edge cache (Go)
> Backend architecture overview
6M+ daily active users today
*gulp*
> Backend architecture overview
1. Performance monitoring
>
> Performance monitoring > use cases
• A little obvious:
• Track the performance of an existing codepath
• Track the performance of a new codepath
• Keep an eye on overall application
> Performance monitoring > use cases
Given you have access to a system that aggregates
data for consumption later, you just need to:
1. import a library
2. call a function
> Performance monitoring > in practice
loadlib(‘statsd’);
function do_an_expensive_thing($lots_of_data){
    $start = time();

    foreach($lots_of_data as $chunk){
existing_function_one($chunk);
existing_function_two();
statsd_count("$env.expensive_thing.loop_count");
    }
    $end = time();
    statsd_timing("$env.expensive_thing.loop_timing", $end-$start);
    return;
}
Request a New
Workspace
> Performance monitoring > at Slack
> Performance monitoring > in practice
> Performance monitoring > at Slack
> Performance monitoring > trade-offs
Cons
• Storing lots of data is expensive
• Knowing what specificity to monitor is tough
Pros
• You’re better off having more performance data than
not enough
• Easy to set up alerting in the background
>
2. Add rate limits
• Used by most companies with publicly-
facing APIs
• Prevent servers from coming under
unhealthy load
• Prevent spamming
> Add rate limits > use cases
> Add rate limits > in practice
109.29.287
POST /invite
+1
109.29.287
POST /invite
101 4mes/1 min
429: Too
Many Requests
memcached
> Add rate limits > in practice
xoxp-8314999681-…
POST chat.postMessage
+1
hash(xoxp-8314999681-…)
chat.postMessage
101 4mes/1 min
429: Too
Many Requests
Retry AMer: 1 sec
> Add rate limits > at Slack
• Externally (API) & internally (enqueuing jobs)
• Rate limit individual methods keyed by some
entity (user, team, channel, globally, etc.)
hNps://api.slack.com/docs/rate-limits
> Add rate limits > at Slack
> Add rate limits > trade-offs
Cons
• Picking the right number is difficult
• Risk potentially annoying your users
Pros
• Always safer to have them in place
• Easily tweaked to handle growing # of users
• Easier to opt users into rate limits from the beginning
> Paginate
3. Paginate
> Paginate > use cases
+
function do_a_thing_for_many_channels($channels){
    $all_members = array();
    $channel_ids = array_column($channels, 'id');
    $chunk = array_slice($channel_ids, 0, 1000);
    return query("SELECT * FROM members
WHERE channel_id IN $chunk");
}
> Paginate > in practice
> Cheaper by the dozen > at Slack
https://api.slack.com/methods/users.list
Cons
• Picking the right number is hard, but thankfully not a
big deal
• Clients may need to make multiple calls to get full lists
Pros
• Always safer to have
• Easier to opt users into pagination from the beginning
> Paginate > trade-offs
>
4. Cache, cache, cache
Generally, it is best to cache one or a combination of:
• data that changes very little
• data that is expensive to calculate
• data that is accessed often
• data derived from multiple sources
> Cache, cache, cache > use cases
How old is my mom?
> Cache, cache, cache > use cases
locally
remotely
database
> Cache, cache, cache > in practice
Within a single request

• No network cost
• Invalidation unnecessary
• No TTL (time to life)
> Cache, cache, cache > in practice
> Cache, cache, cache > in practice
On the web server

• No network cost
• Invalidation difficult
• Tiny TTL is best
> Cache, cache, cache > in practice
In a distributed,
remote caching tier

• Some network cost
• Invalidation easy
• Flexible TTL
locally
remotely
database
$GLOBALS,
apc,
<<__Memoize>>
memcached
MySQL
> Cache, cache, cache > at Slack
Cons
• Invalidation is hard
• Storing lots of data in a remote caching tier is expensive
Pros
• Generally, it’s an easy, quick win to store reasonable
amounts of data within the context of your request
• Although speed of a request might not increase, you’re
saving load on the database
> Cache, cache, cache > trade-offs
5. Make it asynchronous
>
> Make it asynchronous > use cases
• You have a task that
• can be split into independent subtasks
• doesn’t need to complete right away
> Make it asynchronous > use cases
Making a pie
>
just me
1. prepare the crust 2. prepare the filling 3. combine 4. bake
with some help
> Make it asynchronous > use cases
1. prepare the crust
1. prepare the filling
2. combine 3. bake
async function curl_A(): Awaitable<string> {
$x = await HHAsiocurl_exec("http://example.com/");
return $x;
}
async function curl_B(): Awaitable<string> {
$y = await HHAsiocurl_exec("http://example.net/");
return $y;
}
async function async_curl(): Awaitable<void> {
$start = microtime(true);
list($a, $b) = await HHAsiov(array(curl_A(), curl_B()));
$end = microtime(true);
echo "Total time taken: " . strval($end - $start) . " seconds" . PHP_EOL;
}
HHAsiojoin(async_curl());
> Make it asynchronous > in practice > language constructs
function do_something_asynchronously($something){
    # Get some data.
    $other_data = get_more_than_something($something);
    job_queue_enqueue('async_task', 'special_queue', array(
            'something'     => $something,
            'other_data'    => $other_data,
    ));
    return;
}
> Make it asynchronous > in practice > job queue
>> Make it asynchronous > at Slack
channels.archive
function channel_archive($channel, $archiver){
    # Get members
    foreach($members as $member){
        send_message($member, "Channel $channel['name'] was archived.");
        remove_member($member, $channel);
        send_client_event($member, "leave_channel");
    }
    send_message($archiver, "Channel $channel['name'] was archived.");
    return;
}
> Make it asynchronous > at Slack
>
What happens when
we archive a channel
with 500 users?
> Make it asynchronous > at Slack
function channel_archive($channel, $archiver){
    schedule_job(($channel, $archiver) ==> channel_archive_process_members(
$channel, $archiver));
    send_message($archiver, "Channel $channel['name'] is being archived.");
    return;
}
function channel_archive_process_members($channel, $archiver){
    # Get members
    foreach($members as $member){
        send_message($member, "Channel $channel['name'] was archived.");
        remove_member($member, $channel);
        send_client_event($member, "leave_channel");
    }
    send_message($archiver, "Channel $channel['name'] was archived.");
    return;
}
> Make it asynchronous > at Slack
What happens when
we archive a channel
with 17,000 users?
> Make it asynchronous > at Slack
function channel_archive($channel){
    schedule_job(($channel, $archiver) ==> channel_archive_process_members(
$channel, $archiver));
    send_message($archiver, "Channel $channel['name'] is being archived.");
    return;
}
function channel_archive_process_members($channel, $archiver){
    # Get members
    foreach($members as $member){
        schedule_job(($channel, $member) ==> channel_archive_process_single_member(
$channel, $member), 200);
    }
    return;
}
function channel_archive_process_single_member($member){
    send_message($member, "Channel $channel['name'] was archived.");
    remove_member($member, $channel);
    send_client_event($member, "leave_channel");
    return;
}
> Make it asynchronous > at Slack
Cons
• Unexpected behavior due to ordering
• Fault tolerance becomes tricky
• Too many jobs can cause overflowing queues
Pros
• If you know the operation could take a while and the
result of the operation has no bearing on subsequent
code, then offload to a queue.
> Make it asynchronous > at Slack
>
6. Tiered degrada4on.
> Tiered degradation plan > use cases
> Tiered degradation plan> Tiered degradation plan > use cases
> Tiered degradation plan > use cases
> Tiered degradation plan > use cases
> Tiered degradation plan > use cases
1. Absolutely necessary
2. Popular features
3. Mostly everything else
> Tiered degradation plan > in practice
• Set job queue priorities
• Ensure clients exponentially back-off
struggling API endpoints
• Use internal rate limits
• Respond appropriately to error codes
> Tiered degradation plan > in practice
We’ve yet to
figure this out
ourselves!
> Tiered degradation plan > at Slack
Cons
• Building out a tiered degradation plan takes lots of effort
from both product and engineering folks across the entire
company.
Pros
• If it’s already in place, understanding where your feature fits
in is the key to ensuring the best experience for your users.
> Tiered degradation plan > use cases
7. Iterate
>
Thank you!
@qcmaude

More Related Content

What's hot

Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansibleahamilton55
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShellDale Lane
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode ChefSri Ram
 
HBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBaseHBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBaseMichael Stack
 
Oracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesOracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesKim Berg Hansen
 
Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2benjaminwootton
 
Cassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A ComparisonCassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A Comparisonshsedghi
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringJoe Kutner
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerKidong Lee
 
Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Viet-Dung TRINH
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebeanFaren faren
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPAFaren faren
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Chef
 
Streamline Hadoop DevOps with Apache Ambari
Streamline Hadoop DevOps with Apache AmbariStreamline Hadoop DevOps with Apache Ambari
Streamline Hadoop DevOps with Apache AmbariAlejandro Fernandez
 
Cooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with ChefCooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with ChefG. Ryan Fawcett
 

What's hot (20)

Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode Chef
 
HBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBaseHBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBase
 
Oracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesOracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web Services
 
Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2
 
Cassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A ComparisonCassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A Comparison
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
Chef advance
Chef advanceChef advance
Chef advance
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and Spring
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
Hadoop on osx
Hadoop on osxHadoop on osx
Hadoop on osx
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-docker
 
Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebean
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
 
Streamline Hadoop DevOps with Apache Ambari
Streamline Hadoop DevOps with Apache AmbariStreamline Hadoop DevOps with Apache Ambari
Streamline Hadoop DevOps with Apache Ambari
 
Varnish 4 cool features
Varnish 4 cool featuresVarnish 4 cool features
Varnish 4 cool features
 
Cooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with ChefCooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with Chef
 

Similar to Say YES to Premature Optimizations

Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) RoundupWayne Carter
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsConcentric Sky
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPkatzgrau
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011CodeIgniter Conference
 
Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek PROIDEA
 
Docker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic StackDocker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic StackJakub Hajek
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Studyhernanibf
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACPerformance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACKristofferson A
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesDoris Chen
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsUlf Wendel
 
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...Nagios
 

Similar to Say YES to Premature Optimizations (20)

Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) Roundup
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek
 
Docker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic StackDocker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic Stack
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACPerformance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
php & performance
 php & performance php & performance
php & performance
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
 

Recently uploaded

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
 
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
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
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
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
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
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
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
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 

Recently uploaded (20)

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
 
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-...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
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
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
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 🔝✔️✔️
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
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
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Say YES to Premature Optimizations

  • 2. I work on performance at Slack. > About me
  • 4. 1. Insights into the Slack backend 2. Small, easy performance improvements 3. Slightly larger, more difficult improvements 4. Thinking at scale 5. Developing a long term plan > Table of contents
  • 5. Once upon a time … some folks created a messaging platform called . > Backend architecture overview
  • 7. ~ 2 GB > Backend architecture overview + message server (Java) + edge cache (Go)
  • 8. > Backend architecture overview 6M+ daily active users today
  • 11. > Performance monitoring > use cases • A little obvious: • Track the performance of an existing codepath • Track the performance of a new codepath • Keep an eye on overall application
  • 12. > Performance monitoring > use cases Given you have access to a system that aggregates data for consumption later, you just need to: 1. import a library 2. call a function
  • 13. > Performance monitoring > in practice loadlib(‘statsd’); function do_an_expensive_thing($lots_of_data){     $start = time();
     foreach($lots_of_data as $chunk){ existing_function_one($chunk); existing_function_two(); statsd_count("$env.expensive_thing.loop_count");     }     $end = time();     statsd_timing("$env.expensive_thing.loop_timing", $end-$start);     return; }
  • 14. Request a New Workspace > Performance monitoring > at Slack
  • 15. > Performance monitoring > in practice
  • 17. > Performance monitoring > trade-offs Cons • Storing lots of data is expensive • Knowing what specificity to monitor is tough Pros • You’re better off having more performance data than not enough • Easy to set up alerting in the background
  • 18. > 2. Add rate limits
  • 19. • Used by most companies with publicly- facing APIs • Prevent servers from coming under unhealthy load • Prevent spamming > Add rate limits > use cases
  • 20. > Add rate limits > in practice 109.29.287 POST /invite +1 109.29.287 POST /invite 101 4mes/1 min 429: Too Many Requests
  • 21. memcached > Add rate limits > in practice xoxp-8314999681-… POST chat.postMessage +1 hash(xoxp-8314999681-…) chat.postMessage 101 4mes/1 min 429: Too Many Requests Retry AMer: 1 sec
  • 22. > Add rate limits > at Slack • Externally (API) & internally (enqueuing jobs) • Rate limit individual methods keyed by some entity (user, team, channel, globally, etc.)
  • 24. > Add rate limits > trade-offs Cons • Picking the right number is difficult • Risk potentially annoying your users Pros • Always safer to have them in place • Easily tweaked to handle growing # of users • Easier to opt users into rate limits from the beginning
  • 26. > Paginate > use cases +
  • 27. function do_a_thing_for_many_channels($channels){     $all_members = array();     $channel_ids = array_column($channels, 'id');     $chunk = array_slice($channel_ids, 0, 1000);     return query("SELECT * FROM members WHERE channel_id IN $chunk"); } > Paginate > in practice
  • 28. > Cheaper by the dozen > at Slack https://api.slack.com/methods/users.list
  • 29. Cons • Picking the right number is hard, but thankfully not a big deal • Clients may need to make multiple calls to get full lists Pros • Always safer to have • Easier to opt users into pagination from the beginning > Paginate > trade-offs
  • 31. Generally, it is best to cache one or a combination of: • data that changes very little • data that is expensive to calculate • data that is accessed often • data derived from multiple sources > Cache, cache, cache > use cases
  • 32. How old is my mom? > Cache, cache, cache > use cases
  • 34. Within a single request
 • No network cost • Invalidation unnecessary • No TTL (time to life) > Cache, cache, cache > in practice
  • 35. > Cache, cache, cache > in practice On the web server
 • No network cost • Invalidation difficult • Tiny TTL is best
  • 36. > Cache, cache, cache > in practice In a distributed, remote caching tier
 • Some network cost • Invalidation easy • Flexible TTL
  • 38. Cons • Invalidation is hard • Storing lots of data in a remote caching tier is expensive Pros • Generally, it’s an easy, quick win to store reasonable amounts of data within the context of your request • Although speed of a request might not increase, you’re saving load on the database > Cache, cache, cache > trade-offs
  • 39. 5. Make it asynchronous >
  • 40. > Make it asynchronous > use cases • You have a task that • can be split into independent subtasks • doesn’t need to complete right away
  • 41. > Make it asynchronous > use cases Making a pie
  • 42. > just me 1. prepare the crust 2. prepare the filling 3. combine 4. bake with some help > Make it asynchronous > use cases 1. prepare the crust 1. prepare the filling 2. combine 3. bake
  • 43. async function curl_A(): Awaitable<string> { $x = await HHAsiocurl_exec("http://example.com/"); return $x; } async function curl_B(): Awaitable<string> { $y = await HHAsiocurl_exec("http://example.net/"); return $y; } async function async_curl(): Awaitable<void> { $start = microtime(true); list($a, $b) = await HHAsiov(array(curl_A(), curl_B())); $end = microtime(true); echo "Total time taken: " . strval($end - $start) . " seconds" . PHP_EOL; } HHAsiojoin(async_curl()); > Make it asynchronous > in practice > language constructs
  • 44. function do_something_asynchronously($something){     # Get some data.     $other_data = get_more_than_something($something);     job_queue_enqueue('async_task', 'special_queue', array(             'something'     => $something,             'other_data'    => $other_data,     ));     return; } > Make it asynchronous > in practice > job queue
  • 45. >> Make it asynchronous > at Slack channels.archive
  • 46. function channel_archive($channel, $archiver){     # Get members     foreach($members as $member){         send_message($member, "Channel $channel['name'] was archived.");         remove_member($member, $channel);         send_client_event($member, "leave_channel");     }     send_message($archiver, "Channel $channel['name'] was archived.");     return; } > Make it asynchronous > at Slack
  • 47. > What happens when we archive a channel with 500 users? > Make it asynchronous > at Slack
  • 48. function channel_archive($channel, $archiver){     schedule_job(($channel, $archiver) ==> channel_archive_process_members( $channel, $archiver));     send_message($archiver, "Channel $channel['name'] is being archived.");     return; } function channel_archive_process_members($channel, $archiver){     # Get members     foreach($members as $member){         send_message($member, "Channel $channel['name'] was archived.");         remove_member($member, $channel);         send_client_event($member, "leave_channel");     }     send_message($archiver, "Channel $channel['name'] was archived.");     return; } > Make it asynchronous > at Slack
  • 49. What happens when we archive a channel with 17,000 users? > Make it asynchronous > at Slack
  • 50. function channel_archive($channel){     schedule_job(($channel, $archiver) ==> channel_archive_process_members( $channel, $archiver));     send_message($archiver, "Channel $channel['name'] is being archived.");     return; } function channel_archive_process_members($channel, $archiver){     # Get members     foreach($members as $member){         schedule_job(($channel, $member) ==> channel_archive_process_single_member( $channel, $member), 200);     }     return; } function channel_archive_process_single_member($member){     send_message($member, "Channel $channel['name'] was archived.");     remove_member($member, $channel);     send_client_event($member, "leave_channel");     return; } > Make it asynchronous > at Slack
  • 51. Cons • Unexpected behavior due to ordering • Fault tolerance becomes tricky • Too many jobs can cause overflowing queues Pros • If you know the operation could take a while and the result of the operation has no bearing on subsequent code, then offload to a queue. > Make it asynchronous > at Slack
  • 53. > Tiered degradation plan > use cases
  • 54. > Tiered degradation plan> Tiered degradation plan > use cases
  • 55. > Tiered degradation plan > use cases
  • 56. > Tiered degradation plan > use cases
  • 57. > Tiered degradation plan > use cases
  • 58. 1. Absolutely necessary 2. Popular features 3. Mostly everything else > Tiered degradation plan > in practice
  • 59. • Set job queue priorities • Ensure clients exponentially back-off struggling API endpoints • Use internal rate limits • Respond appropriately to error codes > Tiered degradation plan > in practice
  • 60. We’ve yet to figure this out ourselves! > Tiered degradation plan > at Slack
  • 61. Cons • Building out a tiered degradation plan takes lots of effort from both product and engineering folks across the entire company. Pros • If it’s already in place, understanding where your feature fits in is the key to ensuring the best experience for your users. > Tiered degradation plan > use cases