Michał Tomański
A pure function always computes the same value given the same parameters.
sin(pi/2)
class BankAccount {
private balance;
public withdraw() {
this.balance = balance > 100 ? balance - 100 : 0;
return balance
}
}
simple-db-lookups {
fork-join-executor {parallelism-factor = 10.0}
}
expensive-db-lookups {
fork-join-executor {parallelism-max = 4}
}
db-write-operations {
fork-join-executor {parallelism-factor = 2.0}
}
expensive-cpu-operations {
fork-join-executor {parallelism-max = 2}
}
Divide and conquer algorithm
Lightweight threads
Threads stealing
solve(problem):
if problem is small enough:
solve problem directly (sequential algorithm)
else:
for part in subdivide(problem)
fork subtask to solve part
join all subtasks spawned in previous loop
combine results from subtasks
Thread pools
Futures
Text
Reactive Streams
class Buncher extends FSM[State, Data] {
startWith(Idle, Uninitialized)
when(Idle) {
case Event(SetTarget(ref), Uninitialized) =>
stay using Todo(ref, Vector.empty)
}
when(Active, stateTimeout = 1 second) {
case Event(Flush | StateTimeout, t: Todo) =>
goto(Idle) using t.copy(queue = Vector.empty)
}
initialize()
}
CQRS / Event Sourcing
Chaotic Monkeys
Increase latency
Throw exceptions
Return 500 response code
Kill a node
Kill a store
Coursera:
Conferences: