0
我有一段寫入套接字的代碼,然後從服務器讀取響應。服務器速度非常快(每次5ms內響應)。但是,寫入套接字很快 - 從套接字讀取響應總是慢得多。任何線索?從TCPSocket讀取Ruby/Rails的速度很慢
module UriTester
module UriInfo
class << self
def send_receive(socket, xml)
# socket = TCPSocket.open("service.server.com","2316")
begin
start = Time.now
socket.print(xml) # Send request
puts "just printed the xml into socket #{Time.now - start}"
rescue Errno::ECONNRESET
puts "looks like there is an issue!!!"
socket = TCPSocket.open("service.server.com","2316")
socket.print(xml) # Send request
end
response=""
while (line =socket.recv(1024))
response += line
break unless line.grep(/<\/bcap>/).empty?
end
puts "SEND_RECEIVE COMPLETED. IN #{Time.now - start}"
# socket.close
response
end
end
end
end
謝謝!
這是什麼,你實際上試圖衡量,爲什麼? – 2009-09-01 14:56:40