rails 项目,用 thin + nginx 运行,然后同时打开多个页面,返回时间不正常。
action 内容都是
@t1=Time.now sleep 5 @t2=Time.now view 内容都加入
!!!! <%= @t1.strftime "%H%M%S" -%> to <%= @t2.strftime "%H%M%S" %> == <%= @t2-@t1 -%> !!!!
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? '