dRuby2016

 dRuby2016

RubyKaigi2016

40f4d1f2e77078955bd01e9fb4a503ba?s=128

seki at druby.org

September 08, 2016
Tweet

Transcript

  1. ͠͹Β͓͘଴͍ͪͩ͘͞ ✓ ͝ཡͷεϙϯαʔͷఏڙ ʹΑΓ͓ૹΓ͠·͢

  2. slide sponsors 044(BUFח⿫⸇׃״ֲׅ ջأذ؍٦ـؤռ䋆涪㡰⚥!NB ؔزشה3VCZדֶ䖉׍׃גְתׅկ!NJXB ؔزشה3VCZדֶ䖉׍׃גְתׅկ!NBNF 歍׃鴥׫כUPSVCZEPPSLFFQFSKQַ׵!WFTUJHF@ ؔزشה3VCZծ➙䎃כְְ괏ス  ך傈!1613-

    虠加歕ջ梾楤㼔Ꟍ枾䒍莔ռ׀勻䏄ֶ䖉׍׃גֶ׶תׅ!PHJKVO
  3. more slide sponsors Ⰻ鿇׌׏ה䙼׏ג׋??![[BL@KQ E3VCZח״׷ⴓ侔٥8FCفؚٗٓىؚٝ ؔ٦ي爡F#PPL4UPSF  IUUQFTUPSFPINTIBDPKQUJUMFT1!IJTBTIJN ׫זׁתծTFLJ眍׾ֶ嚂׃׫ֻ׌ְׁկ䊛䃵歲꥔ך倯כծLBXBTBLJSCծ ZPLPIBNBSC׾ֶ鑐׃ֻ׌ְׁկ,ذٖؽך飑ⰅכծTFLJׁ׿穗歋ד׀湱锑ְ׋

    ׌ֽ׷ה׀⼿⸂׃תׅկ!UTVCPJ &NCFS4BQQPSP׾״׹׃ֶֻיְָ׃תׅխխխխխխխ IUUQTXXXGBDFCPPLDPNHSPVQTFNCFSTBQQPSP!USJDLOPUFT ְִ٦ְ✌✌؟ٝٓ؎ؤ⳿ꨡד3VCZ8PSME$POGFSFODF遤ֲֿ ׈٦!ZBODZB
  4. dRuby in the last century seki@ruby-lang.org

  5. @m_seki Rubyίϛολ ERB, dRuby, Rindaͷஶऀ લ࠲͕Matz - Ruby committer -

    Author of ERB, dRuby, Rinda
  6. Agenda dRubyͷੜཱ͍ͪ dRubyͷ঺հ ͜Ε͔Β - The birth of dRuby -

    Introduction of dRuby - Future
  7. 1999 [ruby-list:15406] 1st dRuby

  8. 1st dRuby on T-shirts TV[VSJKQN@TFLJ

  9. 2005 - ·ͩॳ࡮Γങ͑·͢ dRuby ʹΑΔ ؔকढ़ஶ ෼ࢄ ɾ Web ϓϩάϥϛϯά

    First printing from 2005 (Still available)
  10. ΋ͬͱΘ͔Γ΍͘͢΄Ίͯʂ Praise it more directly, please!

  11. 2012 (-2014 ઈ൛) Publication from 2012 (Become out of print

    in 2014)
  12. 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.
  13. 2000-2016 ࠓ೔͸ಉ͡ձ৔Ͱ·ͨdRubyͷ࿩Λ͍ͨ͠ I would like to give a talk about

    dRuby again in the same place today.
  14. ͠͹Β͓͘଴͍ͪͩ͘͞ ✓  ✓ 4MJEFTQPOTPST ✓ "HFOEB please wait for

    a moment
  15. OOPARTS I was just reminded of dRuby's OOPARTS-ness

  16. OOPARTS

  17. dRuby͸Ͳ͔͜Β͖ͨͷ dRubyҎલ (Before dRuby: BD) Where did dRuby come from?

    - Before dRuby (BD)
  18. 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
  19. 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
  20. CGIͷ୯७ͳੈք (BD5) ԶϚΠΫϩαʔϏε࣌୅ request/response, stateless ͍ΖΜͳγεςϜΛCGIͰॻ͖௚ͨ͠ Perl, AppleScript A simple

    world of CGI - My Microservices era - request/response, stateless - Rewrote various systems using CGI
  21. Ruby & shttpsrv (BD1) 1998-9 Ruby & shttpsrvʹग़ձ͏ 1998-9, Met

    Ruby & shttpsrv
  22. shttpsrv RubyͰॻ͔ΕͨHTTPαʔό WEBrickΑΓͣͬͱલ খ͍͞ - Web server written in Ruby

    - Before WEBrick - Small and extensible
  23. HTTPΛϓϩηεʹຒΊࠐΉ খ͞ͳΞϓϦʹWebαʔόΛຒΊࠐΉ ΞϓϦؒΛHTTPͰͭͳ͍Ͱָ͠ΜͰͨ Embedding HTTP into processes - Embedding web

    server into small apps - Had fun Application communication via HTTP
  24. ͳΜ͔ؾʹೖΒͳ͍ ͍ͭ΋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
  25. RubyͰ࿩͍ͨ͠ Ruby ObjectͳΜ͔ͩΒɺRubyΆ͘࿩͍ͨ͠ Want to speak in Ruby - Given

    that they are Ruby objects, it is tempting to speak in Ruby-ish way
  26. RubyʹؼΖ RubyͷΑ͏ʹৼΔ෣͏෼ࢄΦϒδΣΫτ RPCͰͳ͘RMI Rubyͷϝιουݺͼग़͠ΛsocketͰ֦ு Return to Ruby - Distributed objects

    acting like Ruby - No RPC, but RMI - Extending Ruby's method invocation with sockets
  27. ϩϚϯ 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
  28. ͭ·Γ ؆୯௨৴ϥΠϒϥϦͰ͸ͳ͍ ௨৴Λ؆୯ʹ͢Δ͜ͱ͸ૂ͍ͬͯͳ͍ طଘͷ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
  29. ͠͹Β͓͘଴͍ͪͩ͘͞ ✓  ✓ E3VCZલ࢙Λઆ໌ͨ͠ ✓ ͔ͭ͗ΒE3VCZΛ঺հ please wait for

    a moment - Done: Pre-history of dRuby - Now, we are on to demonstration
  30. dRubyͯͳʹʁ ෼ࢄΦϒδΣΫτγεςϜ ϓϩηεӽ͠ʹϝιου͕ݺ΂Δ ϓϩηεؒͰΦϒδΣΫτ͕ૹΕΔ What is dRuby? - Distributed Object

    System - Can Invoke methods in different process - Can send objects between process
  31. ਐΊํ irbͷσϞͰجຊతͳಈ࡞Λઆ໌ ΈΜͳTerminalΛ2ͭ༻ҙͯ͠ʂ unixͷਓ΋windowsͷਓ΋! Outline - Basis using irb demo

    - Please prepare two teminals!
  32. dRubyͷ͓͔͛ͰWindowsͰ ΋࣮ݧͰ͖ΔΑʂ Thanks to the dRuby book, gets on Windows

    no longer blocks other threads.
  33. Demo1 Starting up dRubyΛ࢖͏ͨΊͷ४උ ؆୯ͳRMI Key Value Store Demo1 Starting

    Up - Preparing to use dRuby - A simple RMI - Key-Value Store
  34. Hashαʔό Hash server (oso-matz) client (jushi-matz) Hash server kvs['greeting'] =

    'Hello, World.'
  35. start_service start_serviceͰ͸͡Ί·͢ URIͱΦϒδΣΫτΛࢦఆͯ͠ެ։ ໌ࣔతͳެ։ DRb.start_service('druby://localhost:54321', {}) DRb.uri #=> 'druby://localhost:54321' DRb.front

    #=> {} start_service - Begin with start_service - Publicize URI and an object - Explicit publicizing
  36. Proxy URI͔ΒProxyΛੜ੒ kvs = DRbObject.new_with_uri('druby://localhost:54321') Generates a proxy from a

    URI
  37. ͨͩݺͿ͚ͩ ผϓϩηεͷϝιουݺͼग़͠ Hash#[]=(k, v) kvs['greeting'] = "Hello, World." Just call

    the method - Calling method in a different process
  38. Hashαʔό DRb.start_service('druby://localhost:54321', {}) DRb.front #=> {} DRb.start_service kvs = DRbObject.new_with_uri('druby://localhost:54321')

    kvs['greeting'] = "Hello, World." DRb.front #=> {"greeting"=>"Hello, World."}
  39. Demo1 DRb.start_service('druby://localhost:54321', {}) DRb.front DRb.start_service kvs = DRbObject.new_with_uri('druby://localhost:54321') kvs['greeting'] =

    "Hello, World."
  40. ΍ͬͨ͜ͱ DRb.start_serviceͰ͸͡Ίͨ URIͰproxyΛͭͬͨ͘ ͋ͱ͸ݺͿ͚ͩ What we did - Started with

    DRb.start_service - Created a proxy with a URI - Then, we just called it
  41. ͼͬ͘Γͯ͠ʂ 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
  42. 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
  43. ΦϒδΣΫτΛૹΔ ϝιουͷҾ਺Ͱ$stdoutΛૹΔ ҉໧తʹެ։ kvs['outlet'] = $stdout Sending objects - Send

    $stdout as method arguments - Publicized implicitly
  44. ٯస ϦϞʔτͷ$stdoutͷϝιουΛݺͿ ϗϯϞϊΛ͍࣋ͬͯΔํ͕αʔόʔ ϝιουΛݺͿํ͕ΫϥΠΞϯτ DRb.front['outlet'].class #=> DRb::DRbObject DRb.front['outlet'].puts('Hello, Again.') Reversal

    - Call $stdout methods on the remote - The one that has the read one is the server - The one that calls the method is the client
  45. Demo2 Ͳ͕ͬͪαʔόʁ DRb.front['outlet'].class #=> DRb::DRbObject DRb.front['outlet'].puts('Hello, Again.') kvs['outlet'] = $stdout

    kvs['outlet'] #=> $stdout Demo2 Which one is the server?
  46. Demo2 Ͳ͕ͬͪαʔόʁ kvs['outlet'] = $stdout kvs['outlet'] #=> $stdout DRb.front['outlet'].class #=>

    DRb::DRbObject DRb.front['outlet'].puts('Hello, Again.')
  47. ΍ͬͨ͜ͱ 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
  48. ͳʹ͕͓͖ͨʁ ҉໧తͳެ։ $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
  49. Marshal.dump 'outlet'͸dumpͰ͖Δ ෳ੡ $stdout͸dumpͰ͖ͳ͍ proxy Marshal.dump - 'outlet' is dumpable

    - duplicating - $stdout cannot be dumped - proxy kvs['outlet'] = $stdout # kvs.[]=('outlet', $stdout)
  50. ͜͜Ͱͷԋग़ 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
  51. ࣗવʹݟ͑Δଥڠ΋ඞཁͩ ӬԕʹProxyͰ͸஋͕खʹೖΒͳ͍ Ͳ͔͜ʹڥք͕ඞཁͩ Marshal.dumpʹͨ͠ ͳΜ͔͍͍ײ͡ʹಈ͘ Natural compromise - Using proxy,

    we will never get the value - We need a border somewhere - Made it using Marshal.dump - Works good
  52. OOPͬΆ͞ ΦϒδΣΫτ͕૬ޓʹݺͼ߹͑Δ͜ͱ How to make it look OOP-ish - Let

    objects call each other
  53. 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
  54. OOPͬΆ͞ ΠςϨʔλ΋ಉ͡࢓૊ΈͰಈ͘Α block ro.each do |it| foo(it) end How to

    make it look OOP-ish - Iterators also work the same way - block
  55. Demo3 ෼ࢄQueue QueueΛ࢖ͬͯ଴ͪ߹Θͤ͠·͢ ϓϩηεؒͰpush/pop Demo 3 Distributed Queue - Wait

    using queue - push/pop between processes
  56. ଴ͪ߹Θͤ QueueΛ࢖ͬͯ଴ͪ߹Θͤ jushi-matz͔Βͷσʔλͷ౸ணΛ଴ͪ·͢ Waiting - Waiting using queue - Wait

    for the data from jushi-matz to arrive
  57. ४උ QueueΛ࡞ͬͯHashʹೖΕ·͢ popͯ͠଴ͪ·͢ queue = Queue.new DRb.front['queue'] = queue queue.pop

    Preparation - Create a queue, and put it in a Hash - Pop, and wait
  58. σʔλΛૹΔ Hashαʔό͔ΒQueueΛखʹೖΕΔ pushͰσʔλΛૹΓ·͢ queue = kvs['queue'] queue.push(1.0) Sending data -

    Obtain a queue from a hash server - send a data
  59. 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
  60. Demo3 ෼ࢄQueue queue = Queue.new DRb.front['queue'] = queue queue.pop queue.pop

    queue = kvs['queue'] queue.push(1.0) queue.push(2.0)
  61. ͳʹ͕͓͖ͨʁ 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
  62. ͜͜Ͱͷԋग़ Queue, Mutex, Monitor ... ThreadಉظϝΧχζϜ΋ͦͷ··࢖͑Δ Some thoughts here -

    Queue, Mutex, Monitor, ... - We can use the Thread-synchronization mechanism as is
  63. dRuby͕޲͘ঢ়گ ण໋ͷҧ͏৘ใΛѻ͏ ଴ͪ߹ΘͤΛσβΠϯ͢Δ͜ͱ͕ଟ͍ Scenarios suited for dRuby - Handling information

    of different life span - A system of waiting
  64. 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
  65. Twitterͷ৔߹ In case of Twitter

  66. 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.
  67. ঺հͷ·ͱΊ جຊతͳdRubyͷ࢖͍ํΛ঺հͨ͠ ४උ RMI Queue ෼ࢄΦϒδΣΫτΆ͔ͬͨʁ Interim summary - Introduced

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

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

    to fix: - Several points to revert to the initial implementation - Tests - Enlighten people
  70. ηΩϡϦςΟͬΆ͍ͷফ͍ͨ͠ 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
  71. 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.
  72. ܒ໤͢Δ ·͓ͣ΋͠Ζ͕ͬͯ΋Β͏ ฒߦॲཧͷצॴ(ʁ)ʹؾ͍ͮͯ΋Β͏ Enlightening people - Have people enjoy it.

    - Let them realize the tips of parallel processing
  73. ͠͹Β͓͘଴͍ͪͩ͘͞ ✓  ✓ ඪ४ఴ෇Λଓ͚ͯ΋Β͏ Α͏ʹΞϐʔϧ͢Δ ✓ ΋͏ऴΘΓ ✓ εϥΠυӳ༁νʔϜʹ͓

    ྱΛ͍͏ please wait for a moment - Appeal to have them continuously attached by default - Almost the end
  74. 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
  75. ·ͱΊ 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?