TCP optimization over long distance connections

Posted on

TCP is the foundation of modern internet traffic. In this tutorial, I will show you how you can optimize your server for much faster data transfer on the TCP Protocol.

Before

To understand by how far did this improve our TCP connection, we need to have an idea of where we are at currently without the optimization.

For the tutorial today, we are using a VPS in Europe and to simulate the very worst network conditions, we chose a VPS in China.

For testing, we are using a network testing tool called iperf3. To install on Ubuntu / Debian, use:

apt-get install iperf3

We are going to do two tests – Single thread, and one with 8 thread.

Single thread

The command for this is:

# on server 1:
iperf3 -s
# on server 2:
iperf3 -c <server 1 address>

Then, the multithread test:

8 threaded test

This can be ran with:

#on server 1:
iperf3 -s
#on server 2:
iperf3 -P <number of threads in integer> -c <server 1 address>

 

The multithreaded test above was performed with 8 threads, hence:

iperf3 -P 8 -c <114.51.4.109>

 

(Of course 114.51.4.109 is not my real ip…)

Alright! Now we have a rough idea of where our baseline speeds are. Let’s get optimizing!

Method

For this, we will be using the English port of the Nekonekocloud optimization script, which you can find on my github here.

wget https://cdn.jsdelivr.net/gh/daycat/tcp-optimization@main/tcp.sh -O tcp.sh && chmod +x tcp.sh && bash tcp.sh

You should see this screen:

Script menu

Once you get to this step, take a look at your System info.

At the end of the line, in green, is your system kernel version. The 5.10.0 represents that your kernel version is 5.10.0 and the amd64 at the end means that you are using a VPS on a X86_64 platform (you don’t need to worry about this)

See also  How to Install Trojan on IPv6 VPS

If your number is smaller than 5.x : i.e 4.9.x, you need to run step 1, which updates your linux kernel version. Please note that running step 1 can result in data loss and if you have any important data, you should backup your data before you run it (works fine on Hax VPS KVM locations, but I cannot guarantee that it will work fine every time) . After, reboot and run step 2.

The rest of the script’s functionality isn’t necessary for the TCP optimization, but I’d recommend you run 4, Resource tuning.

Lets test again!

After

Single thread

Multithread

 

As you can see, there are some improvements after optimizing the TCP traffic.