SlideShare uma empresa Scribd logo
1 de 98
Baixar para ler offline
Miguel Ángel Pastor Olivar
Reactive Applications
Building concurrent and distributed apps using Akka
miguelinlas3@gmail.com - Liferay Inc and MadridJUG
@miguelinlas3

Saturday, October 19, 13
About me

Writing software for the Liferay platform team
Phd student? on distributed and cloud
systems
Scala enthusiast
Twitter: @miguelinlas3

Saturday, October 19, 13
Agenda

Reactive apps: do we really need them?
Crash course on basic Akka concepts
Old known problems
A quick look into newer (and more fun tools)

Saturday, October 19, 13
Reactive applications

Applications has become extremely
demanding
New kind of systems
Event driven, scalable , resilient, responsive
This is what Reactive Applications are all
about

Saturday, October 19, 13
Reactive applications: definitions

Blocking
Caller blocked. Wait for the results
Non blocking
Caller not blocked. Need to pool
Asynchronous
Caller not blocked. Select, epoll, signals
Event driven
Message flowing through the system
Saturday, October 19, 13
Basic pillars

Saturday, October 19, 13
Basic pillars

Event Driven

Saturday, October 19, 13
Basic pillars

Event Driven

Resilient

Saturday, October 19, 13
Basic pillars

Event Driven

Resilient

Saturday, October 19, 13

Scalable
Basic pillars

Event Driven

Resilient

Scalable

Responsive

Saturday, October 19, 13
Going event driven
Old known problems,
The actor model

Saturday, October 19, 13
Going Event Driven

Saturday, October 19, 13
Going Event Driven

Shared Memory

Saturday, October 19, 13
Going Event Driven

Shared Memory

Saturday, October 19, 13
Going Event Driven

Thread 1

Shared Memory

Saturday, October 19, 13
Going Event Driven

Thread 1

Thread 2

Shared Memory

Saturday, October 19, 13
Going Event Driven

Thread 1

Thread 2

Shared Memory

Saturday, October 19, 13
Going Event Driven

Thread 1

Thread 2

Shared Memory

Saturday, October 19, 13
Going Event Driven

Thread 1

Thread 2

R/W

Shared Memory

Saturday, October 19, 13
Going Event Driven

Thread 1

Thread 2

R/W
R/W

Shared Memory

Saturday, October 19, 13
Going Event Driven

Thread 1

Thread 2

R/W
R/W

Shared Memory

Saturday, October 19, 13

AVOID IT!!
Going event driven: problems with locks

Saturday, October 19, 13
Going event driven: problems with locks

Composition

Saturday, October 19, 13
Going event driven: problems with locks

Composition
Locks don´t compose

Saturday, October 19, 13
Going event driven: problems with locks

Composition
Locks don´t compose

Saturday, October 19, 13

Granularity
Going event driven: problems with locks

Composition
Locks don´t compose
Have I taken too few
locks? Too many?

Saturday, October 19, 13

Granularity
Going event driven: problems with locks

Composition
Locks don´t compose
Have I taken too few
locks? Too many?

Encapsulation

Saturday, October 19, 13

Granularity
Going event driven: problems with locks

Composition
Locks don´t compose
Have I taken too few
locks? Too many?

Encapsulation
Breaking abstractions

Saturday, October 19, 13

Granularity
Going event driven: problems with locks

Composition
Locks don´t compose

Granularity

Have I taken too few
locks? Too many?

Encapsulation
Breaking abstractions

Saturday, October 19, 13

Correctness
Going event driven: problems with locks

Composition
Locks don´t compose

Granularity

Have I taken too few
locks? Too many?

Encapsulation
Breaking abstractions

Correctness

Have I taken the
correct lock?

Saturday, October 19, 13
Going event driven: problems with locks

Composition
Locks don´t compose

Granularity

Have I taken too few
locks? Too many?

Encapsulation
Breaking abstractions

Ordering

Saturday, October 19, 13

Correctness

Have I taken the
correct lock?
Going event driven: problems with locks

Composition
Locks don´t compose

Granularity

Have I taken too few
locks? Too many?

Encapsulation
Breaking abstractions

Ordering

Saturday, October 19, 13

Have I used the
correct order?

Correctness

Have I taken the
correct lock?
Going event driven: designing your system

Asynchronous message/event passing
Workflow of the events through your system
Benefits:
Better throughput
Lower latencies
Loosely coupled solutions

Saturday, October 19, 13
Going event driven: Amdahl’s law

Saturday, October 19, 13
Going event driven: the actor model

Fundamental unit of computation that embodies:
• Processing
• Storage
• Communication
Three axioms. When an Actor receives a message it can:
• Create new Actors
• Send messages to Actors it knows
• Designate how it should handle the next message it receives
Carl Hewitt

