Top Banner
Ruby goes to @elise_huard Euruko 2011 Monday 30 May 2011
41

Ruby goes to hollywood

Oct 17, 2014

Download

Technology

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ruby goes to hollywood

Rubygoes to

@elise_huard Euruko 2011 Monday 30 May 2011

Page 2: Ruby goes to hollywood

Why Concurrency?

Monday 30 May 2011

Page 3: Ruby goes to hollywood

“... 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

Page 4: Ruby goes to hollywood

Concurrency != Parallellism

Monday 30 May 2011

Page 5: Ruby goes to hollywood

3 threads, 2 cores

1

2

3

1

1

2

3 1

23

core1 core2 core1 core2

Monday 30 May 2011

Page 6: Ruby goes to hollywood

language VM

OS(kernel processes, other processes)

Your program

multicore - multiCPU

Monday 30 May 2011

Page 7: Ruby goes to hollywood

Concurrency will melt your brain

non-determinism

mutable AND shared state

Monday 30 May 2011

Page 8: Ruby goes to hollywood

Actor Model

Monday 30 May 2011

Page 9: Ruby goes to hollywood

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

Page 10: Ruby goes to hollywood

Hewitt et al. 1973

Generalization of the lambda calculus

Monday 30 May 2011

Page 11: Ruby goes to hollywood

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

Page 12: Ruby goes to hollywood

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

Page 13: Ruby goes to hollywood

Implementations

• using threads/processes

• async messaging - mailbox

• pattern matching on incoming messages

• actors = state machines.

Monday 30 May 2011

Page 14: Ruby goes to hollywood

Lifecycle

from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm

Monday 30 May 2011

Page 15: Ruby goes to hollywood

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

Page 16: Ruby goes to hollywood

Monday 30 May 2011

Page 17: Ruby goes to hollywood

Actors in Ruby

Monday 30 May 2011

Page 18: Ruby goes to hollywood

Concurrent gem

theoretical - different concurrency models

https://github.com/mental/concurrent

Monday 30 May 2011

Page 19: Ruby goes to hollywood

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

Page 20: Ruby goes to hollywood

Revactor

concurrent I/O for networking appsEvented rather than parallel

https://github.com/tarcieri/revactor

Monday 30 May 2011

Page 21: Ruby goes to hollywood

Celluloid

thread-based actors

based on erlang

https://github.com/tarcieri/celluloid

Monday 30 May 2011

Page 22: Ruby goes to hollywood

No true parallelism with MRI

Monday 30 May 2011

Page 23: Ruby goes to hollywood

Cheat on Ruby

Monday 30 May 2011

Page 24: Ruby goes to hollywood

Erlang

light-weight processes

= actors

Monday 30 May 2011

Page 25: Ruby goes to hollywood

Erlang

blocking receives

timeouts

supervision trees: fault-tolerance

Monday 30 May 2011

Page 26: Ruby goes to hollywood

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

Page 27: Ruby goes to hollywood

Reia or Elixir

languages on erlang vm

friendlier, more ruby-like, OO

Monday 30 May 2011

Page 28: Ruby goes to hollywood

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

Page 29: Ruby goes to hollywood

Akka

actor model + software transactional memoryjava and scala

Monday 30 May 2011

Page 30: Ruby goes to hollywood

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

Page 31: Ruby goes to hollywood

JRuby!

Monday 30 May 2011

Page 32: Ruby goes to hollywood

Caveat

Monday 30 May 2011

Page 33: Ruby goes to hollywood

Advantages

easy to grasp

real encapsulation - separation of concerns

highly decentralized

Monday 30 May 2011

Page 34: Ruby goes to hollywood

But

many messages (bandwidth)

livelocks are still possible

Monday 30 May 2011

Page 35: Ruby goes to hollywood

Back to Ruby

Monday 30 May 2011

Page 36: Ruby goes to hollywood

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

Page 37: Ruby goes to hollywood

Let’s think about it.

Monday 30 May 2011

Page 38: Ruby goes to hollywood

Thanks@elise_huard

http://www.delicious.com/elisehuard/concurrencyMonday 30 May 2011

Page 39: Ruby goes to hollywood

Ruby goes to

HollywoodElise Huard LRUG 11-04-2011

Monday 30 May 2011

Page 40: Ruby goes to hollywood

Ruby goes to

HollywoodElise Huard LRUG

Monday 30 May 2011

Page 41: Ruby goes to hollywood

Monday 30 May 2011