apache CNAMES 慢吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/748584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Are CNAMES slow?
提问by Gabriel Sosa
I'm using CNAMEs together with S3/CloudFront to serve some static files like js, css, images, etc.
我正在使用 CNAME 和 S3/CloudFront 来提供一些静态文件,如 js、css、图像等。
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.
我这样做是为了使存储桶的 URL 漂亮,因为我认为最好将所有目标都定位到我的网站,以防将来我想移动这些文件,更改应该是透明的。
Today reading blogs I saw some think CNAMEs are evil for speed.
今天在阅读博客时,我看到一些人认为 CNAME 对速度不利。
So, what to think about it?
那么,该怎么想呢?
采纳答案by Ben S
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.
CNAMES 使用 DNS 查找添加了另一个间接级别,因此会产生一些惩罚。但是,一旦通过 DNS 查找 IP,它就应该保持缓存状态,并且该客户端不会再受到惩罚。
Make sure to set the expiry times correctly in your DNS entry and you shouldn't see any visible delay.
确保在您的 DNS 条目中正确设置到期时间,您不应该看到任何可见的延迟。
回答by Alnitak
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.
根据其他答案,使用 CNAME 只会导致非常小的额外 DNS 解析延迟,并且仅当结果不在递归 DNS 服务器的缓存中时。
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 Aor AAAArecord.
请注意,DNS 客户端通常不会明确要求 CNAME 记录。通常,他们会询问他们真正想要的任何记录类型 - 对于将是AorAAAA记录的 Web 浏览器。
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 Sectionof the DNS response (and not in the Additional Sectionas someone else answered).
上游服务器的工作是识别被查询的域名中有一个 CNAME 条目,然后查找并返回目标结果。在这种情况下,CNAME 记录和所需的结果都在DNS 响应的回答部分中返回(而不是在其他人回答的附加部分中)。
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.
为了获得最佳性能,最好将 CNAME 的目标托管在与包含 CNAME 的域名相同的权威 DNS 服务器上,以便无需进一步的 DNS 请求即可完成 CNAME 解析。
回答by Micha? Piaskowski
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.
在大多数情况下,使用 CNAME 的影响非常低。DNS响应格式允许服务器在报文中添加一些额外的数据,很多情况下,当你查找CNAME记录时,服务器会在附加数据部分添加相应的A记录,所以不需要再查找了。
回答by Moose
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.
正如 Ben S 所说,使用 CNAMES 需要注意的一件事是,如果 CNAME 的目标没有被缓存,它将需要再次查找。
HOWEVER, if the target of the CNAME is yet another CNAME, then it will require YET ANOTHER lookup, ad nauseum.
然而,如果 CNAME 的目标是另一个 CNAME,那么它将需要另一次查找,令人作呕。
I would suggest against pointing your CNAME to another CNAME.
我建议不要将您的 CNAME 指向另一个 CNAME。

