reactive programming: brincando com eficiência, composição e assíncronia

Post on 17-Aug-2015

99 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Reactive Programming: Brincando com eficiência, composição e assincronia.

Felipe Mamud@ftmamud

Raphael Almeida@raphait

HPC

Agradecimentos

HPC

Será que nossos sistemas já estão no limite?

INTERNET USERS2.4bi

2012

INTERNET USERS3.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 TIMESECONDS

CLOUD-BASED CLUSTERMULTICORE

OFFLINE MAINTENANCE

REAL TIMEMILLISEC/MICROSEC

100% UPTIME

FAST DATA

GIBABYTE DATA

BIGDATA

PETABYTES

2015

As exigências e as expectativas para aplicações mudaram

drasticamente nos últimos anos.

Precisamos de sistemas que irão:

● Reagir a eventos (Event-Driven)

● Reagir a carga (Scalable)

● Reagir a falhas (Resilient)

● Reagir a usuários (Responsive)

Reactive Programming“Readily responsive to a stimulus”

Reactive Manifesto

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

Reactive frameworksReactor

ReactiveX

Message-Driven“Reactive Systems rely on asynchronous

message-passing”

Share Mutable State

● with threads:

○ code that is totally non-deterministic;

○ the root of all evil;

● Avoid it at all cost;

● Use immutability;

Never/Avoid Block

● Unless you really have to;

● Blocking kills scalability (+ performance);

● Use non-blocking IO;

● Use lock-free concurrency;

Async● Use asynchronous event/message passing;

● Lower latency (vs sales);

● Better throughput;

● A more loosely coupled architecture, easier

to extend, evolve and maintain.

Some t ls

● Actors

● Agents

● Future/Dataflow

● Reactive Extensions (Rx)

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;

Agents

● Reactive memory cells;● Send a update function to the Agent;● Reads are “free”, just dereferences

the Ref;● Composes nicely;

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;

Reactive Extensions (Rx)

● Extend Futures with the concept of a

Stream;

● Composable in a type-safe way;

● Event-based & asynchronous;

● Observable ⇛ Push Collections;

Elastic“Capable of being easily expanded or

upgraded on demand”

● Mobile

● SQL Replication

● NoSQL DB

● Cloud Services

Distributed systems

What is the essence of distributed computing?

What is the essence of distributed computing?

1. Information travels at the speed of light;

2. Independent things fail independently.

Why necessary?

● Scalability;

● Availability;

● The network is unreliable;

● Location Transparency;

“Almost” no limit to scalability.

Shared Nothing

Assynchronous communication

Location Transparency

Loose Coupling

Resilience“The ability of a substance or object to spring back into shape.”

“The capacity to recover quickly from difficulties.”

● Exception in thread;

● Errors do not propagate between threads;

● Error handling tangled with business logic;

Failure recover

Right Way

● Isolate the failure;

● Compartmentalize;

● Manage failure locally;

● Avoid cascading failures;

● Supervision;

Responsive“Quick to respond or react appropriately”

● Latency consistent;

● Use Back Pressure;

● Smart Batching;

● Reative Request

(Async & Non-blocking Request & Response)

Responsive

Dúvidas?

THANK YOU!FRIENDS TECHDAY

COMPARTILHAR, APRENDER E CONTRIBUIR!

Felipe Mamud@ftmamud

Raphael Almeida@raphait

We are a reactive family

top related