Net::HTTP请求连接太慢?

Net::HTTP request connection too slow?

我从 ovh-rest gem:

中提取了以下代码
method = :get
@api_url = "https://api.ovh.com/1.0"
@api_key, @api_secret, @consumer_key = "123456789", "abcdef", "ghijkl"
endpoint = "/ip/123.456.678/"
url = @api_url + endpoint
uri = URI.parse(url)
body = nil
ts = Time.now.to_i.to_s
sig = "$" + Digest::SHA1.hexdigest("#{@api_secret}+#{@consumer_key}+#{method.upcase}+#{url}+#{body}+#{ts}")
request_uri = uri.path
request_uri += '?' + uri.query if uri.query
request = Net::HTTP.const_get(method.capitalize).new(request_uri)
request["X-Ovh-Application"] = @api_key
request["X-Ovh-Consumer"] = @consumer_key
request["X-Ovh-Timestamp"] = ts
request["X-Ovh-Signature"] = sig
request["Content-type"] = "application/json"
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.request(request)
JSON.parse(response.body)

如果我一步一步地做所有事情,我会出现以下错误:

{
  "errorCode": "QUERY_TIME_OUT",
  "httpCode": "400 Bad Request",
  "message": "Query out of time"
} 

但是如果我在执行 response = http.request(request) 之前等待几秒钟(持续时间可变),我的请求就成功了:

{
  "organisationId": "nil",
  "country": "myCountry",
  "routedTo": {
    "serviceName": "somename"
  },
  "ip": "123.456.678/32",
  "canBeTerminated": true,
  "type": "failover",
  "description": "nil"
}

我不知道问题是出在我的服务器上(ruby 处理速度过快以便快速响应)还是出在其他地方..

重要提示:

这段代码工作得很好,但几天前..停止工作。

这已通过日期重新同步解决。由于所有服务器的时间都相同,所以它很有魅力。