Benchmarkspec

2,524
-1

Published on

Benchmark Specとは、RSpec + Benchmark-ips。

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,524
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • こんにちは!
    よろしくお願いします。

    直前でタイトル変えました。
    Benchmark Specというのを紹介したいと思います。
  • パフォーマンス要求
    どれくらいの処理速度が必要か指定できる。
  • 内部の仕組みとしてはbenchmark-ipsを使用しているので、指定した処理に対して、1秒間に何回実行できたかを測るものです。
  • これで、ある処理が要求するパフォーマンスを満たしているかのテストがかけます。
  • Benchmarkspec

    1. 1. Benchmark Spec Proprietary and Confidential to Ruby Development Co., LTD page1
    2. 2. Proprietary and Confidential to Ruby Development Co., LTD page2 • 自己紹介 • 氏名:柴田 有一郎 • 所属:株式会社 Ruby開発 https://www.ruby-dev.jp • 職業:Web系のプロマネ的なことをやってます
    3. 3. Proprietary and Confidential to Ruby Development Co., LTD page3 • ここから本題 • 元ネタあります。 • http://www.gladbills.com/help/development/benchmarking.md • 2015/10/02にGitLabにマージされています • Benchmark Specとは = RSpec + benchmark-ips
    4. 4. Proprietary and Confidential to Ruby Development Co., LTD page4 • よくあるパフォーマンス上の問題?? • 修正でパフォーマンス上問題のある処理を入れてしまった!! • CIでの自動化テストでは検出できない • QAで検出できても、複数の修正が入ってると特定に時間がかか る
    5. 5. Proprietary and Confidential to Ruby Development Co., LTD page5 • 解決するために、こんなアプローチはどう? • CIで自動テストのように、自動ベンチマークを行う • パフォーマンス要求を設定できる
    6. 6. Proprietary and Confidential to Ruby Development Co., LTD page6 • 具体的にどんな感じ? • describe でbenchmark を指定 • 「benchmark」が指定されたときだけ、benchmark spec機能を有効にします。 describe User, benchmark: true do end
    7. 7. Proprietary and Confidential to Ruby Development Co., LTD page7 • ユーザログイン処理のbenchmark Specを例に説明 describe User, benchmark: true do describe ‘.by_login’ do before do create(:user, email: ‘alice@ruby-dev.jp’) end ユーザを作成 例は超適当です(_ _)
    8. 8. Proprietary and Confidential to Ruby Development Co., LTD page8 • パフォーマンス要求を設定 describe User, benchmark: true do describe ‘.by_login’ do before do create(:user, email: ‘alice@ruby-dev.jp’) end let(:iterations) { 1000 } 1秒間に1000回以上で成功 (平均して1回のログイン処理 は1ミリ秒以内)
    9. 9. Proprietary and Confidential to Ruby Development Co., LTD page9 • subjectへ登録 let(:iterations) { 1000 } describe ‘using a Email address’ do subject{ -> { User.by_login(‘alice@ruby-dev.jp’)} } テスト対象として、.by_loginを Procオブジェクトとして登録
    10. 10. Proprietary and Confidential to Ruby Development Co., LTD page10 • エクスペクテーション(expectation)は? describe ‘using a Email address’ do subject{ -> { User.by_login(‘alice@ruby-dev.jp’)} } it { is_expected.to iterate_per_second(iterations) } end end end カスタムマッチャ「iterate_per_second」 を作成し、使用します。 ※いきなり出てきて申し訳ないです。 以降説明あります。
    11. 11. Proprietary and Confidential to Ruby Development Co., LTD page11 • カスタムマッチャー「iterate_per_second」 • 元ネタから説明用にかなり単純化しています。 module BenchmarkMatchers extend RSpec::Matchers::DSL matcher :iterate_per_second do |min_iterations| match do |block| report = Benchmark.ips(quiet: true) do |bench| bench.report(&block) end 内部で、Benchmark.ipsを実施 rails_helper.rbでinclude config.include BenchmarkMatchers, benchmark: true
    12. 12. Proprietary and Confidential to Ruby Development Co., LTD page12 • カスタムマッチャー「iterate_per_second」 matcher :iterate_per_second do |min_iterations| match do |block| report = Benchmark.ips(quiet: true) do |bench| bench.report(&block) end expect(report.entries[0].ips).to be >= min_iterations end end 要求されるイテレーション以上な ら、テスト成功。
    13. 13. Proprietary and Confidential to Ruby Development Co., LTD page13 まとめ 今後、benchmark specを導入して、性能を 落とす処理の混入をCIで検出できるか試し て行きたいと考えています。
    14. 14. Proprietary and Confidential to Ruby Development Co., LTD page14 •最後に • ありがとうございました!
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×