如何降低 Amazon Cloudfront 成本? [英] How to reduce Amazon Cloudfront costs?

查看:46
本文介绍了如何降低 Amazon Cloudfront 成本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,最近几天流量激增.我将 Wordpress 与 W3 Total Cache 插件和 Amazon Cloudfront 结合使用,以从站点传送图像和文件.

I have a site that has exploded in traffic the last few days. I'm using Wordpress with W3 Total Cache plugin and Amazon Cloudfront to deliver the images and files from the site.

问题是 Cloudfront 的成本相当高,就在过去一周,接近 500 美元.有没有办法降低成本?也许使用其他 CDN 服务?

The problem is that the cost of Cloudfront is quite huge, near $500 just the past week. Is there a way to reduce the costs? Maybe using another CDN service?

我是 CDN 的新手,所以我可能没有很好地实现这一点.我已经创建了一个 cloudfront 发行版并在 W3 Total Cache Plugin 上配置了它.但是,我没有使用 S3,也不知道我是否应该或如何使用.老实说,我不太确定 Cloudfront 和 S3 之间有什么区别.

I'm new to CDN, so I might not be implementing this well. I've created a cloudfront distribution and configured it on W3 Total Cache Plugin. However, I'm not using S3 and don't know if I should or how. To be honest, I'm not quite sure what's the difference between Cloudfront and S3.

有人可以在这里给我一些提示吗?

Can anyone give me some hints here?

推荐答案

我不太确定 Cloudfront 和 S3 之间有什么区别.

I'm not quite sure what's the difference between Cloudfront and S3.

这很简单.S3 是一个数据存储.它存储文件,并且具有超级可扩展性(可以轻松扩展到一次为 1000 人提供服务.)问题在于它是集中式的(即从世界上的一个地方提供服务.)

That's easy. S3 is a data store. It stores files, and is super-scalable (easily scaling to serving 1000's of people at once.) The problem is that it's centralized (i.e. served from one place in the world.)

CloudFront 是一个 CDN.它将您的文件缓存在世界各地,以便更快地提供服务.如果你眯着眼睛,他们似乎在存储"你的文件,但缓存随时可能丢失(或者如果他们启动了一个新节点),所以你仍然需要原始文件.

CloudFront is a CDN. It caches your files all over the world so they can be served faster. If you squint, it looks like they are 'storing' your files, but the cache can be lost at any time (or if they boot up a new node), so you still need the files at your origin.

如果每个文件的点击次数太少,CF 实际上可能会伤害您.例如,在东京,CF 可能有 20 个节点.在所有 20 个 CF 节点缓存您的文件之前,可能需要对文件进行 100 个请求(请求是随机分布的).在这 100 个请求中,其中 20 个将命中空缓存并在获取文件时看到额外的 200 毫秒延迟.他们通常会缓存您的文件很长时间.

CF may actually hurt you if you have too few hits per file. For example, in Tokyo, CF may have 20 nodes. It may take 100 requests to a file before all 20 CF nodes have cached your file (requests are randomly distributed). Of those 100 requets, 20 of them will hit an empty cache and see an additional 200ms latency as it fetches the file. They generally cache your file for a long time.

我没有使用 S3,不知道我是否应该使用

I'm not using S3 and don't know if I should

可能不是.如果您希望您的网站在媒体中大量增长,请考虑使用 S3.(即大量使用照片上传.)

Probably not. Consider using S3 if you expect your site to massively grow in media. (i.e. lots of use photo uploads.)

有没有办法降低成本?也许使用其他 CDN 服务?

Is there a way to reduce the costs? Maybe using another CDN service?

这完全取决于您的网站.一些想法:

That entirely depends on your site. Some ideas:

1) 确保您提供的是适当的标头.并确保您的过期时间不会太短(最好为数天、数周或数月).

1) Make sure you are serving the appropriate headers. And make sure your expires time isn't too short (should be days or weeks, or months, ideally).

最佳实践"是永远不要使页面过期,除非您的索引页应该每 X 分钟、几小时或几天过期(取决于您希望它更新的速度.)确保每个页面/图像都说明它的时长可以缓存.

The "best practice" is to never expire pages, except maybe your index page which should expire every X minutes or hours or days (depending on how fast you want it updated.) Make sure every page/image says how long it can be cached.

2) 如上所述,只有当每个页面被请求每个缓存时间超过 100 次时,CF 才有用.如果您有数百万个页面,每个页面都请求了几次,那么 CF 可能没有用.

2) As stated above, CF is only useful if each page is requested > 100's of times per cache time. If you have millions of pages, each requested a few times, CF may not be useful.

3) 来自亚洲的请求比来自美国的请求贵得多.如果您在东京更受欢迎,请考虑在东京启动您的服务器.

3) Requests from Asia are much more expensive than the from the US. Consider launching your server in Toyko if you're more popular there.

4) 查看您的 Web 服务器日志,了解 CF 请求您的每个资产的频率.如果它比您预期的更频繁,则您的缓存标头设置错误.如果您设置缓存数月",您应该每天只看到少量请求(因为它们启动新服务器等),以及发布新文件时的几百个请求(即每个 CF 边缘节点一个请求).

4) Look at your web server log and see how often CF is requesting each of your assets. If it's more often than you expect, your cache headers are setup wrong. If you setup "cache this for months", you should only see a handful of requests per day (as they boot new servers, etc), and a few hundred requests when you publish a new file (i.e. one request per CF edge node).

根据您的设置,其他 CDN 可能更便宜.根据您的服务器,其他设置可能更便宜.(即,如果您提供大量小文件,最好在 EC2 上进行自己的缓存.)

Depending on your setup, other CDNs may be cheaper. And depending on your server, other setups may be less expensive. (i.e. if you serve lots of small files, you might be better off doing your own caching on EC2.)

这篇关于如何降低 Amazon Cloudfront 成本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