Jump to content

Cloudflare R2 as a Patcher CDN


Recommended Posts

  • Management

Hello guys

So, now that Cloudflare R2 is in general availability, it's time to talk about it and how it can improve your metin2 servers, more specifically, the patcher.

Tradicional CDNs and block storage are expensive and charge a lot for egress bandwidth, but Clouldflare, as always, doesn't charge for bandwidth, at all. Here is the pricing: https://developers.cloudflare.com/r2/platform/pricing/

Storage: 10GB/month (free), then $0.015/GB-month
Class A Operations: 1 million requests/month, then $4.50/million requests
Class B Operations: 10 million requests/month, then $0.36/million requests

On Class A, the more important operations for the patcher are: PutObject, and, if you use cloudflare's dashboard, ListBuckets and ListObjects (or the equivalent AWS S3 commands on the script at the bottom).
On Class B, the more important operations for the patcher are: GetObject, and, again, if you use cloudflare's dashboard, UsageSummary (or the equivalent AWS S3 commands on the script at the bottom).

I made a small PowerShell script to download a lot of files from the storage:

For ($i = 0; $i -lt 1000; $i++) {
    $ProgressPreference = 'SilentlyContinue'
    $combinedVariable = "C:\Users\Karbust\Desktop\test\metin2_$i.exe"
    $Response = Invoke-Webrequest -Uri https://<my custom domain>/metin2.exe -OutFile $combinedVariable
}

This was the usage metrics:

ouL2AGY.png

They barely change, the 20 class B requests are basically all from UsageSummary (refreshing the page), and the Class A are ListBuckets and ListObjects.

Why is that? Because by using a custom domain it will cache the requests. This is good to prevent GetObject flooding requests. Cloudflare, on free accounts (until Enterprise), can cache up to 512MB per file.

Instead of relying on the default cache rules, you can change them, to something like this:

7ekgRbH.png

When you make an update, you need to purge the cache, either purge it all or just the files you want.

 

Tutorial

Go to your cloudflare dashboard and access the R2 tab:

V9t2yPN.png

There you will be asked to enable it. You will need to have a payment setup in the account.

Then, after that's done, create a bucket, you can call it whatever you want:

8H0b1kN.png

Then go you Settings and scroll down to the Domain Access section and add one:

The domain must be in the same cloudflare account as the bucket.

KU4iZZc.png

LVhGpZX.png

Now you can use that domain to access the files in the bucket. If you change the cache settings, you must do it on the domain you added.

When you upload a file (or a folder), it will be something like this:

QmtSW4N.png

To access that file, you do https://<domain>/metin2.exe, like this: https://r2-tests.karbust.com/metin2.exe

If you have folders, just do https://<domain>/folder_name/file_name.

 

If you use my patcher:

You just need to edit this variables:

export const patchlistUrl = 'https://<domain>/files.json'
export const patchlistFolder = 'https://<domain>/files/'
export const patchSliderUrl = 'https://<domain>/slider.json'
export const patchSliderImages = 'https://<domain>/slider/'

 

Since you can't upload more than 100 files at the same time with the dashboard, I made a script in typescript to help with that:

This is the hidden content, please
 or 
This is the hidden content, please

The instructions are in the repository, but I will say this, add the files inside the uploads folder, then run the script. If try to upload a file which already exists and the MD5 hash matches, it will not be uploaded and will return a http error code 412.

 

The end

 

I decided to make this tutorial since many servers use either one or multiple VPS to have more bandwidth, and downloads can become slow if many players are downloading at the same time, and because Cloudflare doesn't charge for used bandwidth, and has a generous free tier can is more than enough for almost all server owners.

 

Enjoy

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 34
  • Good 5
  • Love 4
  • Love 19

raw

raw

Link to comment
Share on other sites

  • Premium

Great tutorial. However I'm skeptical about a real life scenario with a free CDN. Let's remember Cloudflare released not long ago their free Wireguard based VPN. Sounds great doesn't it? Except it's hardly usable at all because many sites are blocking it straight away.

Back in the day I tested paid CDN -Rackspace, MaxCDN - for file distribution and it was... pretty bad. One has to be careful with any sort of cache as an outdated cache will mean the client downloading files over and over every time. Moreover when we consider most of players would be located in a geographically small area, the need for a CDN is perhaps questionable.

In any case I'm looking forward to people reporting their experiences with this, if it actually works it could be very valuable for peak traffic scenarios.

  • Metin2 Dev 3
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.