I'm running fairly simple PHP websites, on Ubuntu, with AWS EC2 instances, which use *.rds.amazonaws.com
domain names to connect to their respective RDS instances.
This introduces 2 issues:
When the DNS cache expires, every 5 seconds, the next request adds a minimum of 12ms to my websites processing time, which isn't ideal (I try to keep within a 100ms budget).
Occasionally this resolution step fails, so rather than showing an error page to my customers, my script will sleep for ~500ms, and try again.
I'm wondering if there is something, like a local caching DNS resolver, that could handle these issues more gracefully?
Perhaps it could cache the IP address for 3 seconds, then automatically try to refresh that cache, knowing that it has 2 seconds left. And if it does continue to fail, still provide the old/stale response, as that's better than no response.
Or, it could offer up the cached response immediately, even if it has expired (it's probably still correct); and if did just provide an expired response, run an update, just incase the RDS instance has just moved.
Or, could I bodge it, with a script that checks the DNS response in a loop (dig +short
), and when the IP address changes, update the /etc/hosts
file, using a hostname such as database-abc
.
As an aside, my sites tend to get about ~4 requests every 5 seconds during the day (so cache updates are fairly frequent), but there is low activity overnight.