Discourse の CDN ヒット/キャッシュ率を最大化する方法は?

みなさん、こんにちは。

以下の CDN 設定を行っています:

  • JS 用のプルゾーン
  • ロゴやホームページのグラフィック(頻繁にアクセスされるもの)用のプルゾーン
  • S3 アセット(Digital Ocean Spaces 上)用のプルゾーン

私は BunnyCDN を利用しています。当フォーラムのトラフィックは、北米が約 85%、英国/フランスが 5%、東南アジアが 10% です。

最初の 2 つのプルゾーンについては、頻繁にアクセスされるファイルであるため、レイテンシを低く抑えつつキャッシュヒット率(それぞれ 92%、99.8%)を比較的高く保つために、BunnyCDN が提供する世界中の 34 のエッジサーバーをすべて利用しています。理想的には JS のキャッシュ率をさらに高めたいのですが、課題として、トラフィックの少ないデータセンターでは、JS のアクセス頻度が非常に低い(月に数回程度)ため、キャッシュ率が低下してしまいます。

3 つ目の S3 アセット用のプルゾーンについては、ユーザー生成の S3 アセットはアクセス頻度が低い場合もあるため、多数の CDN エッジサーバーがキャッシュヒット率を低下させ、結果としてアクセス時間にも悪影響を及ぼすことを避けるため、北米とヨーロッパの 10 のエッジサーバーのみを利用しています。理想的には東南アジアにもエッジサーバーを配置したいのですが、BunnyCDN では利用するデータセンターを個別に選択することができません。BunnyCDN でのヒット/キャッシュ率は約 78% です。これは、例えば最適化された画像ではなくフルサイズのオリジナル画像にアクセスしたり、検索エンジンからのリファラルで頻繁にアクセスされない古い議論に飛んだりする場合に、パーセンテージが確実に低下するため、まずまずの数値だと考えています。以前は Cloudfront を利用していましたが、その際のヒット/キャッシュ率は約 55% でした。これは、Cloudfront が CDN として多くのエッジサーバー所在地を持っていることが原因か、あるいは当フォーラムのトラフィック規模が彼らにとって相対的に小さいことが要因かもしれません(コストの問題で Cloudfront から移行しました。当フォーラムは趣味のフォーラムであり、収益は最小限です)。

グループへの質問ですが、ヒット/キャッシュ率を高く保つための戦略や方法はありますか?皆さんはどのようなヒット/キャッシュ率を達成されていますか?

設定を調整してパーセンテージを向上させるための提案はありますか?エッジサーバーの所在地を個別に選択できる予算型の CDN はありますか?エッジルールを通じてそのような設定が可能でしょうか?もし可能であれば、キャッシュ率を高く保つために、トラフィックが集中している米国西海岸、米国東海岸、米国南部、英国、シンガポールの 5 か所だけを選択することもできます。

一つのアイデアとして、最適化されたアセットを S3 から、オリジナルのアセットを DO Spaces から配信するという方法もありますが、ソフトウェアのデフォルト機能ではこの分離は実現できません。

その他、ご意見やご提案があればお聞かせください。

I see, so your idea is to reduce the number of geographical points to increase hit rate? Because if you have “one” location aka everything on one server, that’s a perfect hit rate. :wink:

I would imagine this comes down to knowing your specific audience, and where they are – so metrics would need to be gathered first about which geographical CDN points are being hit, then consolidate to the most used?

If you want a higher hit rate then your choices are 1) fewer PoPs or 2) longer retention. The first choice is going to make the experience worse for some clients, the second is going to cost more money (if it’s even available).

This is exactly what you need to find out. What are your misses and where are they coming from?

The 5 PoPs closest to the majority of our traffic are averaging about low 80s% hit cache rate, whereas the other ones with more sporadic traffic- the lower the traffic is, the lower the hit rate, sometimes below 50%. That’s when I think consolidating the PoPs can bring the hit rate up so the CDN doesn’t always have to go back to the origin to fetch, which, speedwise is worse than just serving from the origin. Its a tradeoff between additional latency with PoPs located farther away, and reduced latency from increased cache rate at the PoP.

Longer retention is tougher to solve. That’s the lever that can bring up the hit rate for the high traffic PoPs, and I don’t necessarily have a solution for that, yet.

I am curious about others’ experience- Does high-70s% and low-80s% cache rate for user-uploaded assets feel low/ about right?

It really depends how often the Discourse instance is updated/deployed though. For us, we deploy a lot so that colors the data significantly.