Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive Programming - Brincando com eficiência, composição e assíncronia

Reactive Programming - Brincando com eficiência, composição e assíncronia

Trilha HPC TDC 2015: Mostramos quais são as principais vantagens e desvantagens da programação reativa. Atualmente existem algumas perguntas que ainda de fato não temos respostas: Será que nossos sistemas já estão no limite? Será que ainda há espaço a ser conquistado e ganhos de performance a se descobrir?

Felipe Mamud

July 24, 2015
Tweet

More Decks by Felipe Mamud

Other Decks in Programming

Transcript

  1. INTERNET USERS 2.4bi 2012 INTERNET USERS 3.01bi TENS OF SERVERS

    Fontes: http://recode.net/2014/05/28/meeker-as-internet-user-growth-slows-the-real-driver-is-mobile-usage/ http://www.slideshare.net/wearesocialsg/digital-social-mobile-in-2015 RESPONSE TIME SECONDS CLOUD-BASED CLUSTER MULTICORE OFFLINE MAINTENANCE REAL TIME MILLISEC/MICROSEC 100% UPTIME FAST DATA GIBABYTE DATA BIGDATA PETABYTES 2015
  2. Precisamos de sistemas que irão: • Reagir a eventos (Event-Driven)

    • Reagir a carga (Scalable) • Reagir a falhas (Resilient) • Reagir a usuários (Responsive)
  3. O que são sistemas Reativos? Sistemas criados como Reativos são

    muito mais flexíveis, desacoplados e escaláveis. Isso os torna mais fáceis de desenvolver e manter. São mais tolerantes a falhas e quando elas ocorrem são tratadas com elegância ao invés de desastre. Sistemas Reativos são responsivos, dando aos usuários feedbacks mais interativos. Fonte: http://www.reactivemanifesto.org/pt-BR
  4. Share Mutable State • with threads: ◦ code that is

    totally non-deterministic; ◦ the root of all evil; • Avoid it at all cost; • Use immutability;
  5. Never/Avoid Block • Unless you really have to; • Blocking

    kills scalability (+ performance); • Use non-blocking IO; • Use lock-free concurrency;
  6. Async • Use asynchronous event/message passing; • Lower latency (vs

    sales); • Better throughput; • A more loosely coupled architecture, easier to extend, evolve and maintain.
  7. Actors • Isolated lightweight event-based processes; • Each actor has

    a mailbox (message queue); • Communicates through asynchronous and non-blocking message passing; • Location transparent (distributable); • Supervision-based failure management;
  8. Agents • Reactive memory cells; • Send a update function

    to the Agent; • Reads are “free”, just dereferences the Ref; • Composes nicely;
  9. Futures/Dataflow • Allows you to spawn concurrent computations and work

    with the not yet computed results; • Freely sharable; • Allows non-blocking composition; • Build in model for managing failure;
  10. Reactive Extensions (Rx) • Extend Futures with the concept of

    a Stream; • Composable in a type-safe way; • Event-based & asynchronous; • Observable ⇛ Push Collections;
  11. What is the essence of distributed computing? 1. Information travels

    at the speed of light; 2. Independent things fail independently.
  12. Resilience “The ability of a substance or object to spring

    back into shape.” “The capacity to recover quickly from difficulties.”
  13. • Exception in thread; • Errors do not propagate between

    threads; • Error handling tangled with business logic; Failure recover
  14. Right Way • Isolate the failure; • Compartmentalize; • Manage

    failure locally; • Avoid cascading failures; • Supervision;
  15. • Latency consistent; • Use Back Pressure; • Smart Batching;

    • Reative Request (Async & Non-blocking Request & Response) Responsive
  16. THANK YOU! FRIENDS TECHDAY COMPARTILHAR, APRENDER E CONTRIBUIR! Felipe Mamud

    @ftmamud Raphael Almeida @raphait We are a reactive family