Andrew Grimm University of New South Wales ニューサウスウェールズ大学  (UNSW) RubyKaigi 2011 日本 Ruby 会議  2011 Finding Black Holes in Ruby with the Small Eigen Collider 小型特異衝突型加速器で Ruby 内のブラックホールの特異点を見つける方法
tl;dr Too Long, Didn't Read( 長過ぎてよんでられない ) Creates random code. Metaprogramming magic! ランダムなコードを作成します。メタプログラミングマジック!
Why? なんで? Why did I create the Small Eigen Collider? なぜ私は小型特異衝突型加速器を作成した ?
Background 背景 Bioinformatician at UNSW UNSW  のバイオインフォマティクス Looking at mutations in HIV HIV 感染の変異を見て
Looking at mutations 私は突然変異で探しています Start with viruses with identical DNA sequence 同一の DNA 配列を持つウイルスで始まります Allow to reproduce for one generation in laboratory 実験室内の 1 つの世代のために再現することができます Determine DNA sequence of new viruses 新しいウイルスの DNA 配列を決定する Differences are mutations 違いは突然変異です
Big data ビッグデータ Looking at approximately 500,000 sequences 約 50 万シーケンスを見て Approx. 150,000,000 DNA letters (A, C, G, T) 約。  1.5 億 DNA の文字( A 、 C 、 G 、 T ) For comparison, human genome is 3,000,000,000 letters 比較のために、ヒトゲノムは 30 億文字です
Problem Ruby is too slow XKCD 303 問題 Ruby は遅すぎる
How slow is my application? 私のアプリのスピード Currently using YARV Ruby 1.9.1 My application looks at 500,000 sequences 50万件のルックアップ An analysis takes 20 minutes 解析には20分かかる
That's after some optimizing! ちなみにこれはチューニングの 後の数字です
Other Rubies might be faster ほかの Ruby 実装はもっと速いかも
JRuby Faster at some tasks Real multithreading (no GIL) 特定の処理は高速で真のマルチスレッド
Rubinius Faster at some tasks Real multithreading Real Soon Now 特定の処理は高速で真のマルチスレッドも近日リリース
Ruby Enterprise Edition Mainly better at garbage collection GC が良い。 More relevant to Rails developers than me Rails 開発者向き
How do I know it'll give the correct results? どのように私はそれが正しい結果を与えているか知ることができる? Should I switch to a faster Ruby? もっと早い Ruby 実装に乗り換えるべき?
What kind of errors worry me? どういうエラーが心配? Large, obvious bugs that cause an exception are fine エラーを生じる明らかなバグはあまり心配なし Small, subtle bugs that give an incorrect result are bad 些細でまちがった結果を生じるバグがやばめ
Other implementations are wrong 他の実装が間違っている Ran my project against Rubinius – 1 unit test failed Rubinius で自分のプロジェクトを走らせてみた - テストが一つ失敗した
Other implementations are wrongerer 他の実装では、さらに間違っている Ran BioRuby with Rubinius – 1 unit test failed Rubinius で BioRuby を走らせてみた - テストが一つが失敗した
Even JRuby is not immune JRuby も例に漏れず Made mistakes in the complicated task of splitting a file into lines ファイルを行に分割する複雑な作業でミス
How many bugs cause 0 failures? Fail しないバグはいくつ? 3 bugs caused 1 unit test failure each 3つのバグがそれぞれ一つの Fail  テストを生じる How many bugs caused 0 unit test failures each? では Fail してない時のバグはいくつ?
How can I be sure there weren't others? どのように他のエラーがないことを確認することができる? Rubinius and JRuby had failed me. RubySpec had failed me. Rubinius でも JRuby でも  RubySpec でもうまくいかなかった
What could I do? 私には何ができる? XKCD 386
What assumptions can I make about the problem? 問題に対してどういった想定をすれば良い?
Bugs are simple ソフトウェアのバグは簡単 Isolate them to a single failure, not several failures 、複数のフェイルがでているコードを単一のフェイルがでているところまで分離
Bugs are simple to fix バグの修正は簡単 Rubinius folk fixed bugs promptly Rubinius 開発者で  1 日以内にバグを修正 String#split 1 day (1 日 ) StringIO#gets 1 day (1 日 ) String#casecmp 3 days (3 日 )
Unexplored territory 未踏の領域 Bugs are from trying something not done before バグというのは今まで行われていなかった領域に足を踏み込む前に現れる
I'm happy to report that this is the first ever "Rubinius doesn't support flipflop" bug. I've been waiting for this day. 「 Rubinius がほげほげをサポートしてない」的なバグリポートをする日をずっと待っていた I'll go ahead and implement it now, I was waiting for someone to report it. It only took 5 years. 今すぐ実装するよ。だれかがリポートしてくれるのを5年間待ってたし
What is the Small Eigen Collider? 小型特異衝突型加速器って何?
How Small Eigen Collider Works 小型特異衝突型加速器はどう動く? Create same tasks, run on different Rubies, compare results 別のルビーで同じタスクを実行し、結果を比較。
Comparing results 比較結果 Me: What is the result of "a".casecmp("b")? YARV: -1 JRuby: -1 Rubinius: +1
Task execution タスクの実行 receiver.send(method_name, *parameters, &block) "a".send(:casecmp, ["b"], &:inspect)
Task creation – objects タスクの作成  -  オブジェクト Receiver and parameters are objects chosen at random, with a random number of parameters レシーバとパラメータはランダムに作成されたオブジェクト
Task creation – method タスクの作成  -  メソッド Potential methods based on reflection リフレクションによるメソッド候補作成 "a".methods # => [:upcase, :zip, ..., :casecmp, …] Method chosen at random 最後はランダムに選ばれる
Result comparison Receiver object: “a” Method: “casecmp” Parameters: [“b”] Result: -1 diff MRI_output.txt rubinius_output.txt  180c180 < Result: -1 --- > Result: 1 結果の比較
Task serialization タスクのシリアル化 Required for consistency これは、一貫性のために必要
Segmentation faults セグメンテーションフォールト CRuby and Rubinius can crash, so need tasks saved CRuby と Rubinius はクラッシュする可能性があるので、タスクを保存する必要あり
Discoveries 発見
Bugs のバグ String#casecmp bug in Rubinius String#casecmp Rubinius のバグ
Segmentation faults セグメンテーションフォールト Found in CRuby and Rubinius CRuby  と  Rubinius  で検出 Thread.kill(nil) caused a segfault in YARV Thread.kill(nil)  が  YARV  でセグフォールとを引き起こした
Current difficulties 現在の課題
Inconsistencies in inspect inspect の結果が実装ごとに異なる inspect has different results between implementations Default: #<StringIO:0x10169cfd8> Rubinius: #<StringIO:0xf7c @string=&quot;&quot; @lineno=0 @append=false @readable=true @writable=true @pos=0>
False alarms 誤報 Is giving nil rather than false a problem? &quot;false&quot; でなく &quot;nil&quot; を与える事は問題? &quot;\n&quot;.is_binary_data? Rbx, MRI 1.8: false JRuby 1.8: nil
Future directions 将来の方向性
Faster 高速化 Faster is often better 速ければより良い Move it to the cloud? クラウドに移行?
Questions? 質問?
Extra material! 補足資料
String#casecmp testing Testing everything except “happy path”! エッジケースのみテスト describe &quot;String#casecmp&quot; do it &quot;is a case-insensitive version of String#<=>&quot; do &quot;abcdef&quot;.casecmp(&quot;abcde&quot;).should == 1 &quot;aBcDeF&quot;.casecmp(&quot;abcdef&quot;).should == 0 &quot;abcdef&quot;.casecmp(&quot;abcdefg&quot;).should == -1 &quot;abcdef&quot;.casecmp(&quot;ABCDEF&quot;).should == 0 end # Snipped I18N tests end
Other bugs found by SEC SEC で見つかったバグ YAML.load(YAML.dump(Regexp.new('',0,'n'))) ''.unpack('d') { true } ObjectSpace.undefine_finalizer(:symbol) Fixnum.set_superclass Object ; 42.to_int YAML.try_implicit(0)
Other bugs independent of SEC SEC とは別に見つかったバグ &quot;XabXcd&quot;.split(&quot;X&quot;, 2) # => [&quot;ab&quot;] but no &quot;cd&quot; StringIO.new(&quot;phone&quot;).gets(&quot;on&quot;) # => gives &quot;pho&quot; when it should give &quot;phon&quot;
Thankyou! Domo arigato! どうもありがとう Translations: Makoto Inoue-san mame2-san Google Translate-san

