SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
Estratégias de I/O para
escalabilidade
Renato Lucindo
Sobre mim
Renato Lucindo
● Twitter: @rlucindo
● Github: /lucindo
Agenda
● Escalabilidade
● 2000: The C10K Problem
○ Threads
○ Events
○ Events + Threads
○ Events + Lightweight Threads
● 2013: The C10M problem
Escalabilidade
● Definição: + hardware ⇒ + carga
● Horizontal
○ hardware ⇒ mais máquinas
● Vertical
○ hardware ⇒ máquina maior
Disclaimer: Sistemas Distribuídos
PRINCIPAL
● Escala horizontal
● Alta disponibilidade
FOCO DA APRESENTAÇÃO
● Escala vertical ¯_(ツ)_/¯
Mean time...
● MTBF e MTTF
○ Mean time between failures (repair)
○ Mean time to failure (replace)
● MTTR
○ Mean time to repair
Trade-off
↑ Escalabilidade Vertical ⇒ ↑ MTTF | ↑ MTBF
Escalabilidade Vertical
Sistemas I/O bound ⇒ Escalabilidade de I/O
2000: The C10K Problem
● Máquina $1200:
○ 1 core (1GHz)
○ 2 GB RAM
○ 1 GB placa de rede
● Objetivo:
○ 10K clientes silmultâneos (conexões)
○ 20K:
■ 50KHz
■ 100Kbytes
■ 50Kbits/sec
http://www.kegel.com/c10k.html
I/O e Paradigmas de Concorrência
I/O:
● Síncrono
● “Assíncrono”
Concorrência:
● Processos, threads e locks
● Eventos e callbacks
● Processos leves e mensagens
I/O no Unix (Linux)
Network I/O
● Sockets = file descriptors
● Operações atomicas = syscalls
● POSIX I/O
○ Default: blocante e buffered
○ Não Blocante: O_NONBLOCK
○ Assíncrono: aio_*
● Polling/Events
Thread per connection (B)
● 1 thread para cada conexão
● I/O blocante
● Isolamento de recursos entre threads
● Simples e fácil de programar
● 2016: 10K Threads no Linux
Thread pool (B)
Little's law: The long-term average number of customers in a stable system L is
equal to the long-term average effective arrival rate, λ, multiplied by the average
time a customer spends in the system, W; or expressed algebraically: L = λW.
The average number of threads in a system is equal average request
arrival rate (requests per sec), multiplied by the average response time.
Threads = (Requests/sec) X Response Time
Ex: com response time de 50ms são necessárias 500 threads para C10K
Single thread events (NB)
● I/O não blocante
● File descriptor polling (select, epool, etc)
● Reactor pattern
● Callbacks
● Subutilização de recursos
● Callback-hell
Single thread events (NB) (cont.)
Events + Threads (NB)
● I/O não blocante
● Evento e I/O tratados por threads diferentes
● Multithreaded reactor pattern
● Trade-off: Locks e callbacks
Events + Threads (NB) (cont.)
Events + Lightweight threads (NB)
● I/O não blocante
● Runtime/VM
● Escala para milhares de lightweight threads com poucas threads físicas
● CSP e Actor Model
○ Troca de mensagens
○ Funcional ou stateful
○ Scheduler preemptivo*
2013: The C10M problem
● Máquina $1200:
○ 8 cores (?GHz)
○ 64 GB RAM
○ 10 GB placa de rede
● Objetivo:
○ 10M clientes silmultâneos (conexões)
Soluções C10M vs. C10K
● Kernel é o problema
● Kernel-bypass:
○ Packets (ou até stack do protocolo inteira)
○ Gerenciamento de memória
○ Gerenciamento de cores
○ Mas e a nuvem :~(
● Sugestões em 2000 para o C10K
http://c10m.robertgraham.com/p/manifesto.html
Recap
● Sistemas Distribuídos: Escalabilidade horizontal + alta disponibilidade.
● Escalabilidade vertical faz diferença.
● Escalabilidade de I/O (rede): não-blocante.
● Estratégias de concorrência
○ (B) Thread-per-connection/Thread-pools
○ (NB) Single-threaded events
○ (NB) Events + threads
○ (NB) Events + lightweight threads
● Fullstack: seu banco de dados acompanha sua aplicação ?
Obrigado :)
Leituras
● UNIX Network Programming (Third Edition)
● Seven Concurrency Models in Seven Weeks

Mais conteúdo relacionado

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 Health
ThinkNow
 
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
Kurio // The Social Media Age(ncy)
 

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
 

