These slides show a high level architecture of Ruby MagLev as well as a small example to illustrate how easy it is to have transparent object persistence in Ruby.
8. MagLev Concepts
• Root Object
• Persistency by Reachability
• (transitive closure)
• Repository (Stone)
• Virtual Machines (Gems)
• local vs remote gems
lautus MiniRubyConf
9. MagLev Concepts
• Root Object
• Persistency by Reachability
• (transitive closure)
• Repository (Stone)
• Virtual Machines (Gems)
• local vs remote gems
• Garbage Collector
lautus MiniRubyConf
10. Ruby
VM
Ruby
VM Shared
Page Repository
Cache
Ruby
VM
Ruby
VM
11.
12. TwitterClone
class Person def remove_follower(person)
@followers.delete(person)
attr_accessor :username, :followers end
def initialize(username) def to_s
@username = username result = "@#{@username} -->
@followers = Array.new [#{@followers.size}]"
end @followers.each {|f| result = result +
" #{f.username}" }
def add_follower(person) result
@followers << person end
end end
lautus MiniRubyConf
13. TwitterClone
Maglev.persistent do
require 'person'
end
Maglev::PERSISTENT_ROOT[:persons] = Array.new
Maglev.commit_transaction
lautus MiniRubyConf
40. TwitterClone2 def add_follower(person)
class Person @followers << person
attr_accessor :username, :email, :followers, :following end
def initialize(username) def remove_follower(person)
@username = username @followers.delete(person)
@email = username + "@mail.com" end
@followers = Array.new
@following = Array.new def to_s
end result = "@#{@username} --> [#{@following.size} :
#{@followers.size}]"
def follows(person) result = result + " following: {"
@following << person @following.each {|f| result = result + " #{f.username}"}
person.add_follower(self) result = result + " }"
end result = result + " followed by: {"
@followers.each {|f| result = result + " #{f.username}"}
def unfollows(person) result = result + " }"
@following.delete(person) result
person.remove_follower(self) end
end end
lautus MiniRubyConf
41. TwitterClone2
Maglev.persistent do
require 'person'
end
Maglev::PERSISTENT_ROOT[:persons] = Array.new
Maglev.commit_transaction
lautus MiniRubyConf
45. MagLev
• Concurrent access to objects in distributed VM’s
lautus MiniRubyConf
46. MagLev
• Concurrent access to objects in distributed VM’s
• Rabbit in hat trick
lautus MiniRubyConf
47. MagLev
• Concurrent access to objects in distributed VM’s
• Rabbit in hat trick
• Proc’s can be persisted
lautus MiniRubyConf
48. MagLev
• Concurrent access to objects in distributed VM’s
• Rabbit in hat trick
• Proc’s can be persisted
• references enclosing environment’s variables
lautus MiniRubyConf