SlideShare uma empresa Scribd logo
1 de 79
Escalabilidade - Do S.O. ao Rails
                                         Bruno Andrade Alves
                                         bruno@dito.com.br




segunda-feira, 28 de fevereiro de 2011
Ideia




segunda-feira, 28 de fevereiro de 2011
Execução




segunda-feira, 28 de fevereiro de 2011
Publicação




segunda-feira, 28 de fevereiro de 2011
Divulgação




segunda-feira, 28 de fevereiro de 2011
Utilização




segunda-feira, 28 de fevereiro de 2011
Satisfação




segunda-feira, 28 de fevereiro de 2011
O que aconteceu?




segunda-feira, 28 de fevereiro de 2011
Solução imediata




segunda-feira, 28 de fevereiro de 2011
Feliz novamente




segunda-feira, 28 de fevereiro de 2011
Produto é um sucesso!




segunda-feira, 28 de fevereiro de 2011
#fail :(




segunda-feira, 28 de fevereiro de 2011
Aplicativo no orkut, facebook e portal de futebol
           com mais de 940 mil usuários cadastrados e mais
           de 50 milhões de apostas




segunda-feira, 28 de fevereiro de 2011
Game educativo para orkut para combate da dengue com
   mais de 850 mil usuários cadastrados em menos de 2
                          meses




segunda-feira, 28 de fevereiro de 2011
Solução utilizada em grande parte dos e-commerces
                         brasileiros dentre eles:




segunda-feira, 28 de fevereiro de 2011
Aplicativo no orkut e no facebook com milhões de
                           usuários impactados




segunda-feira, 28 de fevereiro de 2011
Primeiro organizador de compra coletivas do Brasil




segunda-feira, 28 de fevereiro de 2011
Fluxo de uma aplicação web




segunda-feira, 28 de fevereiro de 2011
Identifique o gargalo



segunda-feira, 28 de fevereiro de 2011
segunda-feira, 28 de fevereiro de 2011
Pontos de otimização para a camada
                 do browser

                                             CSS
                                          Javascript
                                            Cache
                                           Imagens
                                         Requisições




segunda-feira, 28 de fevereiro de 2011
Ferramentas
                                         YSlow         Google Page speed




segunda-feira, 28 de fevereiro de 2011
Gargalo no servidor web




                                                +




segunda-feira, 28 de fevereiro de 2011
Gargalo no servidor web


           Verificar número máximo de clientes configurada
           (maxclients)

           KeepAlive

           KeepAliveTimeout




segunda-feira, 28 de fevereiro de 2011
Apache Server Status




                                                              Existem
                                                            workers livres



segunda-feira, 28 de fevereiro de 2011
passenger-status




segunda-feira, 28 de fevereiro de 2011
passenger-status




segunda-feira, 28 de fevereiro de 2011
passenger-status




                                                  GARGALO


segunda-feira, 28 de fevereiro de 2011
Gargalo na aplicação




segunda-feira, 28 de fevereiro de 2011
Como identificar gargalos na
                            aplicação?




segunda-feira, 28 de fevereiro de 2011
Newrelic




segunda-feira, 28 de fevereiro de 2011
Newrelic



tempo médio
de requisição
     36s
                                                     SELECT está
                                                    demorando 4,8s




segunda-feira, 28 de fevereiro de 2011
Acompanhe o log durante o
                             desenvolvimento




segunda-feira, 28 de fevereiro de 2011
Realize operações pesadas de modo
                  assíncrono

  DelayedJob
  Resque

  Permitem criar uma fila de jobs para serem executados,
  ex.: Envio de emails, atualização de timeline de amigos, etc.




segunda-feira, 28 de fevereiro de 2011
Problema Odrible.com



Com o crescimento dos usuários o ranking passou a
demorar mais de 1 dia para executar




segunda-feira, 28 de fevereiro de 2011
Fatores complicadores


Grande parte do processamento da regra de negócio era
feita no ruby




segunda-feira, 28 de fevereiro de 2011
Fatores complicadores

Grande parte do processamento da regra de negócio era
feita no ruby

Muito tráfego de dados entre o MySQL e o Ruby




segunda-feira, 28 de fevereiro de 2011
Fatores complicadores

Grande parte do processamento da regra de negócio era
feita no ruby

Muito tráfego de dados entre o MySQL e o Ruby

Estrutura de dados não estava otimizada para o
processamento




segunda-feira, 28 de fevereiro de 2011
Solução


                            Desnormalizar base, otimizando a estrutura




segunda-feira, 28 de fevereiro de 2011
Solução
Desnormalizar base, otimizando a estrutura

A ordenação do ranking foi substituída de:




segunda-feira, 28 de fevereiro de 2011
Solução
Desnormalizar base, otimizando o processamento

A ordenação do ranking foi substituída de:




  Por:




segunda-feira, 28 de fevereiro de 2011
Solução
Desnormalizar base, otimizando o processamento

A ordenação do ranking foi substituída de:




  Por:                                             Processamento no banco




segunda-feira, 28 de fevereiro de 2011
Problema no parser de XML


