Présentation effectuée pendant l'Open-XKE de Xebia France.
Ceci est le résultat d'un POC sur la création d'une architecture distribuée de calculs financiers.
On y parle de Scala, programmation fonctionnelle, de Stream, du patter Iteratee, de Akka Actors et Akka Cluster
32. case class Loan(initial: Amount,
duration: Int,
rowIt: RowIt) {
def rows(implicit ctx: ExecutionContext) =
Enumerator.enumerate(
Stream.iterate(first)(f).take(duration)
)
}
Data producer
33. case class Portfolio(loans: Seq[Loansan]) {
def rows(implicit ctx: ExecutionContext) =
Enumerator.interleave(loans.map(_.rows))
}
producers can be
combined
39. object Step {
case class Done[+A, E]
(a: A, remaining: Input[E])
case class Cont[E, +A]
(k: Input[E] => Iteratee[E, A])
case class Error[E]
(msg: String, input: Input[E])
}
53. type RowProducer
= Iterable[Row]
type RowTransformer[T]
= (Row=>T)
type AmountConsumer[T]
= (Iterable[Amount]=>T)
type RowProducer
= Enumerator[Row]
type RowTransformer[T]
= Enumeratee[Row, T]
type AmountConsumer[T]
= Iteratee[Amount, T]
55. // Produce rows
val totalPaidComputation: Future[Amount] =
portfolio.rows &> totalPaid |>>> sum
// Blocking the thread to wait for the result
val totalPaid =
Await.result(
totalPaidComputation,
atMost = defaultTimeout)
totalPaid should equal(3480 EUR)
56. We still have function composition
and prepares the code for asynchronism
83. Step 1
Step 2
Step 3
Stream API
Iteratees
Akka actor
5000 loans
50 rows
5000 loans
50 rows
5000 loans
50 rows
~ 560 ms
~ 4571 ms
~ 4271 ms
with pause
with pause
with pause
~ 144900 ms
~ 39042 ms
~ 40882 ms
100. Pros
Cons
Error management
No on demand computation
Function composition
Network serialization
Parallel computation
Asynchronism
Elasticity
Resilience
101. Step 1
Step 2
Step 3
Step 4
Stream API
Iteratees
Akka actor
Akka cluster
5000 loans
50 rows
5000 loans
50 rows
5000 loans
50 rows
5000 loans
50 rows
~ 560 ms
~ 4571 ms
~ 4271 ms
~ 6213 ms
with pause
with pause
with pause
with pause
~ 144900 ms
~ 39042 ms
~ 40882 ms
~ 77957 ms
1 node / 2 actors
102. Step 1
Step 2
Step 3
Step 4
Stream API
Iteratees
Akka actor
Akka cluster
5000 loans
50 rows
5000 loans
50 rows
5000 loans
50 rows
5000 loans
50 rows
~ 560 ms
~ 4571 ms
~ 4271 ms
~ 5547 ms
with pause
with pause
with pause
with pause
~ 144900 ms
~ 39042 ms
~ 40882 ms
~ 39695 ms
2 nodes / 4 actors
104. Step 1
Step 2
Step 3
Step 4
Stream API
Iteratees
Akka actor
Akka cluster
powerful library
elegant API
error
management
elasticity
low memory
enable
asynchronism
and parallelism
control on
parallel execution
via configuration
resilience
performance
when single
threaded
monitoring
107. Hot subject
Recet blog post from «Mandubian» for Scalaz stream machines and
iteratees [1]
Recent presentation from «Heather Miller» for spores (distribuables
closures) [2]
Recent release of Scala 2.10.3 and performance optimization of Promise
Release candidate of play-iteratee module with performance optimization
Lots of stuff in the roadmap of Akka cluster 2.3.0
108. Hot subject
[1] : http://mandubian.com/2013/08/21/playztream/
[2] : https://speakerdeck.com/heathermiller/on-pickles-and-sporesimproving-support-for-distributed-programming-in-scala