tanihito’s blog

デジタル・新規事業開発・健康など、興味のあることについてつらつらと書いてきます。

RubyKaigi2013に参加しました

2013/05/30~6/1の3日間で開催されたRubyKaigiに参加してきました。自分が参加した発表について、内容をまとめておきます。Ustream・スライドはここにまとまっています。

The Future of JRuby?

JRubyとは、JVM上で動くRubyのこと.

  • 欠点:JVMの開発スピードが遅い
  • 利点:JVMが改善されれば、JRubyの性能の自動的に向上する。現状でRuby1.8よりも早い。

Ruby 'root'

https://speakerdeck.com/hsbt/ruby-root
Rubyコミッターの仕事の紹介。pull requestのmergeや、Rubyでライブラリのテストが通るかの確認(http://ci.hsbt.org/)などを行なっている。

Toward efficient Ruby 2.1

http://rvm.jp/t.pdf
Ruby2.1のRestricted generational Garbage Collection (RGenGC) の説明。

bundle install` Y U SO SLOW: Server Edition'

BundlerAPIをHeroku上で動かした話。

Refining refinements

https://speakerdeck.com/shugo/refining-refinements
Ruby2.0で追加されたrefinements機能の説明。main.using(mod)を呼んだ以降でそのmoduleの関数が使えるようになる。monkey patchに似ているが、monkey patchは全てのクラスが影響を受けるのに対し、refinementsはusingが呼ばれたファイルのみ影響を受けるため、影響範囲を小さくできる。

High Performance Rails

http://rubykaigi.org/2013/talk/S76
CockpadでのRailsの高速化の話。

  • response time (X-Runtime) を200ms以内にしている。
  • Rubyは遅いので、できるだけRubyに処理をさせない。
    • Apache (static files) -> Varnish (page caching) -> Nginx (proxy buffering) -> Unicorn (Rails)
  • Rubyのバージョンを上げる。1.9.3から2.0.0にすると20ms早くなった。
  • Railsの遅い、高速化が必要な場所
    • ActiveRecordのモデル作成
    • routing: url_forを含むviewのhelper
link_to 'hello', hello_index_url
#=> 0.09659 ms
link_to 'hello', controller: 'hello', action: 'index'
#=> 10.97867 ms
  • template engine
    • コンパイルは最初の一回だけなので、レンダリング時間のほうが重要
    • Slim, ERB, Haml の順番で早い
    • 全体の速度にはあまり影響しないので、使いやすいものを選べばよい
  • unicornGCを無効化する
    • 数リクエストごとにまとめてGCを実行することで、レスポンスタイムを短くできる
# config.ru
require "unicorn/oob_gc"
use Unicorn::OobGC, 10
# unicorn config
after_fork do |server, worker|
  GC.disable
end
    • unicorn-worker-killerを使って、メモリを使いすぎたときにworkerをkillできるようにする。
  • Slow Queryを集計しておく

Continuous gem dependency updating with Jenkins and Pull Request

https://speakerdeck.com/kyanny/continuous-gem-dependency-updating-with-jenkins-and-pull-request
Gemfile.lockを更新してpull requestを送るJenkinsタスクを作成し、毎日実行する。

  • hubコマンドを使用する。
  • pull requestのタイトルにテストの結果を書く。失敗していたらすぐに調査。
  • アバターにJenkinsのイラストを使用。
git checkout -b bundle-update-YYYYMMDD
bundle update
git add Gemfile.lock
git cimmit -m 'bundle update'
bundle exec rake spec
hub pull-request

Security is hard, but we can’t go shopping

Concerning 'Applications'

https://speakerdeck.com/moro/concerning-application
ActiveSupport::Concernの紹介。

  • クラスメソッド・インスタンスメソッド・属性の設定などを簡単にincludeできる。
  • Rails4ではcontrollersとmodelsの下にconcernsディレクトリができる。

Refactoring Fat Models with Patterns

http://www.ustream.tv/recorded/33569967
https://github.com/codeclimate/refactoring-fat-models
codeclimateのブログと同じ内容。concernを使ったmix-inを否定しているところが、前の発表と真逆。

Millions of Apps Deployed: What We've Learned

アプリ作成のTips集

  • security_tokenはハードコーディングせずに環境変数に入れる。「このアプリをそのままオープンソースにできるか?」
  • 開発環境と本番環境はできるだけ揃える
    • DB
    • Rubyバージョン
    • データ
  • README.mdを書く
    • 外部ライブラリのインストール方法
    • アプリの起動方法
    • 開発環境での注意点

If you do not enter the tiger's cave, you will not catch its cub: Objects, DCI, and Programming

DCI (Data, context and interaction) の紹介。DCIは面白そうなので後で調べる。参考資料:

The Origamist's Ruby: Folding better code

リファクタリング方法について。

  • Sandi Metz’ rules for developers
    • Classes can be no longer than one hundred lines of code.
    • Methods can be no longer than five lines of code.
    • Pass no more than four parameters into a method. Hash options are parameters.
    • Controllers can instantiate only one object. Therefore, views can only know about one instance variable and views should only send messages to that object (@object.collaborator.value is not allowed).
  • “Learn the rules like a pro, so you can break them like an artist.” - Pablo Picasso

Be a library developer!

http://www.slideshare.net/kou/rubykaigi-2013

  • Remember Than Imagine
    • 問題を解決するための知識(パターン)があると、解決方法を創造するよりも早い
    • Libraryを書くことで、知識を実装にする練習をしよう

'The Metric Talks or Not

https://speakerdeck.com/irohiroki/the-metric-talks-or-not

Contributing to Ruby

どうやってRubyコミュニティーに貢献するか。rdocでドキュメンテーションされていない関数を探し、修正してpull requestを送るところまでをライブコーディングしていた。

LT

  • 暗記用ツールankiの紹介。なぜPythonのツールをRubyKaigiで紹介したのかは謎。
  • rspecの自動作成ツールrspec-kickstarterの紹介。既存のテストがないクラスを修正する際に、これでテストを作っておくとデグレが減るかも。