Small eigen collider ruby kaigi 2011

Preview:

Citation preview

Andrew GrimmUniversity of New South Wales

ニューサウスウェールズ大学 (UNSW)RubyKaigi 2011

日本 Ruby 会議 2011

Finding Black Holes in Ruby with the Small Eigen Collider

小型特異衝突型加速器で Ruby内のブラックホールの特異点を見つけ

る方法

tl;drToo 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 slowXKCD 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 immuneJRubyも例に漏れず

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 inspectinspectの結果が実装ごとに異なる

inspect has different results between implementations

Default: #<StringIO:0x10169cfd8> Rubinius: #<StringIO:0xf7c @string=""

@lineno=0 @append=false @readable=true @writable=true @pos=0>

False alarms誤報

Is giving nil rather than false a problem? "false"でなく "nil"を与える事は問題? "\n".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

describe "String#casecmp" do it "is a case-insensitive version of String#<=>" do "abcdef".casecmp("abcde").should == 1 "aBcDeF".casecmp("abcdef").should == 0 "abcdef".casecmp("abcdefg").should == -1 "abcdef".casecmp("ABCDEF").should == 0 end # Snipped I18N testsend

Testing everything except “happy path”! エッジケースのみテスト

Other bugs found by SECSECで見つかったバグ

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 SECSECとは別に見つかったバグ

"XabXcd".split("X", 2) # => ["ab"] but no "cd" StringIO.new("phone").gets("on") # => gives "pho"

when it should give "phon"

Thankyou!Domo arigato!

どうもありがとう Translations:

Makoto Inoue-san mame2-san Google Translate-san

Recommended