Estratégias de I/O para escalabilidade

  • 1. Estratégias de I/O para escalabilidade Renato Lucindo
  • 2. Sobre mim Renato Lucindo ● Twitter: @rlucindo ● Github: /lucindo
  • 3. Agenda ● Escalabilidade ● 2000: The C10K Problem ○ Threads ○ Events ○ Events + Threads ○ Events + Lightweight Threads ● 2013: The C10M problem
  • 4. Escalabilidade ● Definição: + hardware ⇒ + carga ● Horizontal ○ hardware ⇒ mais máquinas ● Vertical ○ hardware ⇒ máquina maior
  • 5. Disclaimer: Sistemas Distribuídos PRINCIPAL ● Escala horizontal ● Alta disponibilidade FOCO DA APRESENTAÇÃO ● Escala vertical ¯_(ツ)_/¯
  • 6. Mean time... ● MTBF e MTTF ○ Mean time between failures (repair) ○ Mean time to failure (replace) ● MTTR ○ Mean time to repair
  • 7. Trade-off ↑ Escalabilidade Vertical ⇒ ↑ MTTF | ↑ MTBF
  • 8. Escalabilidade Vertical Sistemas I/O bound ⇒ Escalabilidade de I/O
  • 9. 2000: The C10K Problem ● Máquina $1200: ○ 1 core (1GHz) ○ 2 GB RAM ○ 1 GB placa de rede ● Objetivo: ○ 10K clientes silmultâneos (conexões) ○ 20K: ■ 50KHz ■ 100Kbytes ■ 50Kbits/sec http://www.kegel.com/c10k.html
  • 10. I/O e Paradigmas de Concorrência I/O: ● Síncrono ● “Assíncrono” Concorrência: ● Processos, threads e locks ● Eventos e callbacks ● Processos leves e mensagens
  • 11. I/O no Unix (Linux) Network I/O ● Sockets = file descriptors ● Operações atomicas = syscalls ● POSIX I/O ○ Default: blocante e buffered ○ Não Blocante: O_NONBLOCK ○ Assíncrono: aio_* ● Polling/Events
  • 12. Thread per connection (B) ● 1 thread para cada conexão ● I/O blocante ● Isolamento de recursos entre threads ● Simples e fácil de programar ● 2016: 10K Threads no Linux
  • 13. Thread pool (B) Little's law: The long-term average number of customers in a stable system L is equal to the long-term average effective arrival rate, λ, multiplied by the average time a customer spends in the system, W; or expressed algebraically: L = λW. The average number of threads in a system is equal average request arrival rate (requests per sec), multiplied by the average response time. Threads = (Requests/sec) X Response Time Ex: com response time de 50ms são necessárias 500 threads para C10K
  • 14. Single thread events (NB) ● I/O não blocante ● File descriptor polling (select, epool, etc) ● Reactor pattern ● Callbacks ● Subutilização de recursos ● Callback-hell
  • 15. Single thread events (NB) (cont.)
  • 16. Events + Threads (NB) ● I/O não blocante ● Evento e I/O tratados por threads diferentes ● Multithreaded reactor pattern ● Trade-off: Locks e callbacks
  • 17. Events + Threads (NB) (cont.)
  • 18. Events + Lightweight threads (NB) ● I/O não blocante ● Runtime/VM ● Escala para milhares de lightweight threads com poucas threads físicas ● CSP e Actor Model ○ Troca de mensagens ○ Funcional ou stateful ○ Scheduler preemptivo*
  • 19. 2013: The C10M problem ● Máquina $1200: ○ 8 cores (?GHz) ○ 64 GB RAM ○ 10 GB placa de rede ● Objetivo: ○ 10M clientes silmultâneos (conexões)
  • 20. Soluções C10M vs. C10K ● Kernel é o problema ● Kernel-bypass: ○ Packets (ou até stack do protocolo inteira) ○ Gerenciamento de memória ○ Gerenciamento de cores ○ Mas e a nuvem :~( ● Sugestões em 2000 para o C10K http://c10m.robertgraham.com/p/manifesto.html
  • 21. Recap ● Sistemas Distribuídos: Escalabilidade horizontal + alta disponibilidade. ● Escalabilidade vertical faz diferença. ● Escalabilidade de I/O (rede): não-blocante. ● Estratégias de concorrência ○ (B) Thread-per-connection/Thread-pools ○ (NB) Single-threaded events ○ (NB) Events + threads ○ (NB) Events + lightweight threads ● Fullstack: seu banco de dados acompanha sua aplicação ?
  • 23. Leituras ● UNIX Network Programming (Third Edition) ● Seven Concurrency Models in Seven Weeks