Upgrade to Pro — share decks privately, control downloads, hide ads and more …

dRuby2016

 dRuby2016

RubyKaigi2016

seki at druby.org

September 08, 2016
Tweet

More Decks by seki at druby.org

Other Decks in Programming

Transcript

  1. more slide sponsors Ⰻ鿇׌׏ה䙼׏ג׋??![[BL@KQ E3VCZח״׷ⴓ侔٥8FCفؚٗٓىؚٝ ؔ٦ي爡F#PPL4UPSF  IUUQFTUPSFPINTIBDPKQUJUMFT1!IJTBTIJN ׫זׁתծTFLJ眍׾ֶ嚂׃׫ֻ׌ְׁկ䊛䃵歲꥔ך倯כծLBXBTBLJSCծ ZPLPIBNBSC׾ֶ鑐׃ֻ׌ְׁկ,ذٖؽך飑ⰅכծTFLJׁ׿穗歋ד׀湱锑ְ׋

    ׌ֽ׷ה׀⼿⸂׃תׅկ!UTVCPJ &NCFS4BQQPSP׾״׹׃ֶֻיְָ׃תׅխխխխխխխ IUUQTXXXGBDFCPPLDPNHSPVQTFNCFSTBQQPSP!USJDLOPUFT ְִ٦ְ✌✌؟ٝٓ؎ؤ⳿ꨡד3VCZ8PSME$POGFSFODF遤ֲֿ ׈٦!ZBODZB
  2. 2000 Perl/Ruby Conference (Kyoto) 2000೥ ࠷ॳͷߨԋ͸͜ͷձ৔ ײܹ͍ͯ͠Δ - Perl/Ruby Conference

    (Kyoto) - The first talk I gave was in year 2000 at this place. - I am impressed.
  3. BD8͘Β͍ͷ͜ͱ ੲͬΆ͍UNIXΛ࢖ͬͨ૊ΈࠐΈγεςϜ খ͞ͳσʔϞϯͷ૊Έ߹Θͤ fork, pipe, signal, SystemV IPC select()ͳ͔ͬͨ From

    the old days (BD8) - Embedded system using old-fashioned UNIX - Combination of tiny daemons - fork, pipe, signal, SystemV IPC - select() did not exist
  4. BD8͘Β͍ͷ͜ͱ ܭଌ૷ஔ܈Λ੍ޚ ૷ஔ͔ΒσʔλΛऔΔ/੍ޚ͢Δͨ͘͞Μ ͷσʔϞϯͱͦΕΛ·ͱΊΔσʔϞϯ ৘ใΛՄࢹԽ͢ΔΞϓϦέʔγϣϯ ϓϩηεΛ෼͚Δඞવੑ͕͋ͬͨ From the old days

    (BD8) - Controlling a group of measurement devices - Many daemons that extract and control data from devices, and a daemon that controls them in turn - Need to divide between processes
  5. CGIͷ୯७ͳੈք (BD5) ԶϚΠΫϩαʔϏε࣌୅ request/response, stateless ͍ΖΜͳγεςϜΛCGIͰॻ͖௚ͨ͠ Perl, AppleScript A simple

    world of CGI - My Microservices era - request/response, stateless - Rewrote various systems using CGI
  6. ͳΜ͔ؾʹೖΒͳ͍ ͍ͭ΋RubyͱWebͷੈքͷ຋༁࡞ۀͯͨ͠ HTTPʹ͓͚ΔΦϒδΣΫτͷަ׵ͷ੍໿ Server - Clientͷݻఆతͳؔ܎ ϝιουͱ͍͏ΑΓؔ਺ίʔϧ Not so cool

    because... - Routine work translating between Ruby and the Web world - HTTP's restriction on how to exchange objects - Fixed relation between Server and Client - More like a functional call rather than a method
  7. RubyͰ࿩͍ͨ͠ Ruby ObjectͳΜ͔ͩΒɺRubyΆ͘࿩͍ͨ͠ Want to speak in Ruby - Given

    that they are Ruby objects, it is tempting to speak in Ruby-ish way
  8. ϩϚϯ RMIΛࢥ͍͍͔ͭͯΒͷࢥߟ࣮ݧ ෼ࢄΦϒδΣΫτ͕͋Δ͔ͷΑ͏ͳԋग़ͱ͸ OOPLͱΦϒδΣΫτΈ͍ͨͳ... Romance - Thought-experiment since the idea

    of RMI - How to make it look like there are distributed objects - Something like OOP-language and objects
  9. ͭ·Γ ؆୯௨৴ϥΠϒϥϦͰ͸ͳ͍ ௨৴Λ؆୯ʹ͢Δ͜ͱ͸ૂ͍ͬͯͳ͍ طଘͷRPCϓϩτίϧͷϥούʔͰ͸ͳ͍ ΋ͬͱ৘ॹతͳ΋ͷ In other words, Not a

    library that makes communication simple - It doesn't aim to make communication simple - It is not a wrapper of an already-existing RPC protocol - Something more poetic
  10. ͠͹Β͓͘଴͍ͪͩ͘͞ ✓  ✓ E3VCZલ࢙Λઆ໌ͨ͠ ✓ ͔ͭ͗ΒE3VCZΛ঺հ please wait for

    a moment - Done: Pre-history of dRuby - Now, we are on to demonstration
  11. Demo1 Starting up dRubyΛ࢖͏ͨΊͷ४උ ؆୯ͳRMI Key Value Store Demo1 Starting

    Up - Preparing to use dRuby - A simple RMI - Key-Value Store
  12. ΍ͬͨ͜ͱ DRb.start_serviceͰ͸͡Ίͨ URIͰproxyΛͭͬͨ͘ ͋ͱ͸ݺͿ͚ͩ What we did - Started with

    DRb.start_service - Created a proxy with a URI - Then, we just called it
  13. ͼͬ͘Γͯ͠ʂ dRubyͷ४උ͸start_service͚ͩ ΠϯλʔϑΣΠεఆٛෆཁ ੲ͸IDLఆٛ͢ΔγεςϜ͕ଟ͔ͬͨ Surprised, aren't you? - Only need

    to do start_service to prepare for dRuby - No need to declare interfaces - In the old days, many systems defined IDL
  14. Demo2 Ͳ͕ͬͪαʔόʁ ҉໧తʹObjectΛެ։͠·͢ jushi-matzͷ $stdout Λoso-matz͕ݺͼ·͢ server / clientͷཱ৔͕ೖΕସΘΓ·͢ Demo

    2 Which one is the server? - Implicitly publicize an object - oso-matz will call $stdout on jushi-matz - Server/client roles will switch
  15. ΍ͬͨ͜ͱ jushi-matzͷ$stdoutΛoso-matzʹڭ͑ͨ oso-matz͸ͦΕʹputsͨ͠ jushi-matzͷ୺຤ʹҹࣈ͞Εͨ What we did - Taught oso-matz

    about $stdout on jushi-matz - oso-matz did puts on it - Printed on a terminal on jushi-matz
  16. ͳʹ͕͓͖ͨʁ ҉໧తͳެ։ $stdoutΛࣗಈతʹproxyʹऔΓସ͑ͨ Marshal.dumpͷՄ൱͕৚݅ dumpՄೳ ➡ ෳ੡ dumpෆՄೳ ➡ proxy

    What happened? - Implicit publicization - Replaced $stdout with proxy automatically - Depends on the availability of Marshal.dump - dumpable => duplication - not dumpable => proxy
  17. Marshal.dump 'outlet'͸dumpͰ͖Δ ෳ੡ $stdout͸dumpͰ͖ͳ͍ proxy Marshal.dump - 'outlet' is dumpable

    - duplicating - $stdout cannot be dumped - proxy kvs['outlet'] = $stdout # kvs.[]=('outlet', $stdout)
  18. ͜͜Ͱͷԋग़ RubyͳΒҾ਺΍໭Γ஋͕ෳ੡͞Εͳ͍ dRubyͰ΋͢΂ͯproxyʹ͢Δ΂͖ʁ ౰વͦ͏ࢥ͏ true, false, nil, ਺... ͜Ε΋proxyʹ͢Δ΂͖ʁ ͏ʔΜ

    Some thinking - In Ruby, arguments and return values are not duplicated - Should dRuby proxy everything? - Yes, of course - true, false, nil, numbers, ... should it also proxy them? - Mmm
  19. ruby-list:15406 1st sampleɹ require 'drb.rb' class DRbEx def initialize @hello

    = 'hello' end def hello @hello end def sample(a, b, c) a.to_i + b.to_i + c.to_i end end if __FILE__ == $0 DRb.start_service('druby://localhost:7640', DRbEx.new) DRb.thread.join end require 'drb.rb' class DRbEx2 def initialize(n) @n = n end def _dump raise TypeError, 'can\'t dump' end def to_i @n.to_i end end if __FILE__ == $0 DRb.start_service('druby://localhost:7950') ro = DRbObject.new(nil, 'druby://localhost: 7640') p ro.hello p ro.sample(DRbEx2.new(1), 2, 3) p ro.sample(1, ro.sample(DRbEx2.new(1), 2, 3), DRbEx2.new(3)) end
  20. OOPͬΆ͞ ΠςϨʔλ΋ಉ͡࢓૊ΈͰಈ͘Α block ro.each do |it| foo(it) end How to

    make it look OOP-ish - Iterators also work the same way - block
  21. Demo3 ෼ࢄQueue queue = Queue.new DRb.front['queue'] = queue queue =

    kvs['queue'] queue.push(1.0) queue.pop #=> 1.0 queue.pop #(blocked) queue.push(2.0) queue.pop #=> 2.0 (cont.) Demo 3 Distributed Queue
  22. Demo3 ෼ࢄQueue queue = Queue.new DRb.front['queue'] = queue queue.pop queue.pop

    queue = kvs['queue'] queue.push(1.0) queue.push(2.0)
  23. ͳʹ͕͓͖ͨʁ HashαʔόΛհͯ͠QueueΛखʹೖΕͨ Name Serivce QueueΛ࢖ͬͯೋਓ͕଴ͪ߹Θͤͯͨ͠ What happened? - A queue

    was obtained via a hash server - Two people were waiting for each other using a queue
  24. ͜͜Ͱͷԋग़ Queue, Mutex, Monitor ... ThreadಉظϝΧχζϜ΋ͦͷ··࢖͑Δ Some thoughts here -

    Queue, Mutex, Monitor, ... - We can use the Thread-synchronization mechanism as is
  25. BD8͘Β͍ͷ͜ͱ ܭଌ૷ஔ܈Λ੍ޚ ૷ஔ͔ΒσʔλΛऔΔ/੍ޚ͢Δͨ͘͞Μ ͷσʔϞϯͱͦΕΛ·ͱΊΔσʔϞϯ ৘ใΛՄࢹԽ͢ΔΞϓϦέʔγϣϯ ϓϩηεΛ෼͚Δඞવੑ͕͋ͬͨ From the old days

    (BD8) - Controlling a group of measurement devices - Many daemons that extract and control data from devices, and a daemon that controls them in turn - Need to divide between processes
  26. Prototyping Twitter ॳظ͸dRuby/RindaͩͬͨΒ͍͠ ͍·͸࢖ͬͯͳ͍ ࣗ෼ͷαʔϏε΋dRubyͰ͸͡Ίͯ࠷ޙʹ͸ ࢖Θͳ͘ͳΔ͜ͱ͕͋Δ ར༻͞Εͯޮ཰͋͛Δඞཁ͕Ͱ͔ͯΒ - It looks

    like they had used dRuby/Rinda in the beginning. - But not now. - Even I sometimes start some services using dRuby, ending up not using it. - It happened since my services gained popularity, and I needed to make them more efficient.
  27. ঺հͷ·ͱΊ جຊతͳdRubyͷ࢖͍ํΛ঺հͨ͠ ४උ RMI Queue ෼ࢄΦϒδΣΫτΆ͔ͬͨʁ Interim summary - Introduced

    basic uses of dRuby - Preparation - RMI - Queue - Looked like distributed objects?
  28. ͠͹Β͓͘଴͍ͪͩ͘͞ ✓  ✓ E3VCZͷσϞΛͨ͠ ✓ ෼ࢄΦϒδΣΫτΆ͍ʁ ✓ ଓ͖͸ॻ੶Ͱʂ ✓

    ࣍͸ݴ͍༁ please wait for a moment - Did demo on dRuby - Looks like distributed objects? - Please buy the book for more information! - Next: the excuses
  29. ͜Ε͔Β ௚͍ͨ͠ͱ͜Ζ ॳظͷ࣮૷ʹ໭͍ͨ͠ͱ͜Ζ͕͍͔ͭ͘ ςετ ܒ໤͢Δ From now on - Want

    to fix: - Several points to revert to the initial implementation - Tests - Enlighten people
  30. ηΩϡϦςΟͬΆ͍ͷফ͍ͨ͠ ACL, insecure_method ... dRuby͸RMIͰϝιουݺͼग़͠ͷ֦ு ϝιουݺͼग़͠ͳͷͰ݀ͩΒ͚Ͱྑ͍ ةͳ͍΋ͷ͸ةͳ͘ݟ͑Δ΂͖ Want to hide

    security-ish things - ACL, insecure_method, ... - dRuby extends methods with RMI - It is okay to have loop holes since it is a method call - Dangerous things should look dangerous
  31. UnitTest ڈ೥akr͞Μʹݴ͍༁ͨ͠ צҧ͍ͯͨ͠ Ұൠతʹ͸APIͷϝιου୯Ґʹॻ͘΋ͷ ͩͬͨΒ͍͠ ςετέʔεΛετʔϦʔϨϕϧͰॻ͘΂ ͖ͩͱࢥͬͯͨ - I made

    an excuse to akr last year. - I mistook it. - Turned out that in general, they should be written per API method. - I had thought they should be written at story levels.
  32. ͠͹Β͓͘଴͍ͪͩ͘͞ ✓  ✓ ඪ४ఴ෇Λଓ͚ͯ΋Β͏ Α͏ʹΞϐʔϧ͢Δ ✓ ΋͏ऴΘΓ ✓ εϥΠυӳ༁νʔϜʹ͓

    ྱΛ͍͏ please wait for a moment - Appeal to have them continuously attached by default - Almost the end
  33. History of dRuby (and me) 1999-3 ERB 1999-9 DRb 2003

    committer 2010 pokemon-master 2000 Rinda 1998 started ruby 2006 - 2016 Ruby Kaigi
  34. ·ͱΊ 2000೥ͱಉ͡৔ॴͰdRubyͷ࿩Λͨ͠ dRubyͷੜཱ͍ͪ dRubyͷ঺հ ͜Ε͔Β 21ੈل΋͓΋͠Ζ͕ͬͯ΋Β͑ΔͰ͠ΐ͏͔ Conclusion - I gave

    a talk on dRuby at the same place I did in year 2000. - Birth of dRuby - Introduction of dRuby - Future - Will people still have fun with dRuby in the 21st century?