You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
RubyKaigi 2014行った。良い発表がいろいろ聞けたんだけど、最近ISUCONに向けてwebアプリのチューニングに興味があったので特にfinal keynoteが興味深かった。 その中で紹介されていたtmm1/rblineprofが行ごとの実行時間を表示してくれるのでとても便利そうだったんだけど、GitHubではpeek/peek-rblineprofというRails用のプラグインでrblineprofを活用しているので、ISUCONでおそらく使用されるであろうsinatraでどうやって使うか考えていた。 kainosnoema/rack-lineprofというgemがその用途に便利そうだったので紹介したい。 使い方 rack-lineprofはRack middlewareで、まず以下のようにuseする必要がある。 require 'rack-lineprof' class My
rescue_from で拾えない例外がある Rails が用意してくれている rescue_from は controller の外側で発生した例外を拾ってくれない。 例えばパラメータに不正なエンコーディングが含まれるときに、Rails は ActionController::BadRequest を例外として投げる。しかし、この処理は Rails の routing 層で行われているため rescue_from で捕捉することはできない。 そのため Rails の外で発生した例外を捕捉していない場合、ユーザには意図していないエラーページが見えている可能性がある。 Rails の外で起きる例外は exceptions_app で処理するのがお手軽 例えば config/initializers/exceptions_app.rb に以下のコードを書いておく(ErrorsControlle
a2ikm/rack-dynamic_session_secure RailsのセッションストアではRack::Session::Abstract::IDに渡される:secureオプションの値によってCookieのsecure属性を付けたり外したりできるんだけど、基本的にベタの値*1しか受け付けていない。 これをリクエストによって切り替えられると嬉しい場面が出てきたので、Procを渡して動的に評価されるよう書いてみた。Railsだとこんな感じ: # Gemfile gem 'rack-dynamic_session_secure', github: 'a2ikm/rack-dynamic_session_secure' # config/initializers/session_store.rb secure = ->(env) { !!(Rack::Request.new(env).pa
This post is part of a series of 31 Rails 4 articles being released each day in December 2012. A big change to Rails 4 is that production applications will now be thread safe by default. This will have huge performance benefits for applications as they will be able to serve more than one request at a time. Thread Safe Code If you are running a production server which allows for concurrency, such a
UPDATE: The benchmarks have been updated for new versions of ruby, jruby, puma and unicorn Previously I wrote about the difference in performance between using thin, puma and unicorn on heroku’s cedar stack. At the time, heroku’s recommendations where to use thin as a server. They now recommend unicorn for better performance and concurrency. Additionally, I received some very valid criticism on th
Rack::Multiplexerという、複数のRackを束ねるものをつくった。 Plack寄せ この前Perl界隈の人達と鍋を囲む機会があって、 !!1;の話、livedoor BlogのPlack化の話、ISUCONの話、 各社古いアプリ抱えていて辛いね苦しいね頑張ろうね若者に1日で書き換えさせようといった話をして、 結局、何となくこの界隈は全体的に「Plack寄せ」が進んでいるねという話に落ち着いた。 Rack寄せ 一方Ruby界隈だと比較的皆Rackに寄っている傾向にはあると思うけど、 もっと寄せてみると面白いんじゃないかと思って、Rack::Multiplexerをつくった。既にありそう。 Rack::Multiplexerは、所謂WebアプリのRouter(=Dispatcher)の処理を行うための実装で、 メソッドやパスの規則に従って受け取ったリクエストを別のRack app
callの返り値の順序とRack::Response.newの引数の順序が違ったのでメモ。*で展開できたら楽だったのになあ。 class GreatMiddleware def initialize(app) @app = app end def call(env) result = @app.call(env) response = Rack::Response.new(result[2], result[0], result[1]) great_method(response) return result end private def great_method(response) # snip end end
開発環境と本番環境で favicon を変える というのに感動したのでRack middlewareでやってみました。というか、昨日のPlack::Middleware::DevFaviconをRackに移植しただけですけど。 Plack版とおなじく単に favicon.ico ないし favicon.png という名前にマッチしたらグレースケールにして返すというだけの代物ですが、Rack middlwareなので簡単に導入できるのが楽かなと。 使い方は以下のとおり。faviconを配信するミドルウェアよりも先にuseしてください。 if ENV['RACK_ENV'] != 'production' require 'rack-devfavicon' use Rack::DevFavicon end map "/favicon.ico" do run Rack::File.new("#{
この middleware ちゃんと動いてるか確認したい、とか、この middleware とこの middleware を同時に使うとなんかヘッダがおかしいけどどうなってるの!とか、そういうののデバッグ法。 単にログ吐く middleware を stack の途中に積めばよい。 @app.call の前後でそれぞれロギングできる。 class M def initialize(app) @app = app end def call(env) warn '='*80 env.each do |k,v| warn "#{k}=#{v}" end warn '='*80 triplet = @app.call(env) warn triplet.inspect triplet end end config.middleware.insert_before Rack::ETag, M con
Community discussion forum - post a message here if you’re experiencing problems. Support on this forum is provided by the community on a best-effort basis, so a (timely) response is not guaranteed. Issue tracker - report bugs here. Email support@phusion.nl if you are a Phusion Passenger Enterprise customer. Please mention your order reference. If you are not an Enterprise customer, we kindly redi
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く