Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Ruby MagLev

1,520 views

Published on

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.

Published in: Technology
  • Login to see the comments

  • Be the first to like this

Introduction to Ruby MagLev

  1. 1. An introduction to Maglev Rudi Engelbrecht Ruby Conf - 17 June 2011lautus
  2. 2. MagLev Conceptslautus MiniRubyConf
  3. 3. MagLev Concepts • Root Objectlautus MiniRubyConf
  4. 4. MagLev Concepts • Root Object • Persistency by Reachabilitylautus MiniRubyConf
  5. 5. MagLev Concepts • Root Object • Persistency by Reachability • (transitive closure)lautus MiniRubyConf
  6. 6. MagLev Concepts • Root Object • Persistency by Reachability • (transitive closure) • Repository (Stone)lautus MiniRubyConf
  7. 7. MagLev Concepts • Root Object • Persistency by Reachability • (transitive closure) • Repository (Stone) • Virtual Machines (Gems)lautus MiniRubyConf
  8. 8. MagLev Concepts • Root Object • Persistency by Reachability • (transitive closure) • Repository (Stone) • Virtual Machines (Gems) • local vs remote gemslautus MiniRubyConf
  9. 9. MagLev Concepts • Root Object • Persistency by Reachability • (transitive closure) • Repository (Stone) • Virtual Machines (Gems) • local vs remote gems • Garbage Collectorlautus MiniRubyConf
  10. 10. Ruby VM Ruby VM Shared Page Repository CacheRuby VMRuby VM
  11. 11. 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 endlautus MiniRubyConf
  12. 12. TwitterClone Maglev.persistent do require person end Maglev::PERSISTENT_ROOT[:persons] = Array.new Maglev.commit_transactionlautus MiniRubyConf
  13. 13. person.rb
  14. 14. person.rbperson.rb
  15. 15. :persons Array person.rbperson.rb
  16. 16. :persons Array :persons Array person.rb person.rbperson.rb
  17. 17. TwitterClone require person dhh = Person.new("dhh") persons = obie = Person.new("obie") Maglev::PERSISTENT_ROOT[:persons] unclebob = Person.new("unclebob") noob1 = Person.new("noob1") persons << dhh noob2 = Person.new("noob2") persons << obie persons << unclebob dhh.add_follower(obie) dhh.add_follower(unclebob) Maglev.commit_transaction obie.add_follower(unclebob) unclebob.add_follower(noob1) unclebob.add_follower(noob2)lautus MiniRubyConf
  18. 18. :persons Array :persons Array
  19. 19. :persons Arraydhh :persons Array
  20. 20. :persons Arraydhh obie :persons Array
  21. 21. :persons Arraydhh obie :persons unclebob Array
  22. 22. :persons Arraydhh obie :persons unclebob Array
  23. 23. :persons Arraydhh obie :persons unclebob Array
  24. 24. :persons Arraydhh obie :persons unclebob Array
  25. 25. :persons Arraydhh obie :persons unclebob Array noob1
  26. 26. :persons Arraydhh obie :persons unclebob Array noob1 noob2
  27. 27. :persons Arraydhh obie :persons unclebob Array noob1 dhh obie noob2 unclebob noob1 noob2
  28. 28. TwitterClone persons = Maglev::PERSISTENT_ROOT[:persons] persons.each {|p| puts p}lautus MiniRubyConf
  29. 29. TwitterClonelautus MiniRubyConf
  30. 30. TwitterClone • Multiple VM’slautus MiniRubyConf
  31. 31. TwitterClone • Multiple VM’s • Concurrent access - MVCClautus MiniRubyConf
  32. 32. TwitterClone • Multiple VM’s • Concurrent access - MVCC • First commit winslautus MiniRubyConf
  33. 33. 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 endlautus MiniRubyConf
  34. 34. TwitterClone2 Maglev.persistent do require person end Maglev::PERSISTENT_ROOT[:persons] = Array.new Maglev.commit_transactionlautus MiniRubyConf
  35. 35. TwitterClone2 require person dhh = Person.new("dhh") obie = Person.new("obie") unclebob = Person.new("unclebob") noob1 = Person.new("noob1") noob2 = Person.new("noob2") obie.follows(dhh) unclebob.follows(dhh) unclebob.follows(obie) noob1.follows(unclebob) noob2.follows(unclebob) persons = Maglev::PERSISTENT_ROOT[:persons] persons << dhh persons << obie persons << uncleboblautus MiniRubyConf
  36. 36. TwitterClone2 persons = Maglev::PERSISTENT_ROOT[:persons] persons.each {|p| puts p}lautus MiniRubyConf
  37. 37. MagLevlautus MiniRubyConf
  38. 38. MagLev • Concurrent access to objects in distributed VM’slautus MiniRubyConf
  39. 39. MagLev • Concurrent access to objects in distributed VM’s • Rabbit in hat tricklautus MiniRubyConf
  40. 40. MagLev • Concurrent access to objects in distributed VM’s • Rabbit in hat trick • Proc’s can be persistedlautus MiniRubyConf
  41. 41. MagLev • Concurrent access to objects in distributed VM’s • Rabbit in hat trick • Proc’s can be persisted • references enclosing environment’s variableslautus MiniRubyConf
  42. 42. Dinnerlautus MiniRubyConf
  43. 43. Dinner • Enjoy!lautus MiniRubyConf

×