Ruby goes to @elise_huard Euruko 2011 Monday 30 May 2011
Rubygoes to
@elise_huard Euruko 2011 Monday 30 May 2011
Why Concurrency?
Monday 30 May 2011
“... 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
Concurrency != Parallellism
Monday 30 May 2011
3 threads, 2 cores
1
2
3
1
1
2
3 1
23
core1 core2 core1 core2
Monday 30 May 2011
language VM
OS(kernel processes, other processes)
Your program
multicore - multiCPU
Monday 30 May 2011
Concurrency will melt your brain
non-determinism
mutable AND shared state
Monday 30 May 2011
Actor Model
Monday 30 May 2011
no shared statein response to a message, an actor can:make local decisionscreate more actorssend more messagesdetermine how to respond to the next message received
Hewitt et al. 1973
Monday 30 May 2011
Hewitt et al. 1973
Generalization of the lambda calculus
Monday 30 May 2011
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
only actors - no global state
partial order of execution
The point
from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm
Monday 30 May 2011
Implementations
• using threads/processes
• async messaging - mailbox
• pattern matching on incoming messages
• actors = state machines.
Monday 30 May 2011
Lifecycle
from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm
Monday 30 May 2011
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
Monday 30 May 2011
Actors in Ruby
Monday 30 May 2011
Concurrent gem
theoretical - different concurrency models
https://github.com/mental/concurrent
Monday 30 May 2011
Rubinius Actors
require 'actor'
actor = Actor.spawn(Actor.current) do |master| msg = Actor.receive master.send msgend
actor.send "test"msg = Actor.receive# msg == "test"
Monday 30 May 2011
Revactor
concurrent I/O for networking appsEvented rather than parallel
https://github.com/tarcieri/revactor
Monday 30 May 2011
Celluloid
thread-based actors
based on erlang
https://github.com/tarcieri/celluloid
Monday 30 May 2011
No true parallelism with MRI
Monday 30 May 2011
Cheat on Ruby
Monday 30 May 2011
Erlang
light-weight processes
= actors
Monday 30 May 2011
Erlang
blocking receives
timeouts
supervision trees: fault-tolerance
Monday 30 May 2011
Erlectricity
require 'rubygems'
require 'erlectricity'
receive do |f| f.when([:echo, String]) do |text| f.send!([:result, "You said: #{text}"]) f.receive_loop endend
https://github.com/mojombo/erlectricity
Monday 30 May 2011
Reia or Elixir
languages on erlang vm
friendlier, more ruby-like, OO
Monday 30 May 2011
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
Akka
actor model + software transactional memoryjava and scala
Monday 30 May 2011
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
JRuby!
Monday 30 May 2011
Caveat
Monday 30 May 2011
Advantages
easy to grasp
real encapsulation - separation of concerns
highly decentralized
Monday 30 May 2011
But
many messages (bandwidth)
livelocks are still possible
Monday 30 May 2011
Back to Ruby
Monday 30 May 2011
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
Let’s think about it.
Monday 30 May 2011
Thanks@elise_huard
http://www.delicious.com/elisehuard/concurrencyMonday 30 May 2011
Ruby goes to
HollywoodElise Huard LRUG 11-04-2011
Monday 30 May 2011
Ruby goes to
HollywoodElise Huard LRUG
Monday 30 May 2011
Monday 30 May 2011