Saturday, October 19, 13
Going event driven: the actor model

Saturday, October 19, 13
Going event driven: the actor model

Saturday, October 19, 13
Going event driven: the actor model

Saturday, October 19, 13
Going event driven: the actor model

Zero sharing
Isolated, lightweight event based processes
Communication through asynchronous
message passing
Location transparent
Built-in supervision
Saturday, October 19, 13
Actor model: Define a new actor

public class MetricsProcessorActor extends UntypedActor {
public void onReceive(Object message) {
if (message instanceof JVMMetric) {
JVMMetric jvmMetric = (JVMMetric)message;

}
}

}

_dataStore.save(jvmMetric);

private DataStore _dataStore = new LogDataStore();

Saturday, October 19, 13
Actor model: Creating an actor

ActorSystem _agentSystem = ActorSystem.create("AgentSystem");
ActorRef metricsActor =
_agentSystem.actorOf(
new Props(new UntypedActorFactory() {
@Override
public Actor create() {
return new MetricsActor(metricsActor);
}
}),
"metricsActor");

Saturday, October 19, 13
Actor model: Getting a reference

ActorSystem _agentSystem = ActorSystem.create("AgentSystem");
ActorRef handshakeActor =
_agentSystem.actorFor(
"akka://MonitoringServiceSystem@localhost:5557/user/
handshakeActor");

Saturday, October 19, 13
Actor model: Sending a message

metricsActor.tell(
new JVMMessage("JVM-MemoryUsage", new Date().getTime()));

Saturday, October 19, 13
Actor model: Replying to a message

public class HandshakeActor extends UntypedActor {
public void onReceive(Object message) {
if (message instanceof AuthMessage) {
AuthMessage authMessage = (AuthMessage)message;
if (authMessage.getUser() == "migue" &&
authMessage.getCredentials() == "migue")
getSender().tell("ok");
else
getSender().tell("fail");

}

}

} else
throw new IllegalStateException("Unable to handle " +
message);

Saturday, October 19, 13
Actor model: Switching implementation
public class MetricsProcessorActor extends UntypedActor {
public void onReceive(Object message) {
if (message instanceof SwappingMessage) {
getContext().become(altPersistence, false)
}
}
{

};
}

Procedure<Object> altPersistence = new Procedure<Object>()
@Override
public void apply(Object message) {
altDatastore.save(message);
}
DataStore altDatastore = new AltDataStore();
private DataStore _dataStore = new LogDataStore();

Saturday, October 19, 13
Actor model: Routing

final ActorSystem monitoringServiceSystem =
ActorSystem.create("MonitoringServiceSystem");
ActorRef metricsActor =
monitoringServiceSystem.actorOf(
new Props(MetricsProcessorActor.class).withRouter(
new RoundRobinRouter(100), "metricsActor");
}

Dealing with routers does not change our code
metricsActor.tell(
new JVMMessage("JVM-MemoryUsage", new Date().getTime()));

Saturday, October 19, 13
Actor model: Configuring a router

akka {
actor {
deployment {
/metricsActor {
router = round-robin
nr-of-instances = 100
}
}
}
}

Saturday, October 19, 13
Going scalable
Distributed computing,
The actor model

Saturday, October 19, 13
Going scalable: scalability

I really do have an scalability problem ...
if my system is fast for a single user but slow
when the system is under heavy load

Saturday, October 19, 13
Going scalable: transparent distributed computing

Distributed shared mutable state
Distributed objects
Distributed transactions

Saturday, October 19, 13
Going scalable: transparent distributed computing

Synchronous method dispatching across the
network is a bad idea
Ignores partial failures
Raises Latency
General scalability and DC concerns

Saturday, October 19, 13
Going scalable: transparent distributed computing

EMBRACE THE NETWORK!!

Saturday, October 19, 13
Going scalable: remote actors
akka {
actor {
deployment {
/metricsActor {
remote =
"akka://monitorSystem@name:5557"
}
}
}
}

No changes are required in our existing code!!
final ActorSystem monitoringServiceSystem =
ActorSystem.create("MonitoringServiceSystem");
ActorRef metricsActor = monitoringServiceSystem.actorOf(
new Props(MetricsProcessorActor.class), "metricsActor");

Saturday, October 19, 13
Going resilient
Error handling

Saturday, October 19, 13
Going resilient: common problems

Single thread of control
Thread blows up --> you are screwed
Error handling within single thread
Errors don´t get propagated
Defensive programming
Tangled within business logic
Scattered along all our codebase
Saturday, October 19, 13
Going resilient: actor topology and supervision

System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for one

System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for one

System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for one

System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for one

System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for one

System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for one

System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

/B1/B2/B7
/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

B4

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3

B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Supervision strategies: One for all
System

/B1

/A1

B1

A1

/B1/B3

/A1/A2

/B1/B2

B3
B2

A2

/A1/A3
A3
B7
B5

/A1/A2/A4

A4

B6

B4

/B1/B3/B5
/B1/B2/B6

Saturday, October 19, 13

/B1/B2/B7

/B1/B2/B4
Going resilient: configure supervision
final SupervisorStrategy supervisorStrategy =
new OneForOneStrategy(
3, Duration.create(1, TimeUnit.MINUTES),
new Class<?>[] {Exception.class});
_metricsActor = _cloudServiceSystem.actorOf(
new Props(MetricsProcessorActor.class).
withRouter(
new RoundRobinRouter(100).
withSupervisorStrategy(
supervisorStrategy)),
"metricsActor");
Supervision strategies are pluggable and you can develop and configure your own

Saturday, October 19, 13
More tools
We deserve better and more fun tools

Saturday, October 19, 13
More tools: futures

•Spawn concurrent computations
•Write once - Read many
•Freely sharable
•Non-blocking composition
•Composable (monadic operations)
•Managing failure
Saturday, October 19, 13
More tools: futures
val f: Future[List[String]] = future {
session.getRecentPosts
}
// handle both cases: Success and Failure
f onComplete {
case Success(posts) => for (post <- posts) println(post)
case Failure(t) => println("An error has occured: " +
t.getMessage)
}
// only handle Success
f onSuccess {
case posts => for (post <- posts) println(post)
}
// only handle Failure
f onFailure {
case t => println("An error has occured: " + t.getMessage)
}

Saturday, October 19, 13
More tools: agents

•Reactive memory cells
•Send update function to an agent
•Reads are “free”
•Composable
•Originally in Clojure, borrowed by Akka
Saturday, October 19, 13
More tools: agents

// declare the agent
val counter = Agent(0)
// send the function: enqueued the change
counter send { _ + 1}
// long running or blocking operations
implicit val ec = defineSomeExecutionContext()
agent sendOff blockingOperation
// read the agent’ s value
val agentValue = counter.value

Saturday, October 19, 13
More tools: software transactional memory

Sometimes we will deal with shared state
Heap + Stack: transactional dataset:
Begin, commit, rollback
Retry on collision
Rollback on abort
Transaction composability
Saturday, October 19, 13
More tools: reactive extensions

•Futures + Stream concept
•Composables
•Async and event based
•Push collections
•JVM available through the RxJava project
Saturday, October 19, 13
More tools: reactive extensions

def simpleComposition() {
customObservableNonBlocking()
.skip(10)
.take(5)
.map({ stringValue -> return stringValue +
"_transformed"})
.subscribe({ println "nextElement => " + it})
}
// we should an output like this
nextElement
nextElement
nextElement
nextElement
nextElement

Saturday, October 19, 13

=>
=>
=>
=>
=>

foo_10_transformed
foo_11_transformed
foo_12_transformed
foo_13_transformed
foo_14_transformed
More tools: reactive extensions
def Observable<T> getData(int id) {
if(availableInMemory) {
return Observable.create({ observer ->
observer.onNext(valueFromMemory);
observer.onCompleted();
})
} else {
return Observable.create({ observer ->
executor.submit({
try {
T value = getValueFromRemoteService(id);
observer.onNext(value);
observer.onCompleted();
}catch(Exception e) {
observer.onError(e);
}
})
});
}
}

Saturday, October 19, 13
Useful approaches
Where should I use each tool?

Saturday, October 19, 13
Layers of complexity

Declarative & immutable core
Logic or functional programming
Futures and/or dataflow
Non-determinism when needed
Actors, Agents or Rx
Shared mutability
Protected by Software Transactional Memory
Finally, only if it is really needed
Locks and explicit threads
Saturday, October 19, 13
Takeways
A quick summary

Saturday, October 19, 13
Takeaways

Go reactive
Avoid locking (share nothing, lock free algs)
Already in the JVM? Akka could be good choice
Distributed systems are hard
Use the correct level of abstraction
And remember ...

Saturday, October 19, 13
Takeaways

hammer

When all you have is a
everything looks like
a

nail.

Choose the
right tool for your job!
Saturday, October 19, 13
Questions?
And let’s hope answers

Saturday, October 19, 13
References
Interesting resources

Saturday, October 19, 13
References: slides, talks and books

High Performance Networking in the JVM by Eric
Onnen
Going reactive talk by Jonas Bonér
Introducing Akka by Jonas Bonér
The future I was promised by Viktor Klang
Real world Akka recipes by Björn Antonsson et all

Saturday, October 19, 13
References: slides, talks and books

Programming Concurrency in the JVM: Mastering
synchronization, STM and Actors by Venkat
Subramaniam
Systems than run forever Self-heal by Joe Amstrong
The art of multiprocessor programming, Revised
Reprint by Maurice Herlihy
Reactive Manifesto

Saturday, October 19, 13
References: frameworks and toolkits

Erlang
Akka Toolkit
Scala language
Vert.x
Clojure language
GPars

Saturday, October 19, 13
References: frameworks and toolkits

Cloud Haskell
NodeJS
Netty IO
Finagle

Saturday, October 19, 13

Mais conteúdo relacionado

Semelhante a Reactive applications using Akka

Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013Thibault Imbert
 
Interactive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsInteractive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsJuriy Zaytsev
 
Troubleshooting Live Java Web Applications
Troubleshooting Live Java Web ApplicationsTroubleshooting Live Java Web Applications
Troubleshooting Live Java Web Applicationsashleypuls
 
Android Security & Penetration Testing
Android Security & Penetration TestingAndroid Security & Penetration Testing
Android Security & Penetration TestingSubho Halder
 
FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...
FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...
FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...New Relic
 
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPACheng Ta Yeh
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with SiestaGrgur Grisogono
 
Provisioning profiles like a Pro
Provisioning profiles like a ProProvisioning profiles like a Pro
Provisioning profiles like a ProJay Graves
 
Cloud Tech III: Actionable Metrics
Cloud Tech III: Actionable MetricsCloud Tech III: Actionable Metrics
Cloud Tech III: Actionable Metricsroyrapoport
 
Java Tech Day 2009 - Developing Cloud Computing Applications With Java
Java Tech Day 2009 - Developing Cloud Computing Applications With JavaJava Tech Day 2009 - Developing Cloud Computing Applications With Java
Java Tech Day 2009 - Developing Cloud Computing Applications With JavaShlomo Swidler
 
Cassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at Ooyala
Cassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at OoyalaCassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at Ooyala
Cassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at OoyalaDataStax Academy
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From DesignRobert Treat
 
Phpday - Automated acceptance testing with Behat and Mink
Phpday - Automated acceptance testing with Behat and MinkPhpday - Automated acceptance testing with Behat and Mink
Phpday - Automated acceptance testing with Behat and MinkRichard Tuin
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programmingMichael Neale
 
CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...
CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...
CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...Cohesive Networks
 
Interact your wearable and an iot device
Interact your wearable and an iot deviceInteract your wearable and an iot device
Interact your wearable and an iot deviceJeff Prestes
 
Managing Windows Systems with Puppet - PuppetConf 2013
Managing Windows Systems with Puppet - PuppetConf 2013Managing Windows Systems with Puppet - PuppetConf 2013
Managing Windows Systems with Puppet - PuppetConf 2013Puppet
 
Digital Twins for Security Automation
Digital Twins for Security AutomationDigital Twins for Security Automation
Digital Twins for Security AutomationKim Hammar
 

Semelhante a Reactive applications using Akka (20)

Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013
 
Interactive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsInteractive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.js
 
Troubleshooting Live Java Web Applications
Troubleshooting Live Java Web ApplicationsTroubleshooting Live Java Web Applications
Troubleshooting Live Java Web Applications
 
Android Security & Penetration Testing
Android Security & Penetration TestingAndroid Security & Penetration Testing
Android Security & Penetration Testing
 
FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...
FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...
FUTURESTACK13: Software analytics with Project Rubicon from Alex Kroman Engin...
 
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with Siesta
 
Provisioning profiles like a Pro
Provisioning profiles like a ProProvisioning profiles like a Pro
Provisioning profiles like a Pro
 
Cloud Tech III: Actionable Metrics
Cloud Tech III: Actionable MetricsCloud Tech III: Actionable Metrics
Cloud Tech III: Actionable Metrics
 
Java Tech Day 2009 - Developing Cloud Computing Applications With Java
Java Tech Day 2009 - Developing Cloud Computing Applications With JavaJava Tech Day 2009 - Developing Cloud Computing Applications With Java
Java Tech Day 2009 - Developing Cloud Computing Applications With Java
 
Cassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at Ooyala
Cassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at OoyalaCassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at Ooyala
Cassandra Meetup: Real-time Analytics using Cassandra, Spark and Shark at Ooyala
 
Don't do this
Don't do thisDon't do this
Don't do this
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From Design
 
Phpday - Automated acceptance testing with Behat and Mink
Phpday - Automated acceptance testing with Behat and MinkPhpday - Automated acceptance testing with Behat and Mink
Phpday - Automated acceptance testing with Behat and Mink
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programming
 
CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...
CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...
CIW Lab with CoheisveFT: Get started in public cloud - Part 1 Cloud & Virtual...
 
Interact your wearable and an iot device
Interact your wearable and an iot deviceInteract your wearable and an iot device
Interact your wearable and an iot device
 
Managing Windows Systems with Puppet - PuppetConf 2013
Managing Windows Systems with Puppet - PuppetConf 2013Managing Windows Systems with Puppet - PuppetConf 2013
Managing Windows Systems with Puppet - PuppetConf 2013
 
100% JS
100% JS100% JS
100% JS
 
Digital Twins for Security Automation
Digital Twins for Security AutomationDigital Twins for Security Automation
Digital Twins for Security Automation
 

Mais de Miguel Pastor

Liferay & Big Data Dev Con 2014
Liferay & Big Data Dev Con 2014Liferay & Big Data Dev Con 2014
Liferay & Big Data Dev Con 2014Miguel Pastor
 
Microservices: The OSGi way A different vision on microservices
Microservices: The OSGi way A different vision on microservicesMicroservices: The OSGi way A different vision on microservices
Microservices: The OSGi way A different vision on microservicesMiguel Pastor
 
Liferay and Big Data
Liferay and Big DataLiferay and Big Data
Liferay and Big DataMiguel Pastor
 
Reactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala MeetupReactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala MeetupMiguel Pastor
 
Liferay Devcon 2013: Our way towards modularity
Liferay Devcon 2013: Our way towards modularityLiferay Devcon 2013: Our way towards modularity
Liferay Devcon 2013: Our way towards modularityMiguel Pastor
 
Liferay Module Framework
Liferay Module FrameworkLiferay Module Framework
Liferay Module FrameworkMiguel Pastor
 
Hadoop, Cloud y Spring
Hadoop, Cloud y Spring Hadoop, Cloud y Spring
Hadoop, Cloud y Spring Miguel Pastor
 
Scala: un vistazo general
Scala: un vistazo generalScala: un vistazo general
Scala: un vistazo generalMiguel Pastor
 
Platform as a Service overview
Platform as a Service overviewPlatform as a Service overview
Platform as a Service overviewMiguel Pastor
 
Aspect Oriented Programming introduction
Aspect Oriented Programming introductionAspect Oriented Programming introduction
Aspect Oriented Programming introductionMiguel Pastor
 
Software measure-slides
Software measure-slidesSoftware measure-slides
Software measure-slidesMiguel Pastor
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails introMiguel Pastor
 

Mais de Miguel Pastor (18)

Liferay & Big Data Dev Con 2014
Liferay & Big Data Dev Con 2014Liferay & Big Data Dev Con 2014
Liferay & Big Data Dev Con 2014
 
Microservices: The OSGi way A different vision on microservices
Microservices: The OSGi way A different vision on microservicesMicroservices: The OSGi way A different vision on microservices
Microservices: The OSGi way A different vision on microservices
 
Liferay and Big Data
Liferay and Big DataLiferay and Big Data
Liferay and Big Data
 
Reactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala MeetupReactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala Meetup
 
Liferay Devcon 2013: Our way towards modularity
Liferay Devcon 2013: Our way towards modularityLiferay Devcon 2013: Our way towards modularity
Liferay Devcon 2013: Our way towards modularity
 
Liferay Module Framework
Liferay Module FrameworkLiferay Module Framework
Liferay Module Framework
 
Liferay and Cloud
Liferay and CloudLiferay and Cloud
Liferay and Cloud
 
Jvm fundamentals
Jvm fundamentalsJvm fundamentals
Jvm fundamentals
 
Scala Overview
Scala OverviewScala Overview
Scala Overview
 
Hadoop, Cloud y Spring
Hadoop, Cloud y Spring Hadoop, Cloud y Spring
Hadoop, Cloud y Spring
 
Scala: un vistazo general
Scala: un vistazo generalScala: un vistazo general
Scala: un vistazo general
 
Platform as a Service overview
Platform as a Service overviewPlatform as a Service overview
Platform as a Service overview
 
HadoopDB
HadoopDBHadoopDB
HadoopDB
 
Aspect Oriented Programming introduction
Aspect Oriented Programming introductionAspect Oriented Programming introduction
Aspect Oriented Programming introduction
 
Software measure-slides
Software measure-slidesSoftware measure-slides
Software measure-slides
 
Arquitecturas MMOG
Arquitecturas MMOGArquitecturas MMOG
Arquitecturas MMOG
 
Software Failures
Software FailuresSoftware Failures
Software Failures
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails intro
 

Último

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Último (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Reactive applications using Akka

  • 1. Miguel Ángel Pastor Olivar Reactive Applications Building concurrent and distributed apps using Akka miguelinlas3@gmail.com - Liferay Inc and MadridJUG @miguelinlas3 Saturday, October 19, 13
  • 2. About me Writing software for the Liferay platform team Phd student? on distributed and cloud systems Scala enthusiast Twitter: @miguelinlas3 Saturday, October 19, 13
  • 3. Agenda Reactive apps: do we really need them? Crash course on basic Akka concepts Old known problems A quick look into newer (and more fun tools) Saturday, October 19, 13
  • 4. Reactive applications Applications has become extremely demanding New kind of systems Event driven, scalable , resilient, responsive This is what Reactive Applications are all about Saturday, October 19, 13
  • 5. Reactive applications: definitions Blocking Caller blocked. Wait for the results Non blocking Caller not blocked. Need to pool Asynchronous Caller not blocked. Select, epoll, signals Event driven Message flowing through the system Saturday, October 19, 13
  • 11. Going event driven Old known problems, The actor model Saturday, October 19, 13
  • 13. Going Event Driven Shared Memory Saturday, October 19, 13
  • 14. Going Event Driven Shared Memory Saturday, October 19, 13
  • 15. Going Event Driven Thread 1 Shared Memory Saturday, October 19, 13
  • 16. Going Event Driven Thread 1 Thread 2 Shared Memory Saturday, October 19, 13
  • 17. Going Event Driven Thread 1 Thread 2 Shared Memory Saturday, October 19, 13
  • 18. Going Event Driven Thread 1 Thread 2 Shared Memory Saturday, October 19, 13
  • 19. Going Event Driven Thread 1 Thread 2 R/W Shared Memory Saturday, October 19, 13
  • 20. Going Event Driven Thread 1 Thread 2 R/W R/W Shared Memory Saturday, October 19, 13
  • 21. Going Event Driven Thread 1 Thread 2 R/W R/W Shared Memory Saturday, October 19, 13 AVOID IT!!
  • 22. Going event driven: problems with locks Saturday, October 19, 13
  • 23. Going event driven: problems with locks Composition Saturday, October 19, 13
  • 24. Going event driven: problems with locks Composition Locks don´t compose Saturday, October 19, 13
  • 25. Going event driven: problems with locks Composition Locks don´t compose Saturday, October 19, 13 Granularity
  • 26. Going event driven: problems with locks Composition Locks don´t compose Have I taken too few locks? Too many? Saturday, October 19, 13 Granularity
  • 27. Going event driven: problems with locks Composition Locks don´t compose Have I taken too few locks? Too many? Encapsulation Saturday, October 19, 13 Granularity
  • 28. Going event driven: problems with locks Composition Locks don´t compose Have I taken too few locks? Too many? Encapsulation Breaking abstractions Saturday, October 19, 13 Granularity
  • 29. Going event driven: problems with locks Composition Locks don´t compose Granularity Have I taken too few locks? Too many? Encapsulation Breaking abstractions Saturday, October 19, 13 Correctness
  • 30. Going event driven: problems with locks Composition Locks don´t compose Granularity Have I taken too few locks? Too many? Encapsulation Breaking abstractions Correctness Have I taken the correct lock? Saturday, October 19, 13
  • 31. Going event driven: problems with locks Composition Locks don´t compose Granularity Have I taken too few locks? Too many? Encapsulation Breaking abstractions Ordering Saturday, October 19, 13 Correctness Have I taken the correct lock?
  • 32. Going event driven: problems with locks Composition Locks don´t compose Granularity Have I taken too few locks? Too many? Encapsulation Breaking abstractions Ordering Saturday, October 19, 13 Have I used the correct order? Correctness Have I taken the correct lock?
  • 33. Going event driven: designing your system Asynchronous message/event passing Workflow of the events through your system Benefits: Better throughput Lower latencies Loosely coupled solutions Saturday, October 19, 13
  • 34. Going event driven: Amdahl’s law Saturday, October 19, 13
  • 35. Going event driven: the actor model Fundamental unit of computation that embodies: • Processing • Storage • Communication Three axioms. When an Actor receives a message it can: • Create new Actors • Send messages to Actors it knows • Designate how it should handle the next message it receives Carl Hewitt Saturday, October 19, 13
  • 36. Going event driven: the actor model Saturday, October 19, 13
  • 37. Going event driven: the actor model Saturday, October 19, 13
  • 38. Going event driven: the actor model Saturday, October 19, 13
  • 39. Going event driven: the actor model Zero sharing Isolated, lightweight event based processes Communication through asynchronous message passing Location transparent Built-in supervision Saturday, October 19, 13
  • 40. Actor model: Define a new actor public class MetricsProcessorActor extends UntypedActor { public void onReceive(Object message) { if (message instanceof JVMMetric) { JVMMetric jvmMetric = (JVMMetric)message; } } } _dataStore.save(jvmMetric); private DataStore _dataStore = new LogDataStore(); Saturday, October 19, 13
  • 41. Actor model: Creating an actor ActorSystem _agentSystem = ActorSystem.create("AgentSystem"); ActorRef metricsActor = _agentSystem.actorOf( new Props(new UntypedActorFactory() { @Override public Actor create() { return new MetricsActor(metricsActor); } }), "metricsActor"); Saturday, October 19, 13
  • 42. Actor model: Getting a reference ActorSystem _agentSystem = ActorSystem.create("AgentSystem"); ActorRef handshakeActor = _agentSystem.actorFor( "akka://MonitoringServiceSystem@localhost:5557/user/ handshakeActor"); Saturday, October 19, 13
  • 43. Actor model: Sending a message metricsActor.tell( new JVMMessage("JVM-MemoryUsage", new Date().getTime())); Saturday, October 19, 13
  • 44. Actor model: Replying to a message public class HandshakeActor extends UntypedActor { public void onReceive(Object message) { if (message instanceof AuthMessage) { AuthMessage authMessage = (AuthMessage)message; if (authMessage.getUser() == "migue" && authMessage.getCredentials() == "migue") getSender().tell("ok"); else getSender().tell("fail"); } } } else throw new IllegalStateException("Unable to handle " + message); Saturday, October 19, 13
  • 45. Actor model: Switching implementation public class MetricsProcessorActor extends UntypedActor { public void onReceive(Object message) { if (message instanceof SwappingMessage) { getContext().become(altPersistence, false) } } { }; } Procedure<Object> altPersistence = new Procedure<Object>() @Override public void apply(Object message) { altDatastore.save(message); } DataStore altDatastore = new AltDataStore(); private DataStore _dataStore = new LogDataStore(); Saturday, October 19, 13
  • 46. Actor model: Routing final ActorSystem monitoringServiceSystem = ActorSystem.create("MonitoringServiceSystem"); ActorRef metricsActor = monitoringServiceSystem.actorOf( new Props(MetricsProcessorActor.class).withRouter( new RoundRobinRouter(100), "metricsActor"); } Dealing with routers does not change our code metricsActor.tell( new JVMMessage("JVM-MemoryUsage", new Date().getTime())); Saturday, October 19, 13
  • 47. Actor model: Configuring a router akka { actor { deployment { /metricsActor { router = round-robin nr-of-instances = 100 } } } } Saturday, October 19, 13
  • 48. Going scalable Distributed computing, The actor model Saturday, October 19, 13
  • 49. Going scalable: scalability I really do have an scalability problem ... if my system is fast for a single user but slow when the system is under heavy load Saturday, October 19, 13
  • 50. Going scalable: transparent distributed computing Distributed shared mutable state Distributed objects Distributed transactions Saturday, October 19, 13
  • 51. Going scalable: transparent distributed computing Synchronous method dispatching across the network is a bad idea Ignores partial failures Raises Latency General scalability and DC concerns Saturday, October 19, 13
  • 52. Going scalable: transparent distributed computing EMBRACE THE NETWORK!! Saturday, October 19, 13
  • 53. Going scalable: remote actors akka { actor { deployment { /metricsActor { remote = "akka://monitorSystem@name:5557" } } } } No changes are required in our existing code!! final ActorSystem monitoringServiceSystem = ActorSystem.create("MonitoringServiceSystem"); ActorRef metricsActor = monitoringServiceSystem.actorOf( new Props(MetricsProcessorActor.class), "metricsActor"); Saturday, October 19, 13
  • 55. Going resilient: common problems Single thread of control Thread blows up --> you are screwed Error handling within single thread Errors don´t get propagated Defensive programming Tangled within business logic Scattered along all our codebase Saturday, October 19, 13
  • 56. Going resilient: actor topology and supervision System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 57. Supervision strategies: One for one System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 58. Supervision strategies: One for one System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 59. Supervision strategies: One for one System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 60. Supervision strategies: One for one System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 61. Supervision strategies: One for one System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 62. Supervision strategies: One for one System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 63. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 64. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 65. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 66. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 67. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 68. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 69. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 70. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 71. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 72. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 /B1/B2/B7 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 B4 /B1/B2/B4
  • 73. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 74. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 75. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 76. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 77. Supervision strategies: One for all System /B1 /A1 B1 A1 /B1/B3 /A1/A2 /B1/B2 B3 B2 A2 /A1/A3 A3 B7 B5 /A1/A2/A4 A4 B6 B4 /B1/B3/B5 /B1/B2/B6 Saturday, October 19, 13 /B1/B2/B7 /B1/B2/B4
  • 78. Going resilient: configure supervision final SupervisorStrategy supervisorStrategy = new OneForOneStrategy( 3, Duration.create(1, TimeUnit.MINUTES), new Class<?>[] {Exception.class}); _metricsActor = _cloudServiceSystem.actorOf( new Props(MetricsProcessorActor.class). withRouter( new RoundRobinRouter(100). withSupervisorStrategy( supervisorStrategy)), "metricsActor"); Supervision strategies are pluggable and you can develop and configure your own Saturday, October 19, 13
  • 79. More tools We deserve better and more fun tools Saturday, October 19, 13
  • 80. More tools: futures •Spawn concurrent computations •Write once - Read many •Freely sharable •Non-blocking composition •Composable (monadic operations) •Managing failure Saturday, October 19, 13
  • 81. More tools: futures val f: Future[List[String]] = future { session.getRecentPosts } // handle both cases: Success and Failure f onComplete { case Success(posts) => for (post <- posts) println(post) case Failure(t) => println("An error has occured: " + t.getMessage) } // only handle Success f onSuccess { case posts => for (post <- posts) println(post) } // only handle Failure f onFailure { case t => println("An error has occured: " + t.getMessage) } Saturday, October 19, 13
  • 82. More tools: agents •Reactive memory cells •Send update function to an agent •Reads are “free” •Composable •Originally in Clojure, borrowed by Akka Saturday, October 19, 13
  • 83. More tools: agents // declare the agent val counter = Agent(0) // send the function: enqueued the change counter send { _ + 1} // long running or blocking operations implicit val ec = defineSomeExecutionContext() agent sendOff blockingOperation // read the agent’ s value val agentValue = counter.value Saturday, October 19, 13
  • 84. More tools: software transactional memory Sometimes we will deal with shared state Heap + Stack: transactional dataset: Begin, commit, rollback Retry on collision Rollback on abort Transaction composability Saturday, October 19, 13
  • 85. More tools: reactive extensions •Futures + Stream concept •Composables •Async and event based •Push collections •JVM available through the RxJava project Saturday, October 19, 13
  • 86. More tools: reactive extensions def simpleComposition() { customObservableNonBlocking() .skip(10) .take(5) .map({ stringValue -> return stringValue + "_transformed"}) .subscribe({ println "nextElement => " + it}) } // we should an output like this nextElement nextElement nextElement nextElement nextElement Saturday, October 19, 13 => => => => => foo_10_transformed foo_11_transformed foo_12_transformed foo_13_transformed foo_14_transformed
  • 87. More tools: reactive extensions def Observable<T> getData(int id) { if(availableInMemory) { return Observable.create({ observer -> observer.onNext(valueFromMemory); observer.onCompleted(); }) } else { return Observable.create({ observer -> executor.submit({ try { T value = getValueFromRemoteService(id); observer.onNext(value); observer.onCompleted(); }catch(Exception e) { observer.onError(e); } }) }); } } Saturday, October 19, 13
  • 88. Useful approaches Where should I use each tool? Saturday, October 19, 13
  • 89. Layers of complexity Declarative & immutable core Logic or functional programming Futures and/or dataflow Non-determinism when needed Actors, Agents or Rx Shared mutability Protected by Software Transactional Memory Finally, only if it is really needed Locks and explicit threads Saturday, October 19, 13
  • 91. Takeaways Go reactive Avoid locking (share nothing, lock free algs) Already in the JVM? Akka could be good choice Distributed systems are hard Use the correct level of abstraction And remember ... Saturday, October 19, 13
  • 92. Takeaways hammer When all you have is a everything looks like a nail. Choose the right tool for your job! Saturday, October 19, 13
  • 93. Questions? And let’s hope answers Saturday, October 19, 13
  • 95. References: slides, talks and books High Performance Networking in the JVM by Eric Onnen Going reactive talk by Jonas Bonér Introducing Akka by Jonas Bonér The future I was promised by Viktor Klang Real world Akka recipes by Björn Antonsson et all Saturday, October 19, 13
  • 96. References: slides, talks and books Programming Concurrency in the JVM: Mastering synchronization, STM and Actors by Venkat Subramaniam Systems than run forever Self-heal by Joe Amstrong The art of multiprocessor programming, Revised Reprint by Maurice Herlihy Reactive Manifesto Saturday, October 19, 13
  • 97. References: frameworks and toolkits Erlang Akka Toolkit Scala language Vert.x Clojure language GPars Saturday, October 19, 13
  • 98. References: frameworks and toolkits Cloud Haskell NodeJS Netty IO Finagle Saturday, October 19, 13