filterã®ããã©ã¼ãã³ã¹ãã¹ã
before_filter, after_filter, around_filter ãææ°éãã¦ã
ã©ã®ãããããã©ã¼ãã³ã¹ã«å½±é¿ãåºãã®ãããã£ãã調ã¹ã¦ã¿ã
ç°å¢
- App Server
- Amazon EC2: Large Instance
- Apache: ããã©ã«ãè¨å®
- Ruby: 1.8.7
- Passenger
- RailsEnv: production
- RailsMaxPoolSize: 30
- RailsPoolIdleTime: 1200
- Rails: 2.3.8
- Request Server
- Amazon EC2: Large Instance
- ab (Apache Bench) ã§App Serverã«å¯¾ãã¦ãªã¯ã¨ã¹ã
- 100件åææ¥ç¶ã5ç§éç¶ãã¦ãã©ãããããªã¯ã¨ã¹ããå¦çã§ããããè¦ã
$ ab -c 100 -t 5 http://ec2-***.amazonaws.com/filter_check
çµæ
å ã«çµæã
ä¸è¨ãabã³ãã³ãã10åå®è¡ããå¹³åã®ãComplete requests*1ããRequests per second*2ããçµæã¨ãã
表ã®é ç®åå®ç¾©
- ctrler_10: ã³ã³ããã¼ã©å ã®åä¸ã¡ã½ããã10æ
- ctrler_100: ã³ã³ããã¼ã©å ã®åä¸ã¡ã½ããã100æ
- cls_10: filterã¯ã©ã¹(newç¡ã)ã10æ
- cls_100: filterã¯ã©ã¹(newç¡ã)ã100æ
- cls_new_10: filterã¯ã©ã¹(newæã)ã10æ
- cls_new_100: filterã¯ã©ã¹(newæã)ã100æ
ãªããfilterã®ä¸èº«ã¯ç©º
filter ç¡ã
- Complete requests: 2442.1
- Requests per second: 487.897
before_filter
ctrler_10 | ctrler_100 | cls_10 | cls_100 | cls_new_10 | cls_new_100 | |
---|---|---|---|---|---|---|
Complete requests | 2255.1 | 1543.9 | 2148 | 1492.4 | 2244.6 | 1467.5 |
Requests per second | 450.536 | 308.538 | 429.212 | 298.123 | 448.455 | 293.194 |
after_filter
ctrler_10 | ctrler_100 | cls_10 | cls_100 | cls_new_10 | cls_new_100 | |
---|---|---|---|---|---|---|
Complete requests | 2245.1 | 1482 | 2205 | 1555.8 | 2187.3 | 1444.5 |
Requests per second | 448.375 | 295.654 | 440.341 | 310.75 | 436.62 | 288.5 |
around_filter
ctrler_10 | ctrler_100 | cls_10 | cls_100 | cls_new_10 | cls_new_100 | |
---|---|---|---|---|---|---|
Complete requests | 1864 | 167 | 1465.3 | 15 | 1453.9 | 11.8 |
Requests per second | 372.369 | 33.291 | 292.664 | 2.902 | 290.409 | 2.292 |
before_filter & after_filter
ctrler_10 | ctrler_100 | cls_10 | cls_100 | cls_new_10 | cls_new_100 | |
---|---|---|---|---|---|---|
Complete requests | 2079 | 1071.6 | 2077.3 | 1011.8 | 2038.7 | 1042.4 |
Requests per second | 415.254 | 214.024 | 415.154 | 201.969 | 407.193 | 208.08 |
ææ³
before_filter, after_filter 10æãããã ã¨ã
ã³ã³ããã¼ã©å
ã¡ã½ããã§ããfilterã¯ã©ã¹ã§ãããã»ã©å·®ã¯ãªããã
åé¡ã«ãªãã»ã©ã§ã¯ãªãããã
around_filter ã¯çµæ§éã
ãã¾ãã«ãã³ã³ããã¼ã©å
ã¡ã½ããã§ã¯ãªããfilterã¯ã©ã¹ã ã¨ããã«ããã
ã³ã¼ã
### app/controllers/filter_check_controller.rb class FilterCheckController < ApplicationController # ctrler_10,100 #before_filter :ctrler_before_filter, :ctrler_before_filter, :ctrler_before_filter, ... # cls_10,100 #before_filter TestFilter, TestFilter, TestFilter, ... # cls_new_10,100 #before_filter TestFilter2.new, TestFilter2.new, TestFilter2.new, ... def index render :text => "done" end private # ã³ã³ããã¼ã©å ã®filterç¨ã¡ã½ãã def ctrler_before_filter end def ctrler_after_filter end def ctrler_around_filter yield end end ### lib/test_filter.rb # filterã¯ã©ã¹(newç¡ã) class TestFilter def self.before(controller) end def self.after(controller) end end ### lib/test_filter2.rb # filterã¯ã©ã¹(newæã) class TestFilter2 def before(controller) end def after(controller) end end