Jump to content
Maintenance ×
×
×
  • Create New...

Load balancing with Nginx


Recommended Posts

  • Premium
Posted (edited)

So I was checking out Aeldra's Discord and apparently their patcher was slow as a snail, which reminded me of the opening of WoM3 back in the day.

The typical OVH dedicated server has a bandwidth of 100 Mbps upstream if I remember well, although you can buy more bandwidth (which costs as much as the server itself) and some come with 1 Gbps. Anyway that's a gigaBIT per second which makes around 150 megabytes per second. Pretty good but not enough for a big opening thing where you have hundreds of users expecting to download at 4 Mbps each.

NGINX (the one you pay for) includes some load balancing mechanism but we can emulate it with the free one. We are in fact sorta randomly distributing people among a number of servers.

So here is how you can just throw money at the problem (if you have this problem you're probably gonna get rich anyway) and just rent more servers or just use a bunch of VPS you have lying around. I'm not going to make lengthy explanations here if u need help you know where to find me and my paypal.

So we have our url let's say patch.wom2.org pointing to our main webserver, Here's where the magic happens (http context)

split_clients "${remote_addr}" $destination {
       50%   alpha.patch.wom2.org:8080;
       30%   bravo.patch.wom2.org:8080;
       20%   charlie.patch.wom2.org:8080;
 }

Here we have three subdomains pointing at three different servers (any place where u can install nginx will do, you can measure speed at the endpoint with nethogs for example to see which is slower and reduce the percent of requests that are sent there). The OG web server can serve files too (here it's alpha). Do not use Linux if you can avoid it. And do NOT use Apache. FreeBSD is the king when it comes to streaming sry Linux fanboys.

The three servers must of course have identical copies of your files (use rsync when updating patches) and the same nginx configuration. Here's the config for the OG server which redirects the user to the previously chosen subdomain when downloading from the pack directory (server context obviously)

server {
        listen 51.84.214.58:80;
        server_name patch.wom2.org;

        root  /home/www/patch.wom2.org;


        location /1.1.1.1/ {
                 log_not_found on;
                 return 302 http://$destination$request_uri;
        }

}

Finally here's the config of one of our load balancing server, which in its root folder contains the contents of 1.1.1.1, in fact alpha.patch and patch are in the same folder.

 server {
        listen  51.84.214.58:8080 sndbuf=32k;
        server_name alpha.patch.wom2.org;
        root  /home/www/patch.wom2.org;

        location / {
                 limit_rate 4096k;
                 if_modified_since off;
                 expires epoch;
         }
}

As you can see I limited speed to 4 Mbps to avoid people with a big pipe taking all the bandwidth.

Remember no Cloudflare here, CF is not for file serving.

Edited by Shogun
  • Metin2 Dev 8
  • Love 3
  • Love 2
  • Good 3

Currently working on my FreeBSD blog:

FreeBSD is Fun, practical tutorials and articles

⚠️                Are you under attack?               ⚠️

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


  • Activity

    1. 1

      Metin2 TitleBar Move Frezze

    2. 1

      Metin2 TitleBar Move Frezze

    3. 0

      Navicat "Trial" Reset

    4. 13

      Item ToolTip Width Fix

    5. 0

      Guild icon wrong position

    6. 3

      Monster health

    7. 4

      Luffy Pet

    8. 38

      Core X → Top Metin2 & Metin2 Download → Changelogs

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.