The document discusses concurrency and the actor model. It notes that as processors are no longer getting significantly faster, programs need to be parallelized to run faster. The actor model is introduced as a way to build concurrent programs where actors communicate asynchronously by message passing and have no shared state, avoiding issues like race conditions. Several Ruby libraries and frameworks for implementing the actor model are described, including Celluloid and Akka. The advantages of the actor model like encapsulation and decentralization are highlighted, though issues like potential for livelocks are also noted.
3. “... for the first time in history, no one is
building a much faster sequential processor.
If you want your programs to run
significantly faster (...) you’re going to have to
parallelize your program.”
Hennessy and Patterson
“Computer Architectures” (4th edition, 2007)
Monday 30 May 2011
9. Hewitt et al. 1973
no shared state
in response to a message, an actor can:
make local decisions
create more actors
send more messages
determine how to respond to the next message
received
Monday 30 May 2011
10. Hewitt et al. 1973
Generalization of the lambda
calculus
Monday 30 May 2011
11. Inspiration
artificial intelligence
‘quantum mechanics’ - observing details
by which the order of arrival of
messages for an actor is determined
can affect result
Monday 30 May 2011
12. The point
only actors - no global state
partial order of execution
from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm
Monday 30 May 2011
13. Implementations
• using threads/processes
• async messaging - mailbox
• pattern matching on incoming messages
• actors = state machines.
Monday 30 May 2011
14. Lifecycle
from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm
Monday 30 May 2011
15. Sleeping barber
shop with x chairs
1 barber
no customer: sleep. customers: cut hairs
customer
if barber is sleeping: wake him up
else if enough chairs take a chair
else leave
Monday 30 May 2011
26. Erlectricity
require 'rubygems'
require 'erlectricity'
receive do |f|
f.when([:echo, String]) do |text|
f.send!([:result, "You said: #{text}"])
f.receive_loop
end
end
https://github.com/mojombo/erlectricity
Monday 30 May 2011
27. Reia or Elixir
languages on erlang vm
friendlier, more ruby-like, OO
Monday 30 May 2011
28. Scala
“We also included enhancements to make it
easier to call from Ruby into Scala libraries,
which has enabled the Lift web framework to
offer support for Ruby.” Charles Nutter, ‘JRuby 1.6 released,
now what ?’
http://www.engineyard.com/blog/2011/jruby-1-6-released-now-what/
Actors in standard library
Monday 30 May 2011
29. Akka
actor model + software transactional memory
java and scala
Monday 30 May 2011
30. Akka
• sending: reply is possible or not, sync or
async
• supervision: several strategies
• as library or as framework
• local and distributed
Monday 30 May 2011
36. Time to control
shared state ?
Change RubySpec:
default: variables not shared between
threads?
integrate better concurrency primitives
into the Ruby stdlib ?
Monday 30 May 2011