SlideShare una empresa de Scribd logo
1 de 58
Guild Prototype
Koichi Sasada
Cookpad Inc.
<ko1@cookpad.com>
RubyKaigi 2016 talk
RubyKaigi 2016 talk
TL;DR
•We can run parallel programs with Guilds
•Current implementation is too preliminary
and so buggy (easy to halt)
→ “Thread programming” is too hard
for human beings.
Today’s talk
•Background of Guild
•Demonstrations
•Guild specifications (ideas)
•Guild implementations (w/ future plan)
•Synchronizations
•Performance optimizations
Koichi Sasada
http://atdot.net/~ko1/
•A programmer
•2006-2012 Faculty
•2012-2017 Heroku, Inc.
•2017- Cookpad Inc.
•Job: MRI development
•Core parts
• VM, Threads, GC, etc
Recent achievements for Ruby 2.6
•Speedup `Proc#call` … x1.4 improvements
[Bug #10212].
•Speedup `block.call` where `block` is
passed block parameter. [Feature #14330]
(x2.62).
Advertisement
Cookpad booth events
【Day 2】
15:20~15:50 Global Office Hours
【Day 3】
12:00~13:00 Q&A with @wyhaines
15:20~15:50 Ruby interpreter developme
live by @ko1 & @mame
Cookpad X RubyKaigi 2018: Day 2 Party
⏰ June 1st, 19:30 - 21:30 (opens 19:00)
💰 Free (Registration required)
Show up to this booth at 18:40 if you want to head with us!
Background of
Guild
Motivation
Productivity (most important for Ruby)
• Thread programming is too difficult
• Making correct/safe concurrent programs easily
Performance by Parallel execution
• Making parallel programs
• Threads can make concurrent programs, but can’t run them
in parallel on MRI (CRuby)
• People want to utilize Multi/many CPU cores
RubyKaigi2016 Proposal
Guild: new concurrency abstraction for Ruby 3
• Idea: DO NOT SHARE mutable objects between Guilds
→ No data races, no race conditions
Replace Threads to Guilds
Guilds, Threads and Fibers
• Guild has at least one thread (and a thread has at
least one fiber)
• Threads in different Guilds can run in parallel
Guild
Thread
Fiber
Guild
Thread
Fiber
Guild
Thread
Fiber
Fiber
Thread
Fiber
Design “Shareable” and “non-sharable”
• Non-shareable objects
• (normal) Mutable objects (String, Array, …)
• They are members of only one Guild
• Using only 1 Guild, it compatible with Ruby 2
Guild 1 Guild 2
obj
obj
obj
obj
obj
Can’t access
(read/write)
NG!!
Demonstrations
Demonstration (on 40 vCPUs)
•CPU 40 virtual CPUs (2 x 10 x 2)
•x 2 CPUs
•Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
• x10 cores
• x2 hyper threading
•Ubuntu 16.10
•Already EOL 
Demonstration (on 40 vCPUs)
•Workload
•Calculate fib(23) x 100_000 times
• Serial version: 100_000.times{ fib(23) }
• Guild version:
main
Guild
FibHub
Guild
fib
workerfib
worker
fib
worker
…load balancing
We can change
# of workers
FIBHUB = make_worker_hub do |n|
[n, fib(n)]
end
# library
def make_worker_hub n_workers = WN, &worker_proc
pp WN: n_workers if $VERBOSE
Guild.new(n_workers, worker_proc) do |nw, wp|
guilds = nw.times.map do
Guild.new do
while data = Guild.receive
result = wp.call(data)
Guild.parent << [:ans, Guild.current, result]
end
end
end
requests = []
while true
cmd, sender_guild, data = *Guild.receive
case cmd
when :req
if g = guilds.pop
g << data
else
requests << data
end
when :ans
Guild.parent << data
if req = requests.pop
sender_guild << req
else
guilds << sender_guild
end
end
end
end
end
# Make worker guilds # Receive an answers from workers
# Send a remaining task
# to the worker if exists
# Send a task
# if an idle worker is available
# Receive a request from master
# Send an answers to master
# You don’t need to write such common code
# but we provide some kind of a framework
https://gist.github.com/ko1/e5327126a77e078a0ffdf005013592ea
fib(23) with # of Guilds on 40 vCPUs
0
10
20
0 20 40 60 80 100
# of Guilds
Speedup ratio (compare with serial execution)
Demonstration (on 40 vCPUs)
•Workload
•Calculate fib(n) x 100_000 times (0 ≦n≦30)
• Serial version: 100_000.times{ fib(23) }
• Guild version: 40 Guilds
main
Guild
FibHub
Guild
fib
workerfib
worker
fib
worker
…load balancing
Execution time (sec) of fib(n) x 100_000
with 40 Guilds on 40 vCPUs
0
5000
10000
15000
0 5 10 15 20 25 30 35
sec
n for fib(n)
real (sec) real-serial (sec)
12,896.23 sec
=~ 3.5 hours
791.2541 sec
=~ 13 minutes
Order of fib(n) is “O(2^n)”
fib(n) with 40 Guilds on 40 vCPUs
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0 5 10 15 20 25 30 35
Speedupratiocompare
withserialexecution
n for fib(n)
Slower Faster
fib(9): about 100 recursive calls
Demonstration (on 40 virtual CPU)
•Workload
•Calculate wordcount for files and find a file
which contains maximum number of words.
• on “ruby/test/**/*” files (1,108 files)
def word_count file
r = File.read(file).b.upcase.split(/¥W/).uniq.size
end
Demonstration (on 40 virtual CPU)
•Workload
•Calculate wordcount for files and find a file
which contains maximum number of words.
• on “ruby/test/**/*” files (1,108 files)
main
Guild
WCHub
Guild
wc
workerwc
worker
wc
worker
…load balancing
We can change
# of workers
traverse directories,
correct wc results,
and calculate maximum
Demonstration (on 40 virtual CPU)
1.736429 1.652815
2.473468
6.136364
0
5
10
Serial 1 Guold 2 Guild 40 Guilds
Executiontime
(sec)
It is SLOW with multiple Guilds
because GC/object allocation require naïve global locking
(current implementation limitation) and huge contentions.
Guild
Specification
Temporary one.
Guilds, Threads and Fibers
•Guild has at least one thread (and a thread
has at least one fiber)
Guild
Thread
Fiber
Guild
Thread
Fiber
Guild
Thread
Fiber
Fiber
Thread
Fiber
Threads in different guilds
can run in PARALLEL
•Threads in different guilds can run in parallel
•Threads in a same guild can not run in parallel
because of GVL (or GGL: Giant Guild Lock)
G1:T1
G1:T2
G2:T3
Acquire GGL
Acquire GGL
Making Guilds
g1 = Guild.new do
expr1
end
g2 = Guild.new do
expr2
end
# Two new Guilds and Threads are created
# expr1 and expr2 can run in parallel
Inter-Guild communication
Share only “shareable” objects
Shareable
obj1
Shareable
obj2
Guild 1 Guild 2
normal
mutable
obj1
normal
mutable
obj2
Design “Shareable” and “non-sharable”
•You can enjoy usual mutating
programming without any thread-safe
concerns.
•Because we can’t share mutable objects
between Guilds. They are “non-sharable”.
•In other words, you can’t make thread-
unsafe (data-racy) programs with Guilds.
Design “Shareable” and “non-sharable”
•You need to use “Sharable” objects to share
objects between Guilds
•On concurrent programs, most of objects are
not shared (thread-local)
•Tons of local objects and a few sharing objects
•You only need to care about a few objects
non-
sharable
non-
sharable
non-
sharable
non-
sharable sharable
sharable
non-
sharable
non-
sharable
non-
sharable
non-
sharable
non-
sharable
non-
sharable
non-
sharable
non-
sharablenon-
sharable
non-
sharable
non-
non-
sharable
Design “Shareable” and “non-sharable”
•Non-shareable objects
•(normal) Mutable objects (String, Array, …)
•They are member of only one Guild
•Using only 1 Guild, it compatible with Ruby 2
Guild 1 Guild 2
obj
obj
obj
obj
obj
Can’t access
(read/write)
NG!!
Design “Shareable” and “non-sharable”
•Shareable objects
•(1) Immutable objects (Numeric, Symbol, …)
•(2) Class/Module objects
•(3) Special mutable objects
•(4) Isolated Proc
Shareable objects
(1) Immutable objects
• Immutable objects can be shared with any guilds
• Because no mutable operations for them
• “Immutable” != “Frozen”
• a1 = [1, 2, 3].freeze: a1 is Immutable
• a2 = [1, Object.new, 3].freeze: a2 is not Immutable
• Maybe we will introduce deep freeze feature
• Numeric objects, symbols, true, false, nil are immutable
(from Ruby 2.0, 2.1, 2.2)
• Frozen string objects are immutable (if they don’t have
instance variables)
Shareable objects
(2) Class/Module objects
•All objects (including any sharable objects) point
to own classes
• Good: Sharing class/module objects makes program
easier
• Bad: They can point to other mutable objects with
Constants, @@class_variable and @instance_variables
class C
Const = [1, 2, 3] # Const points a mutable
array
end
# We will introduce special protocol for them
Shareable objects
(3) Special mutable objects
• Introduce shared/concurrent data structure
• Shared hash, array, …
• Software transactional memory (from Clojure, …), …
• Guild objects and so on
• They require special process to force
synchronization explicitly
• They can’t mutate without synchronizations.
• Easy to make correct concurrent programs
• Compared with normal Array, Hash, … they should
require special synchronization protocol to access
Shareable objects
(4) Isolated Proc
•Normal Proc can point to mutable objects with
outer local variable (free-variables)
• a = []; Proc.new{p a}.call
•Introduce Isolated Proc (made by
Proc#isolate) which is prohibited to access
outer variables
a = []; Proc.new{p a}.isolate.call
#=> RuntimeError (can’t access a)
•(there are more details but skip)
Shareable objects
(4) Isolated Proc
# Initial block for Guild is isolated
proc
g1 = Guild.new do
expr1 # Make isolated block and invoke
end
g2 = Guild.new do
p g1 #=> RuntimeError (can’t access
“g1”)
# because block is isolated
end
Inter-Guild communication API
•Actor model, send/receive semantics
•Destination addresses are represented by
Guild itself like Erlang/Elixir processes
•Sending shareable objects means sending
only references to the objects (lightweight)
•Two methods to send non-shareable objects
• (1) COPY
• (2) MOVE
Sending objects between Guilds
g1 = Guild.new do # create Isolated Proc
n = Guild.receive
r = fib(n)
Guild.parent << r
end
g1 << 30
p Guild.receive #=> 1346269
Sending shareable objects
Guild1: g1 Guild2: g2
o2
o3
o1
g2 << o1 o1 =Guild.receive
O2:Data O3:Data
Sending non-shareable objects
(1) Send by Copy
Guild1 Guild2
o2
o3
o1
channel
o2
o3
o1
COPY
g2 << o1 o1 = Guild.receive
O2:Data
O3:Data
O2:Data
O3:Data
Sending non-shareable objects
(2) Send by Move
Guild1 Guild2
o2
o3
o1
channel
MOVE
g2.move(o1) o1 =Guild.receive
O2:Data
O3:Data
Sending non-shareable objects
(2) Send by Move
Guild1 Guild2
channel
o2
o3
o1
MOVE
g2.move(o1) o1 = Guild.receive
O2:Data
O3:Data
-
-
-
From Guild1 perspective,
sent objects are invalidated
Sending non-shareable objects
(2) Send by Move
•If we don’t access sent objects after
sending them (and there are many such
cases), we can send them faster
•Examples
•Huge string data
•I/O operation (send request I/O to workers)
Summary of object sharing/non-sharing
• Shareable objects
• Several types of shareable objects
• We can share them between Guilds
• They requires special synchronization protocol to mutate them
• Non-sharable objects
• Normal mutable objects (like String, Array, …)
• Only one Guild can access such objects == membership
• We can send them by COPY or MOVE
• Mutable objects are NOT shared accidentally as Thread
programming → Correct concurrent Prog.
Guild
Implementation
Preliminary implementation includes many bugs, performance issues.
Guild context
•Before Guild
•VM -> *Threads -> *Fibers
•After Guild
•VM -> *Guilds -> *Threads -> *Fibers
•Introduce rb_guild_t.
Introduce synchronizations
•Before Guild
•Multiple threads cannot run simultaneously
•After Guild
•Run (native) threads in parallel
•Need to introduce so many synchronizations
•Introduce VM-wide locks for VM-wide resources
•It is the multi-thread programming!!
Garbage collection
•Stop all Guilds (threads) at GC process
G1:T1
G2:T2
G3:T3
GC process
Pause
request
Restart
request
Future work and optimizations
•Features
•Prohibit sharing non-sharable objects
•Introduce synchronizations to protect VM-
wide resources (process-global)
•Introduce “sharable” object protocols
•Performance
•Reduce synchronizations
•Per Guild Garbage collection
•Introduce new “C API” to reduce TLS access
Future optimizations
• Koichi Sasada, et.al. : An
Implementation of Parallel
Threads for YARV: Yet Another
RubyVM (2007)
• They introduced several
optimization techniques to reduce
synchronizations
One more thing…
Naming of “Guild”
Why “Guild”?
•Prefix should be different from “P”
(Process), “T” (Therad) and “F” (Fiber).
•Ownership can be explained with the word
“Membership”.
•All (normal) objects belong to one Guild.
•Easy to explain “Move” semantics
Any problem?
•“Move” operation is not so popular operation
(most of case “copy” is enough)
•No other languages use this terminology
•Naming is important
•Just now “Guild” is a code name of this
project
Today’s talk
•Background of Guild
•Demonstrations
•Guild specifications (ideas)
•Guild implementations (w/ future plan)
•Synchronizations
•Performance optimizations
Guild Prototype
Koichi Sasada
Cookpad Inc.
<ko1@cookpad.com>
Thank you for your attention
Pros./Cons. Matrix
Process Guild Thread Auto-Fiber Fiber
Available Yes No Yes No Yes
Switch on
time
Yes Yes Yes No No
Switch on I/O Auto Auto Auto Auto No
Next target Auto Auto Auto Auto Specify
Parallel run Yes Yes No (on MRI) No No
Shared data N/A (mostly) N/A Everything Everything Everything
Comm. Hard Maybe Easy Easy Easy Easy
Programming
difficulty
Hard Easy Difficult Easy Easy
Debugging
difficulty
Easy? Maybe Easy Hard Maybe hard Easy

Más contenido relacionado

La actualidad más candente

Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)mircodotta
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015Charles Nutter
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Insidejeffz
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type scriptDmitrii Stoian
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?Roman Elizarov
 
Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Anton Arhipov
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandCharles Nutter
 
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Steven Francia
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMCharles Nutter
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015Charles Nutter
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With ScalaTomer Gabel
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)mircodotta
 
Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014Stefanus Du Toit
 
Kotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designKotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designAndrey Breslav
 

La actualidad más candente (20)

Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
PHP7
PHP7PHP7
PHP7
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
 
Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
 
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)
 
Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014Hourglass Interfaces for C++ APIs - CppCon 2014
Hourglass Interfaces for C++ APIs - CppCon 2014
 
Kotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designKotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language design
 

Similar a Guild Prototype

The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtugVk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtugketan_patel25
 
Apache Storm 0.9 basic training - Verisign
Apache Storm 0.9 basic training - VerisignApache Storm 0.9 basic training - Verisign
Apache Storm 0.9 basic training - VerisignMichael Noll
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Haim Yadid
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Felix Geisendörfer
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Railselliando dias
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)daylerees
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?hawkowl
 
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talkdotCloud
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage SystemsSATOSHI TAGOMORI
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring ClojurescriptLuke Donnet
 
Getting startedwith noir-clojureexchange-2011
Getting startedwith noir-clojureexchange-2011Getting startedwith noir-clojureexchange-2011
Getting startedwith noir-clojureexchange-2011John Stevenson
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeEdward Capriolo
 
Building your own NSQL store
Building your own NSQL storeBuilding your own NSQL store
Building your own NSQL storeEdward Capriolo
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeEdward Capriolo
 
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Mike Broberg
 

