We use the rest-client gem in Ruby to automatically test our REST API. However, I noticed that for each individual query, it also does a DNS lookup for the hostname. In a local environment, if "localhost" is used, tests run quickly, but if the correct hostname is used, they take 2.5 times, making a huge amount of DNS queries.
I believe that this problem is not related, in particular, to the rest-client client, but the Ruby core network. I tried to require "resolv" and "resolv-replace", but they did not help. 'dig' reports that the DNS query has a TTL of 1 hour.
Is there a way to make Ruby DNS cache queries? I can change the code to explicitly use the IP address, but this is the wrong place to fix the problem.
I am running Ubuntu 12.04 and Ruby 1.9.3.
Sampo source
share