O parser de XML desenvolvido passava em todos os
testes, porém quando foi para produção o XML aumentou
de tamanho e o tempo de processamento ficou inviável




segunda-feira, 28 de fevereiro de 2011
Solução


        O parser que utilizava a biblioteca rexml teve que ser
        reescrito utilizando a bliblioteca nokogiri




segunda-feira, 28 de fevereiro de 2011
Conclusão


        Quando for utilizar bibliotecas, procure saber de sua
        performance antes de começar a implementação




segunda-feira, 28 de fevereiro de 2011
Gargalo no banco de dados




segunda-feira, 28 de fevereiro de 2011
MySQLTuner




segunda-feira, 28 de fevereiro de 2011
MySQLTuner

    apenas 100MB de
    um banco 3,9 GB
    está em memória




segunda-feira, 28 de fevereiro de 2011
MySQLTuner

    apenas 100MB de
    um banco 3,9 GB
    está em memória




     Leia as
recomendações
   e procure
  entender o
   significado


segunda-feira, 28 de fevereiro de 2011
MySQL

                             Procure manter o máximo possível do banco
                             em memória

                             Performance muito mais lenta quando se
                             utiliza disco

                             Ative o log de slow queries para ajudar a
                             identificar as queries que estão pesando o BD




segunda-feira, 28 de fevereiro de 2011
MySQL
                             Para fulltext search utilize algum servidor de
                             busca por ex.: Solr e Sphinx

                             Utilizar índice nas tabelas quando necessário

                             Utilizar o “Explain” nas queries para verificar o
                             seu comportamento e otimizá-las se for o
                             caso

                             mysqlperformanceblog.com




segunda-feira, 28 de fevereiro de 2011
Problema Odrible.com

                             Muitas apostas antigas que devem ser
                             guardadas porém pouco acessadas




segunda-feira, 28 de fevereiro de 2011
Solução:


                             Passar dados armazenados na engine InnoDB
                             para Archive que gastam quase 83% menos
                             espaço




segunda-feira, 28 de fevereiro de 2011
Resultado


                             Necessário menos memória para suportar
                             todo o banco em memória




segunda-feira, 28 de fevereiro de 2011
Fluxo de uma aplicação web




segunda-feira, 28 de fevereiro de 2011
Fluxo de uma aplicação web
                              Cache
                              (Varnish, Squid)




segunda-feira, 28 de fevereiro de 2011
Fluxo de uma aplicação web
                              Cache               Cache
                                                 (Page cache,action
                              (Varnish, Squid)    cache, fragment
                                                       cache)




segunda-feira, 28 de fevereiro de 2011
Fluxo de uma aplicação web
                              Cache               Cache               Cache
                                                 (Page cache,action
                              (Varnish, Squid)    cache, fragment     (Memcached)
                                                       cache)




segunda-feira, 28 de fevereiro de 2011
Conclusão?




segunda-feira, 28 de fevereiro de 2011
Cache




segunda-feira, 28 de fevereiro de 2011
Cache

                                         Cache




segunda-feira, 28 de fevereiro de 2011
Cache

                                         Cache

                                         Cache


segunda-feira, 28 de fevereiro de 2011
Faça benchmarks




segunda-feira, 28 de fevereiro de 2011
Tudo deve ser monitorado!




segunda-feira, 28 de fevereiro de 2011
Como monitorar?




segunda-feira, 28 de fevereiro de 2011
Como monitorar?
          Nagios, Munin dentre outros




segunda-feira, 28 de fevereiro de 2011
Como monitorar?
                     Geração de gráficos




segunda-feira, 28 de fevereiro de 2011
Como monitorar?
               Monitoramento proativo




segunda-feira, 28 de fevereiro de 2011
Analytics para página de erros
                        Permite acompanhar o resultado para o usuário final das soluções adotadas




segunda-feira, 28 de fevereiro de 2011
Se o gargalo for hardware?




segunda-feira, 28 de fevereiro de 2011
Escalabilidade vertical




segunda-feira, 28 de fevereiro de 2011
Escalabilidade horizontal




segunda-feira, 28 de fevereiro de 2011
Escalabilidade horizontal

  Infra boo-box

  + 5 bilhões de
  impressões
  em 2010

  Fonte: booblog.boo-box.com




segunda-feira, 28 de fevereiro de 2011
Não existe receita para escalabilidade




segunda-feira, 28 de fevereiro de 2011
Cada caso deve ser analisado
                            separadamente




segunda-feira, 28 de fevereiro de 2011
Não se prenda a uma tecnologia.
      Utilize a melhor para resolver o seu
                    problema



segunda-feira, 28 de fevereiro de 2011
Perguntas?




segunda-feira, 28 de fevereiro de 2011
Referências

                             http://highscalability.com/
                             http://www.mysqlperformanceblog.com/
                             http://railslab.newrelic.com/scaling-rails




segunda-feira, 28 de fevereiro de 2011
Obrigado!
                                         Bruno Andrade Alves
                                         bruno@dito.com.br




segunda-feira, 28 de fevereiro de 2011

Mais conteúdo relacionado

Destaque

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
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)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
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
 

Como Otimizar Desempenho de Aplicações Web