Similar a Guild Prototype (20)

Eusecwest
EusecwestEusecwest
Eusecwest
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtugVk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
 
Apache Storm 0.9 basic training - Verisign
Apache Storm 0.9 basic training - VerisignApache Storm 0.9 basic training - Verisign
Apache Storm 0.9 basic training - Verisign
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
Hands on Gradle
Hands on GradleHands on Gradle
Hands on Gradle
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?
 
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talk
 
cadec-2017-golang
cadec-2017-golangcadec-2017-golang
cadec-2017-golang
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Getting startedwith noir-clojureexchange-2011
Getting startedwith noir-clojureexchange-2011Getting startedwith noir-clojureexchange-2011
Getting startedwith noir-clojureexchange-2011
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL store
 
Building your own NSQL store
Building your own NSQL storeBuilding your own NSQL store
Building your own NSQL store
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL store
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
 

Más de Koichi Sasada

Ruby's Concurrency Management: Now and Future
Ruby's Concurrency Management: Now and FutureRuby's Concurrency Management: Now and Future
Ruby's Concurrency Management: Now and FutureKoichi Sasada
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th yearKoichi Sasada
 
Rubyにおけるトレース機構の刷新
Rubyにおけるトレース機構の刷新Rubyにおけるトレース機構の刷新
Rubyにおけるトレース機構の刷新Koichi Sasada
 
