views:

680

answers:

4
+3  Q: 

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?

+5  A: 

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.

Ben S
I acepted your Answer because made me check the expiration times. TTY
Gabriel Sosa
On the other hand, the DNS calls "expiry" a completely different thing. I believe Ben S meant "TTL", not "expiry".
bortzmeyer
I am setting up a similar structure. What did you set the TTL to?
Declan Shanaghy
+3  A: 

One thing to be aware of with CNAMES is that if the target of the CNAME is not cached, it will require another lookup, as Ben S said.

HOWEVER, if the target of the CNAME is yet another CNAME, then it will require YET ANOTHER lookup, ad nauseum.

I would suggest against pointing your CNAME to another CNAME.

Moose
+4  A: 

The impact of using CNAME is in most cases very low. The DNS response format allows the server to put some additional data in the message, and in many situation when you look up CNAME record, the server will add the corresponding A record in the additional data section, so no more look ups are required.

Michał Piaskowski
Yes, that's usually the case.
Gleb
but incorrect...
Alnitak
Yes, incorrect for a long time. RFC 2181, in july 1997, advised against doing that, for security reasons (section 5.4.1, "Ranking data").
bortzmeyer
Using the dig command with a lookup for, say, www.toyota.com, I get an answer section with four entries: two CNAMEs and two A records. Are you telling me that these four entries didn't all come in the same response packet?
Barry Brown
+3  A: 

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.

Alnitak
+1, thanks for correcting me.
Michał Piaskowski