• 小米!性价比不错

  • 明显有触发条件,为啥要用定时任务?

  • extract model codes into Module... 具体方法可以看 ihower 的 ppt

  • 代码托管服务 bitbucket at February 10, 2012

    个人私有项目我用 Heroku.......

  • passenger

  • 图片上传后剪切缩放功能? at February 10, 2012
  • grape 写 api 发送文件 at February 09, 2012

    #2 楼 @yakjuly API 很少有直接传文件的吧 都是返回文件 URL 的...

  • tree + 1

  • 是哇 是哇

  • 谈谈今天 ruby-china 的优化 at February 05, 2012

    #23 楼 @dazuiba 扩大 cache 的范围必然增大缓存失效的机率。得不偿失呀!除非想做成静态页。 缓存的粒度应该是越小越好。

  • 谈谈今天 ruby-china 的优化 at February 05, 2012

    #17 楼 @fsword https://gist.github.com/1739013 前面 100 个是加了 collection 选项的,后面是没加的

  • 谈谈今天 ruby-china 的优化 at February 05, 2012

    #10 楼 @huacnlee 那样编辑的时候就乱了。。只能加缓存

  • 谈谈今天 ruby-china 的优化 at February 05, 2012

    @fsword 做了一个简单的测试:

    <% unless params[:collection]%>
      <% @topic.posts.each do |post|%>
        <%= render :partial => "post", :locals => {:post => post}%>
      <% end%>
    <% else %>
      <%= render :partial => "post", :collection => @topic.posts%>
    <% end %>
    

    使用 collection 选项 100 个请求耗时 1.73s

    hooopo@hooopo:~/demo$ ab -c1 -n100 http://localhost:3000/topics/1?collection=1
    This is ApacheBench, Version 2.3 <$Revision: 655654 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking localhost (be patient).....done
    
    
    Server Software:        thin
    Server Hostname:        localhost
    Server Port:            3000
    
    Document Path:          /topics/1?collection=1
    Document Length:        26220 bytes
    
    Concurrency Level:      1
    Time taken for tests:   1.731 seconds
    Complete requests:      100
    Failed requests:        0
    Write errors:           0
    Total transferred:      2688900 bytes
    HTML transferred:       2622000 bytes
    Requests per second:    57.78 [#/sec] (mean)
    Time per request:       17.307 [ms] (mean)
    Time per request:       17.307 [ms] (mean, across all concurrent requests)
    Transfer rate:          1517.20 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.0      0       0
    Processing:    11   17  10.7     11      47
    Waiting:       11   17  10.7     11      47
    Total:         11   17  10.7     11      47
    
    Percentage of the requests served within a certain time (ms)
      50%     11
      66%     13
      75%     14
      80%     36
      90%     37
      95%     38
      98%     43
      99%     47
     100%     47 (longest request)
    

    循环 render 耗时 2.24

    hooopo@hooopo:~/demo$ ab -c1 -n100 http://localhost:3000/topics/1
    This is ApacheBench, Version 2.3 <$Revision: 655654 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking localhost (be patient).....done
    
    
    Server Software:        thin
    Server Hostname:        localhost
    Server Port:            3000
    
    Document Path:          /topics/1
    Document Length:        26467 bytes
    
    Concurrency Level:      1
    Time taken for tests:   2.249 seconds
    Complete requests:      100
    Failed requests:        0
    Write errors:           0
    Total transferred:      2713600 bytes
    HTML transferred:       2646700 bytes
    Requests per second:    44.46 [#/sec] (mean)
    Time per request:       22.492 [ms] (mean)
    Time per request:       22.492 [ms] (mean, across all concurrent requests)
    Transfer rate:          1178.20 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.0      0       0
    Processing:    14   22  12.3     16      61
    Waiting:       14   22  12.3     16      61
    Total:         15   22  12.3     16      61
    
    Percentage of the requests served within a certain time (ms)
      50%     16
      66%     18
      75%     22
      80%     42
      90%     43
      95%     48
      98%     52
      99%     61
     100%     61 (longest request)
    

    ruby 1.9.3-p0 ,Rails3.2.1 评论数量是 100 个,_post.html.erb 是简单的读属性没有复杂逻辑,从日志也可以看到循环 render 的耗时明显高于 render collection

  • 谈谈今天 ruby-china 的优化 at February 04, 2012

    这句呀:

    <% replies.each_with_index do |reply,i| %>
      <%= render :partial => "replies/reply", :locals => {:topic => topic, :item => reply, :i => i} %>
    <% end %>
    

    改成:

    <%= render :partial => "replies/reply", :collection => replies%>
    

    (模板里的变量可能要调整一下)

    渲染局部模板是 Rails 里的性能瓶颈之一,像这种循环里 render 相当于数据库查询里面的 n+1 query 了。。

  • #7 楼 @HungYuHei 围观之后的感想: DHH 就是 IT 界的 HH。。 1.名字就很像 2.都有一群粉丝 3.都开赛车 4.都有过一点儿反智言论..

    PS.这个 pull request 好像没人理呀

  • 其实我觉得即使不用 cell,这种组件也应该是自包含的。就是不该依赖 controller 里的变量。

    <%= cache("topic/init_list_sidebar/hot_nodes",:expires_in => 30.minutes) do %>
     <div class="hot_nodes nodes box">
        <h2>热门节点</h2>
        <ul>
          <% Node.hots.limit(10).each do |node| %>
            <li><a href="<%= node_topics_path(:id => node.id) %>"><%= node.name %></a></li>
          <% end %>
        </ul>
      </div>
    <% end %>
    

    优雅一些可以在 Helper 里:

    def hot_notes
      Node.hots.limit(10)
    end
    

    view:

    <%= cache("topic/init_list_sidebar/hot_nodes",:expires_in => 30.minutes) do %>
     <div class="hot_nodes nodes box">
        <h2>热门节点</h2>
        <ul>
          <% hot_nodes.each do |node| %>
            <li><a href="<%= node_topics_path(:id => node.id) %>"><%= node.name %></a></li>
          <% end %>
        </ul>
      </div>
    <% end %>
    

    再 DRY 一下,可以做成局部模板:

    <%= cache("topic/init_list_sidebar/hot_nodes",:expires_in => 30.minutes) do %>
      <%= render :hot_nodes %>
    <% end %>
    

    这种通用组件依赖 controller 里的实例变量的缺点是,如果有多个页面需要调用,必须在 controller 里都加这么一句:

    @hot_nodes = Node.hots.limit(10)
    

    还有就是楼主描述的缓存时候会出现的问题

  • 都不要争啦。。 unless @hot_nodes最 Ruby! if @hot_nodes.present?最 Rails! if defined?(@hot_nodes) 最 Professional!

  • 谈谈今天 ruby-china 的优化 at February 04, 2012

    为什么要 render 这么多次 reply 这个模板?加:collection 选项呀

  • Rails,不折腾。。。

  • +1 当初我就是在 windows 下学的 Ruby/Rails,好痛苦........浪费了大量时间

  • #3 楼 @ery 是哇 gemset

  • #2 楼 @bindiry 用 file 命令呀 不是图片也能处理

  • 我用 octopress 新搭的 blog at January 23, 2012

    嘿嘿 我也搞了一个。。 http://hooopo.github.com

  • #17 楼 @Saito http://stackoverflow.com/questions/4474920/trying-to-add-rvmrc-to-ignore-its-not-working

    rvm 的 doc 里把 check rvmrc into source control 当作 best practice,而 Rails 却给 ignore 了。 https://rvm.beginrescueend.com/rvm/best-practices/ https://github.com/rails/rails/pull/194

    PS. 楼主对不起哇 跑题了...........

  • #17 楼 @Saito 插!这是为什马?!

  • #15 楼 @Saito rvmrc 可以放啊 不过不提交到源码库就行了。我看好多开源项目是把 rvmrc 提交到源码库的,我很迷惑呀 如果只有一个人开发放不放进去是没有什么关系的,或是团队之间对使用 rvm、使用 gemset 与否,gemset 起什么名字、使用什么版本的 ruby 这些都约定好。

  • #13 楼 @Saito rvmrc 我觉得就和项目关系不大哈 有些人用 rvm,有些人不用 有些人用 rvm 还用 gemset,有些人不用 gemset ... 这个东西应该是更 user spec 而不是 project spec...

  • #11 楼 @Saito 你们这些.xxx 文件放到 gitignore 吗