Rubyインタプリタ開発者養成講座
Rubyインタプリタ開発者養成講座Rubyインタプリタ開発者養成講座
Rubyインタプリタ開発者養成講座Koichi Sasada
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th yearKoichi Sasada
 
Cookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 RubyをコンパイルしようCookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 RubyをコンパイルしようKoichi Sasada
 

Más de Koichi Sasada (7)

Ruby's Concurrency Management: Now and Future
Ruby's Concurrency Management: Now and FutureRuby's Concurrency Management: Now and Future
Ruby's Concurrency Management: Now and Future
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th year
 
Rubyにおけるトレース機構の刷新
Rubyにおけるトレース機構の刷新Rubyにおけるトレース機構の刷新
Rubyにおけるトレース機構の刷新
 
Rubyインタプリタ開発者養成講座
Rubyインタプリタ開発者養成講座Rubyインタプリタ開発者養成講座
Rubyインタプリタ開発者養成講座
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th year
 
Cookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 RubyをコンパイルしようCookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
 
Ruby 2.4 Internals
Ruby 2.4 InternalsRuby 2.4 Internals
Ruby 2.4 Internals
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Guild Prototype

  • 1. Guild Prototype Koichi Sasada Cookpad Inc. <ko1@cookpad.com>
  • 4. TL;DR •We can run parallel programs with Guilds •Current implementation is too preliminary and so buggy (easy to halt) → “Thread programming” is too hard for human beings.
  • 5. Today’s talk •Background of Guild •Demonstrations •Guild specifications (ideas) •Guild implementations (w/ future plan) •Synchronizations •Performance optimizations
  • 6. Koichi Sasada http://atdot.net/~ko1/ •A programmer •2006-2012 Faculty •2012-2017 Heroku, Inc. •2017- Cookpad Inc. •Job: MRI development •Core parts • VM, Threads, GC, etc
  • 7. Recent achievements for Ruby 2.6 •Speedup `Proc#call` … x1.4 improvements [Bug #10212]. •Speedup `block.call` where `block` is passed block parameter. [Feature #14330] (x2.62).
  • 8. Advertisement Cookpad booth events 【Day 2】 15:20~15:50 Global Office Hours 【Day 3】 12:00~13:00 Q&A with @wyhaines 15:20~15:50 Ruby interpreter developme live by @ko1 & @mame Cookpad X RubyKaigi 2018: Day 2 Party ⏰ June 1st, 19:30 - 21:30 (opens 19:00) 💰 Free (Registration required) Show up to this booth at 18:40 if you want to head with us!
  • 10. Motivation Productivity (most important for Ruby) • Thread programming is too difficult • Making correct/safe concurrent programs easily Performance by Parallel execution • Making parallel programs • Threads can make concurrent programs, but can’t run them in parallel on MRI (CRuby) • People want to utilize Multi/many CPU cores
  • 11. RubyKaigi2016 Proposal Guild: new concurrency abstraction for Ruby 3 • Idea: DO NOT SHARE mutable objects between Guilds → No data races, no race conditions Replace Threads to Guilds
  • 12. Guilds, Threads and Fibers • Guild has at least one thread (and a thread has at least one fiber) • Threads in different Guilds can run in parallel Guild Thread Fiber Guild Thread Fiber Guild Thread Fiber Fiber Thread Fiber
  • 13. Design “Shareable” and “non-sharable” • Non-shareable objects • (normal) Mutable objects (String, Array, …) • They are members of only one Guild • Using only 1 Guild, it compatible with Ruby 2 Guild 1 Guild 2 obj obj obj obj obj Can’t access (read/write) NG!!
  • 15. Demonstration (on 40 vCPUs) •CPU 40 virtual CPUs (2 x 10 x 2) •x 2 CPUs •Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz • x10 cores • x2 hyper threading •Ubuntu 16.10 •Already EOL 
  • 16. Demonstration (on 40 vCPUs) •Workload •Calculate fib(23) x 100_000 times • Serial version: 100_000.times{ fib(23) } • Guild version: main Guild FibHub Guild fib workerfib worker fib worker …load balancing We can change # of workers
  • 17. FIBHUB = make_worker_hub do |n| [n, fib(n)] end # library def make_worker_hub n_workers = WN, &worker_proc pp WN: n_workers if $VERBOSE Guild.new(n_workers, worker_proc) do |nw, wp| guilds = nw.times.map do Guild.new do while data = Guild.receive result = wp.call(data) Guild.parent << [:ans, Guild.current, result] end end end requests = [] while true cmd, sender_guild, data = *Guild.receive case cmd when :req if g = guilds.pop g << data else requests << data end when :ans Guild.parent << data if req = requests.pop sender_guild << req else guilds << sender_guild end end end end end # Make worker guilds # Receive an answers from workers # Send a remaining task # to the worker if exists # Send a task # if an idle worker is available # Receive a request from master # Send an answers to master # You don’t need to write such common code # but we provide some kind of a framework https://gist.github.com/ko1/e5327126a77e078a0ffdf005013592ea
  • 18. fib(23) with # of Guilds on 40 vCPUs 0 10 20 0 20 40 60 80 100 # of Guilds Speedup ratio (compare with serial execution)
  • 19. Demonstration (on 40 vCPUs) •Workload •Calculate fib(n) x 100_000 times (0 ≦n≦30) • Serial version: 100_000.times{ fib(23) } • Guild version: 40 Guilds main Guild FibHub Guild fib workerfib worker fib worker …load balancing
  • 20. Execution time (sec) of fib(n) x 100_000 with 40 Guilds on 40 vCPUs 0 5000 10000 15000 0 5 10 15 20 25 30 35 sec n for fib(n) real (sec) real-serial (sec) 12,896.23 sec =~ 3.5 hours 791.2541 sec =~ 13 minutes Order of fib(n) is “O(2^n)”
  • 21. fib(n) with 40 Guilds on 40 vCPUs 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 0 5 10 15 20 25 30 35 Speedupratiocompare withserialexecution n for fib(n) Slower Faster fib(9): about 100 recursive calls
  • 22. Demonstration (on 40 virtual CPU) •Workload •Calculate wordcount for files and find a file which contains maximum number of words. • on “ruby/test/**/*” files (1,108 files) def word_count file r = File.read(file).b.upcase.split(/¥W/).uniq.size end
  • 23. Demonstration (on 40 virtual CPU) •Workload •Calculate wordcount for files and find a file which contains maximum number of words. • on “ruby/test/**/*” files (1,108 files) main Guild WCHub Guild wc workerwc worker wc worker …load balancing We can change # of workers traverse directories, correct wc results, and calculate maximum
  • 24. Demonstration (on 40 virtual CPU) 1.736429 1.652815 2.473468 6.136364 0 5 10 Serial 1 Guold 2 Guild 40 Guilds Executiontime (sec) It is SLOW with multiple Guilds because GC/object allocation require naïve global locking (current implementation limitation) and huge contentions.
  • 26. Guilds, Threads and Fibers •Guild has at least one thread (and a thread has at least one fiber) Guild Thread Fiber Guild Thread Fiber Guild Thread Fiber Fiber Thread Fiber
  • 27. Threads in different guilds can run in PARALLEL •Threads in different guilds can run in parallel •Threads in a same guild can not run in parallel because of GVL (or GGL: Giant Guild Lock) G1:T1 G1:T2 G2:T3 Acquire GGL Acquire GGL
  • 28. Making Guilds g1 = Guild.new do expr1 end g2 = Guild.new do expr2 end # Two new Guilds and Threads are created # expr1 and expr2 can run in parallel
  • 29. Inter-Guild communication Share only “shareable” objects Shareable obj1 Shareable obj2 Guild 1 Guild 2 normal mutable obj1 normal mutable obj2
  • 30. Design “Shareable” and “non-sharable” •You can enjoy usual mutating programming without any thread-safe concerns. •Because we can’t share mutable objects between Guilds. They are “non-sharable”. •In other words, you can’t make thread- unsafe (data-racy) programs with Guilds.
  • 31. Design “Shareable” and “non-sharable” •You need to use “Sharable” objects to share objects between Guilds •On concurrent programs, most of objects are not shared (thread-local) •Tons of local objects and a few sharing objects •You only need to care about a few objects non- sharable non- sharable non- sharable non- sharable sharable sharable non- sharable non- sharable non- sharable non- sharable non- sharable non- sharable non- sharable non- sharablenon- sharable non- sharable non- non- sharable
  • 32. Design “Shareable” and “non-sharable” •Non-shareable objects •(normal) Mutable objects (String, Array, …) •They are member of only one Guild •Using only 1 Guild, it compatible with Ruby 2 Guild 1 Guild 2 obj obj obj obj obj Can’t access (read/write) NG!!
  • 33. Design “Shareable” and “non-sharable” •Shareable objects •(1) Immutable objects (Numeric, Symbol, …) •(2) Class/Module objects •(3) Special mutable objects •(4) Isolated Proc
  • 34. Shareable objects (1) Immutable objects • Immutable objects can be shared with any guilds • Because no mutable operations for them • “Immutable” != “Frozen” • a1 = [1, 2, 3].freeze: a1 is Immutable • a2 = [1, Object.new, 3].freeze: a2 is not Immutable • Maybe we will introduce deep freeze feature • Numeric objects, symbols, true, false, nil are immutable (from Ruby 2.0, 2.1, 2.2) • Frozen string objects are immutable (if they don’t have instance variables)
  • 35. Shareable objects (2) Class/Module objects •All objects (including any sharable objects) point to own classes • Good: Sharing class/module objects makes program easier • Bad: They can point to other mutable objects with Constants, @@class_variable and @instance_variables class C Const = [1, 2, 3] # Const points a mutable array end # We will introduce special protocol for them
  • 36. Shareable objects (3) Special mutable objects • Introduce shared/concurrent data structure • Shared hash, array, … • Software transactional memory (from Clojure, …), … • Guild objects and so on • They require special process to force synchronization explicitly • They can’t mutate without synchronizations. • Easy to make correct concurrent programs • Compared with normal Array, Hash, … they should require special synchronization protocol to access
  • 37. Shareable objects (4) Isolated Proc •Normal Proc can point to mutable objects with outer local variable (free-variables) • a = []; Proc.new{p a}.call •Introduce Isolated Proc (made by Proc#isolate) which is prohibited to access outer variables a = []; Proc.new{p a}.isolate.call #=> RuntimeError (can’t access a) •(there are more details but skip)
  • 38. Shareable objects (4) Isolated Proc # Initial block for Guild is isolated proc g1 = Guild.new do expr1 # Make isolated block and invoke end g2 = Guild.new do p g1 #=> RuntimeError (can’t access “g1”) # because block is isolated end
  • 39. Inter-Guild communication API •Actor model, send/receive semantics •Destination addresses are represented by Guild itself like Erlang/Elixir processes •Sending shareable objects means sending only references to the objects (lightweight) •Two methods to send non-shareable objects • (1) COPY • (2) MOVE
  • 40. Sending objects between Guilds g1 = Guild.new do # create Isolated Proc n = Guild.receive r = fib(n) Guild.parent << r end g1 << 30 p Guild.receive #=> 1346269
  • 41. Sending shareable objects Guild1: g1 Guild2: g2 o2 o3 o1 g2 << o1 o1 =Guild.receive O2:Data O3:Data
  • 42. Sending non-shareable objects (1) Send by Copy Guild1 Guild2 o2 o3 o1 channel o2 o3 o1 COPY g2 << o1 o1 = Guild.receive O2:Data O3:Data O2:Data O3:Data
  • 43. Sending non-shareable objects (2) Send by Move Guild1 Guild2 o2 o3 o1 channel MOVE g2.move(o1) o1 =Guild.receive O2:Data O3:Data
  • 44. Sending non-shareable objects (2) Send by Move Guild1 Guild2 channel o2 o3 o1 MOVE g2.move(o1) o1 = Guild.receive O2:Data O3:Data - - - From Guild1 perspective, sent objects are invalidated
  • 45. Sending non-shareable objects (2) Send by Move •If we don’t access sent objects after sending them (and there are many such cases), we can send them faster •Examples •Huge string data •I/O operation (send request I/O to workers)
  • 46. Summary of object sharing/non-sharing • Shareable objects • Several types of shareable objects • We can share them between Guilds • They requires special synchronization protocol to mutate them • Non-sharable objects • Normal mutable objects (like String, Array, …) • Only one Guild can access such objects == membership • We can send them by COPY or MOVE • Mutable objects are NOT shared accidentally as Thread programming → Correct concurrent Prog.
  • 48. Guild context •Before Guild •VM -> *Threads -> *Fibers •After Guild •VM -> *Guilds -> *Threads -> *Fibers •Introduce rb_guild_t.
  • 49. Introduce synchronizations •Before Guild •Multiple threads cannot run simultaneously •After Guild •Run (native) threads in parallel •Need to introduce so many synchronizations •Introduce VM-wide locks for VM-wide resources •It is the multi-thread programming!!
  • 50. Garbage collection •Stop all Guilds (threads) at GC process G1:T1 G2:T2 G3:T3 GC process Pause request Restart request
  • 51. Future work and optimizations •Features •Prohibit sharing non-sharable objects •Introduce synchronizations to protect VM- wide resources (process-global) •Introduce “sharable” object protocols •Performance •Reduce synchronizations •Per Guild Garbage collection •Introduce new “C API” to reduce TLS access
  • 52. Future optimizations • Koichi Sasada, et.al. : An Implementation of Parallel Threads for YARV: Yet Another RubyVM (2007) • They introduced several optimization techniques to reduce synchronizations
  • 53. One more thing… Naming of “Guild”
  • 54. Why “Guild”? •Prefix should be different from “P” (Process), “T” (Therad) and “F” (Fiber). •Ownership can be explained with the word “Membership”. •All (normal) objects belong to one Guild. •Easy to explain “Move” semantics
  • 55. Any problem? •“Move” operation is not so popular operation (most of case “copy” is enough) •No other languages use this terminology •Naming is important •Just now “Guild” is a code name of this project
  • 56. Today’s talk •Background of Guild •Demonstrations •Guild specifications (ideas) •Guild implementations (w/ future plan) •Synchronizations •Performance optimizations
  • 57. Guild Prototype Koichi Sasada Cookpad Inc. <ko1@cookpad.com> Thank you for your attention
  • 58. Pros./Cons. Matrix Process Guild Thread Auto-Fiber Fiber Available Yes No Yes No Yes Switch on time Yes Yes Yes No No Switch on I/O Auto Auto Auto Auto No Next target Auto Auto Auto Auto Specify Parallel run Yes Yes No (on MRI) No No Shared data N/A (mostly) N/A Everything Everything Everything Comm. Hard Maybe Easy Easy Easy Easy Programming difficulty Hard Easy Difficult Easy Easy Debugging difficulty Easy? Maybe Easy Hard Maybe hard Easy

Notas del editor

  1. Today’s my talk is about the current prototype of Guild, a new concurrency abstraction for Ruby 3.
  2. 2 years ago, at RubyKaigi 2016, I talked this presentation, named “a proposal of new concurrency model for Ruby 3”.
  3. At this presentation, I’ve introduced new concurrent abstractuion, named “Guild”. This presentation only showed