CNAME 慢吗?

发布于 2024-07-17 05:53:40 字数 197 浏览 4 评论 0原文

我将 CNAME 与 S3/CloudFront 一起使用来提供一些静态文件,例如 js、css、图像等。

我这样做是为了使存储桶的 URL 更漂亮,因为我认为最好将所有内容都定位到我的网站,以防万一将来我想移动这些文件,更改应该是透明的。

今天阅读博客时,我看到有些人认为 CNAME 对速度有害。

那么,对此有何思考呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

稀香 2024-07-24 05:53:40

CNAMES 使用 DNS 查找添加了另一个间接级别,因此会产生一些损失。 然而,一旦通过 DNS 查找到 IP,它就应该保持缓存状态,并且该客户端不会再受到惩罚。

确保在 DNS 条目中正确设置到期时间,并且您不应该看到任何明显的延迟。

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.

单身情人 2024-07-24 05:53:40

根据其他答案,使用 CNAME 只会导致非常小的额外 DNS 解析延迟,并且仅当结果尚未位于递归 DNS 服务器的缓存中时。

请注意,DNS 客户端通常不会明确要求 CNAME 记录。 通常,他们会询问他们实际想要的任何记录类型 - 对于 Web 浏览器,将是 AAAAA 记录。

上游服务器的工作就是识别所查询的域名中有CNAME条目,然后查找并返回目标结果。 在这种情况下,CNAME 记录和所需的结果都会在 DNS 响应的应答部分中返回(而不是在其他人应答的附加部分中)。

为了获得最佳性能,最好将 CNAME 的目标托管在与包含 CNAME 的域名相同的权威 DNS 服务器上,以便无需进一步的 DNS 请求即可完成 CNAME 解析。

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.

水波映月 2024-07-24 05:53:40

在大多数情况下,使用 CNAME 的影响非常小。
DNS响应格式允许服务器在消息中放置一些附加数据,并且在很多情况下当您查找CNAME记录时,服务器会在附加数据部分添加相应的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.

原来是傀儡 2024-07-24 05:53:40

使用 CNAMES 时需要注意的一件事是,如果 CNAME 的目标未缓存,则将需要另一次查找,正如 Ben S 所说。

但是,如果 CNAME 的目标是另一个 CNAME,那么它将需要另一次查找,令人作呕。

我建议不要将您的 CNAME 指向另一个 CNAME。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文