Post on 20-Jan-2015
description
Rubygoes to
Hollywood@elise_huard LRUG
Tuesday 12 April 2011
Why Concurrency?
Tuesday 12 April 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)
Tuesday 12 April 2011
Concurrent programs
!=Parallel computing
Tuesday 12 April 2011
3 threads, 2 cores
1
2
3
1
1
2
3 1
23
core1 core2 core1 core2
Tuesday 12 April 2011
language VM
OS(kernel processes, other processes)
Your program
multicore - multiCPU
Tuesday 12 April 2011
Concurrency will melt your brain
non-determinism
shared state
Tuesday 12 April 2011
Actor Model
Tuesday 12 April 2011
no shared statein response to a message that it receives, an actor can:make local decisionscreate more actorssend more messagesdetermine how to respond to the next message received
Hewitt et al. 1973
Tuesday 12 April 2011
Inspiration
Artificial Intelligence
quantum mechanics - we cannot observe the details by which the order of arrival of messages for an actor is determined. attempting to do so can affect result and push indeterminacy elsewhere.
Tuesday 12 April 2011
only actors
no global state
partial order of execution
The point
Tuesday 12 April 2011
Actors in Ruby
Tuesday 12 April 2011
definitely not parallel
Tuesday 12 April 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"
Tuesday 12 April 2011
Revactor
sock = Revactor::TCP.connect(host, port)listener = Revactor::TCP.listen(addr, port)sock = listener.accept
sock.controller = Actor.currentsock.active = trueActor.receive do |filter| filter.when(Case[:tcp, sock, Object]) do |_, _, data| ... end filter.when(Case[:somethingelse, Object]) do |_, message| ... endend
Tuesday 12 April 2011
Concurrent gem
theoretical - different concurrency models
use rubinius style actors in other versions of Ruby
https://github.com/mental/concurrent
Tuesday 12 April 2011
Meh.
Tuesday 12 April 2011
Cheat on Ruby
Tuesday 12 April 2011
Erlang
light-weight processes
= actors
Tuesday 12 April 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
Tuesday 12 April 2011
Erlectricity
-module(echo).-export([test/0]).
test() -> Cmd = "ruby echo.rb", Port = open_port({spawn, Cmd}, [{packet, 4}, nouse_stdio, exit_status, binary]), Payload = term_to_binary({echo, <<"hello world!">>}), port_command(Port, Payload), receive {Port, {data, Data}} -> {result, Text} = binary_to_term(Data), io:format("~p~n", [Text]) end.
Tuesday 12 April 2011
BERT RPC
BERT (Binary ERlang Term) serialization library for Ruby.
convert data into erlang binary format before sending them over the wire
Tuesday 12 April 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
Tuesday 12 April 2011
Akka
https://github.com/danielribeiro/RubyOnAkka
Tuesday 12 April 2011
Back to Ruby
Tuesday 12 April 2011
Time to control shared state ?
Change RubySpec ?
default variables: not shared between threads
have keyword for shared variables
Tuesday 12 April 2011
Let’s think about it.
Tuesday 12 April 2011
Thanks@elise_huard
Tuesday 12 April 2011
Ruby goes to
HollywoodElise Huard LRUG 11-04-2011
Tuesday 12 April 2011
Ruby goes to
HollywoodElise Huard LRUG
Tuesday 12 April 2011