【发布时间】:2009-09-01 06:50:04
【问题描述】:
我有一段简单的代码写入套接字,然后从服务器读取响应。服务器非常快(每次在 5 毫秒内响应)。然而,虽然写入套接字很快——从套接字读取响应总是慢得多。有什么线索吗?
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
谢谢!
【问题讨论】:
-
您实际尝试测量的是什么以及为什么?
标签: ruby-on-rails optimization tcp network-programming