Small eigen collider ruby kaigi 2011

  • 1.
    Andrew Grimm Universityof New South Wales ニューサウスウェールズ大学 (UNSW) RubyKaigi 2011 日本 Ruby 会議 2011 Finding Black Holes in Ruby with the Small Eigen Collider 小型特異衝突型加速器で Ruby 内のブラックホールの特異点を見つける方法
  • 2.
    tl;dr Too Long,Didn't Read( 長過ぎてよんでられない ) Creates random code. Metaprogramming magic! ランダムなコードを作成します。メタプログラミングマジック!
  • 3.
    Why? なんで? Whydid I create the Small Eigen Collider? なぜ私は小型特異衝突型加速器を作成した ?
  • 4.
    Background 背景 Bioinformaticianat UNSW UNSW のバイオインフォマティクス Looking at mutations in HIV HIV 感染の変異を見て
  • 5.
    Looking at mutations私は突然変異で探しています Start with viruses with identical DNA sequence 同一の DNA 配列を持つウイルスで始まります Allow to reproduce for one generation in laboratory 実験室内の 1 つの世代のために再現することができます Determine DNA sequence of new viruses 新しいウイルスの DNA 配列を決定する Differences are mutations 違いは突然変異です
  • 6.
    Big data ビッグデータLooking at approximately 500,000 sequences 約 50 万シーケンスを見て Approx. 150,000,000 DNA letters (A, C, G, T) 約。 1.5 億 DNA の文字( A 、 C 、 G 、 T ) For comparison, human genome is 3,000,000,000 letters 比較のために、ヒトゲノムは 30 億文字です
  • 7.
    Problem Ruby istoo slow XKCD 303 問題 Ruby は遅すぎる
  • 8.
    How slow ismy application? 私のアプリのスピード Currently using YARV Ruby 1.9.1 My application looks at 500,000 sequences 50万件のルックアップ An analysis takes 20 minutes 解析には20分かかる
  • 9.
    That's after someoptimizing! ちなみにこれはチューニングの 後の数字です
  • 10.
    Other Rubies mightbe faster ほかの Ruby 実装はもっと速いかも
  • 11.
    JRuby Faster atsome tasks Real multithreading (no GIL) 特定の処理は高速で真のマルチスレッド
  • 12.
    Rubinius Faster atsome tasks Real multithreading Real Soon Now 特定の処理は高速で真のマルチスレッドも近日リリース
  • 13.
    Ruby Enterprise EditionMainly better at garbage collection GC が良い。 More relevant to Rails developers than me Rails 開発者向き
  • 14.
    How do Iknow it'll give the correct results? どのように私はそれが正しい結果を与えているか知ることができる? Should I switch to a faster Ruby? もっと早い Ruby 実装に乗り換えるべき?
  • 15.
    What kind oferrors worry me? どういうエラーが心配? Large, obvious bugs that cause an exception are fine エラーを生じる明らかなバグはあまり心配なし Small, subtle bugs that give an incorrect result are bad 些細でまちがった結果を生じるバグがやばめ
  • 16.
    Other implementations arewrong 他の実装が間違っている Ran my project against Rubinius – 1 unit test failed Rubinius で自分のプロジェクトを走らせてみた - テストが一つ失敗した
  • 17.
    Other implementations arewrongerer 他の実装では、さらに間違っている Ran BioRuby with Rubinius – 1 unit test failed Rubinius で BioRuby を走らせてみた - テストが一つが失敗した
  • 18.
    Even JRuby isnot immune JRuby も例に漏れず Made mistakes in the complicated task of splitting a file into lines ファイルを行に分割する複雑な作業でミス
  • 19.
    How many bugscause 0 failures? Fail しないバグはいくつ? 3 bugs caused 1 unit test failure each 3つのバグがそれぞれ一つの Fail テストを生じる How many bugs caused 0 unit test failures each? では Fail してない時のバグはいくつ?
  • 20.
    How can Ibe sure there weren't others? どのように他のエラーがないことを確認することができる? Rubinius and JRuby had failed me. RubySpec had failed me. Rubinius でも JRuby でも RubySpec でもうまくいかなかった
  • 21.
    What could Ido? 私には何ができる? XKCD 386
  • 22.
    What assumptions canI make about the problem? 問題に対してどういった想定をすれば良い?
  • 23.
    Bugs are simpleソフトウェアのバグは簡単 Isolate them to a single failure, not several failures 、複数のフェイルがでているコードを単一のフェイルがでているところまで分離
  • 24.
    Bugs are simpleto fix バグの修正は簡単 Rubinius folk fixed bugs promptly Rubinius 開発者で 1 日以内にバグを修正 String#split 1 day (1 日 ) StringIO#gets 1 day (1 日 ) String#casecmp 3 days (3 日 )
  • 25.
    Unexplored territory 未踏の領域Bugs are from trying something not done before バグというのは今まで行われていなかった領域に足を踏み込む前に現れる
  • 26.
    I'm happy toreport that this is the first ever &quot;Rubinius doesn't support flipflop&quot; bug. I've been waiting for this day. 「 Rubinius がほげほげをサポートしてない」的なバグリポートをする日をずっと待っていた I'll go ahead and implement it now, I was waiting for someone to report it. It only took 5 years. 今すぐ実装するよ。だれかがリポートしてくれるのを5年間待ってたし
  • 27.
    What is theSmall Eigen Collider? 小型特異衝突型加速器って何?
  • 28.
    How Small EigenCollider Works 小型特異衝突型加速器はどう動く? Create same tasks, run on different Rubies, compare results 別のルビーで同じタスクを実行し、結果を比較。
  • 29.
    Comparing results 比較結果Me: What is the result of &quot;a&quot;.casecmp(&quot;b&quot;)? YARV: -1 JRuby: -1 Rubinius: +1
  • 30.
    Task execution タスクの実行receiver.send(method_name, *parameters, &block) &quot;a&quot;.send(:casecmp, [&quot;b&quot;], &:inspect)
  • 31.
    Task creation –objects タスクの作成 - オブジェクト Receiver and parameters are objects chosen at random, with a random number of parameters レシーバとパラメータはランダムに作成されたオブジェクト
  • 32.
    Task creation –method タスクの作成 - メソッド Potential methods based on reflection リフレクションによるメソッド候補作成 &quot;a&quot;.methods # => [:upcase, :zip, ..., :casecmp, …] Method chosen at random 最後はランダムに選ばれる
  • 33.
    Result comparison Receiverobject: “a” Method: “casecmp” Parameters: [“b”] Result: -1 diff MRI_output.txt rubinius_output.txt 180c180 < Result: -1 --- > Result: 1 結果の比較
  • 34.
    Task serialization タスクのシリアル化Required for consistency これは、一貫性のために必要
  • 35.
    Segmentation faults セグメンテーションフォールトCRuby and Rubinius can crash, so need tasks saved CRuby と Rubinius はクラッシュする可能性があるので、タスクを保存する必要あり
  • 36.
  • 37.
    Bugs のバグ String#casecmpbug in Rubinius String#casecmp Rubinius のバグ
  • 38.
    Segmentation faults セグメンテーションフォールトFound in CRuby and Rubinius CRuby と Rubinius で検出 Thread.kill(nil) caused a segfault in YARV Thread.kill(nil) が YARV でセグフォールとを引き起こした
  • 39.
  • 40.
    Inconsistencies in inspectinspect の結果が実装ごとに異なる inspect has different results between implementations Default: #<StringIO:0x10169cfd8> Rubinius: #<StringIO:0xf7c @string=&quot;&quot; @lineno=0 @append=false @readable=true @writable=true @pos=0>
  • 41.
    False alarms 誤報Is giving nil rather than false a problem? &quot;false&quot; でなく &quot;nil&quot; を与える事は問題? &quot;\n&quot;.is_binary_data? Rbx, MRI 1.8: false JRuby 1.8: nil
  • 42.
  • 43.
    Faster 高速化 Fasteris often better 速ければより良い Move it to the cloud? クラウドに移行?
  • 44.
  • 45.
  • 46.
    String#casecmp testing Testingeverything except “happy path”! エッジケースのみテスト describe &quot;String#casecmp&quot; do it &quot;is a case-insensitive version of String#<=>&quot; do &quot;abcdef&quot;.casecmp(&quot;abcde&quot;).should == 1 &quot;aBcDeF&quot;.casecmp(&quot;abcdef&quot;).should == 0 &quot;abcdef&quot;.casecmp(&quot;abcdefg&quot;).should == -1 &quot;abcdef&quot;.casecmp(&quot;ABCDEF&quot;).should == 0 end # Snipped I18N tests end
  • 47.
    Other bugs foundby SEC SEC で見つかったバグ YAML.load(YAML.dump(Regexp.new('',0,'n'))) ''.unpack('d') { true } ObjectSpace.undefine_finalizer(:symbol) Fixnum.set_superclass Object ; 42.to_int YAML.try_implicit(0)
  • 48.
    Other bugs independentof SEC SEC とは別に見つかったバグ &quot;XabXcd&quot;.split(&quot;X&quot;, 2) # => [&quot;ab&quot;] but no &quot;cd&quot; StringIO.new(&quot;phone&quot;).gets(&quot;on&quot;) # => gives &quot;pho&quot; when it should give &quot;phon&quot;
  • 49.
    Thankyou! Domo arigato!どうもありがとう Translations: Makoto Inoue-san mame2-san Google Translate-san