Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are CNAMES slow?

I'm using CNAMEs together with S3/CloudFront to serve some static files like js, css, images, etc.

I do it to make the bucket's URL pretty and because I think is better have all targeting to my site and in case in some future I want to move those files the change should be transparent.

Today reading blogs I saw some think CNAMEs are evil for speed.

So, what to think about it?

like image 322
Gabriel Sosa Avatar asked Apr 14 '09 17:04

Gabriel Sosa


People also ask

How much time does CNAME take?

CNAME record changes can take up to 72 hours to go into effect, but typically they happen much sooner. Return to the setup or password reset panel in your other browser window and follow the next steps.

Can you have too many CNAME records?

You cannot. A CNAME makes one record another name for another. If a record could have CNAMES for two names, it wouldn't be another name for either of them, but a name for something entirely new, making a CNAME entry inappropriate.

What does a CNAME do?

A Canonical Name or CNAME record is a type of DNS record that maps an alias name to a true or canonical domain name. CNAME records are typically used to map a subdomain such as www or mail to the domain hosting that subdomain's content.

Are Cnames unique?

It also warns you that CNAMEs must be unique to other records. The DNS A record is specified by RFC 1035.


2 Answers

CNAMES add another level of indirection using the DNS lookup, so some penalty will be incurred. However, once the IP has been looked up through DNS, it should remain cached and the penalty shouldn't occur anymore for that client.

Make sure to set the expiry times correctly in your DNS entry and you shouldn't see any visible delay.

like image 172
Ben S Avatar answered Nov 07 '22 15:11

Ben S


As per other answers, using a CNAME should only cause very minimal additional DNS resolution delay, and only if the result is not already in the recursive DNS server's cache.

Note that DNS clients don't routinely ask explicitly for CNAME records. Typically they'll ask for whatever record type they actually want - for a web browser that would be an A or AAAA record.

It's the job of the upstream servers to recognise that the queried domain name has a CNAME entry in it, and then look up and return the target result. In this case both the CNAME record and the required result are returned in the Answer Section of the DNS response (and not in the Additional Section as someone else answered).

For optimum performance it's best that the target of the CNAME be hosted on the same authoritative DNS server as the domain name that contains the CNAME so that the CNAME resolution can be done without further DNS requests.

like image 36
Alnitak Avatar answered Nov 07 '22 16:11

Alnitak