Rails Rails 视图返回时间不正常,感觉很复杂,求解!

windwiny · 2013年09月27日 · 最后由 kevinxu 回复于 2013年09月27日 · 2353 次阅读

rails 项目,用 thin + nginx 运行,然后同时打开多个页面,返回时间不正常。

- 创建 rails 项目,创建 h、k 两个 controller, 各有 a1/ a2/ a3 3 个 action

action 内容都是

@t1=Time.now sleep 5 @t2=Time.now view 内容都加入

!!!! <%= @t1.strftime "%H%M%S" -%> to <%= @t2.strftime "%H%M%S" %> == <%= @t2-@t1 -%> !!!!

- Gemfile 里加入

gem 'thin'

- 启动

用 thin start -p 3001 启动 3001-3005 5 个端口,启动 nginx 代理这 5 个端口

- 用脚本测试

require "eventmachine"

IP = '127.0.0.1' PORT = 80 # 3000 PROTOVER = "1.0" # "1.1"

ENDS = [] URLS = %W{ /h/a1 /h/a1 /h/a1 /h/a1 /h/a1 /h/a1

/h/a2 /h/a2 /h/a2 /h/a2 /h/a2 /h/a2

/h/a3 /h/a3 /h/a3 /h/a3 /h/a3 /h/a3

/k/a1 /k/a1 /k/a1 /k/a1 /k/a1 /k/a1

/k/a2 /k/a2 /k/a2 /k/a2 /k/a2 /k/a2

/k/a3 /k/a3 /k/a3 /k/a3 /k/a3 /k/a3 }

module Client def post_init @@i ||= -1 @@i += 1 @myid = @@i @t1 = Time.now @data = '' send_data "GET #{URLS[@myid]} HTTP/#{PROTOVER}\r\nHost: #{IP}:#{PORT}\r\n\r\n" end def unbind @t2 = Time.now if /500 Internal Server Error/ =~ @data p "500 Internal Server Error" end /!!!! (?.*) !!!!/xm =~ @data puts "myid: #{@myid} #{URLS[@myid]} Socket_time: #{@t1.strftime '%H%M%S'} to #{@t2.strftime '%H%M%S'} == #{@t2-@t1} Rails_time: #{msg} #{@data[-8..-2]}" ENDS << @myid if ENDS.size == URLS.size EM.stop end end def receive_data data @data << data if @data.include? '

http1.1 keepalive 了吧

请 wireshark 大神瞧一眼看看。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号