CAKE w/ Adaptive Bandwidth [August 2022 to March 2024]

Also maybe these aren't so good because the point is that these servers will get saturated with data and ping times might thereby increase? Whereas DNS servers should never get saturated?

Do you suppose for my own VPN use though I should setup a nightly script that cycles to the top recommended one? Hitherto I have just manually cycled from time to time. What causes me to manually change is that I notice upload bandwidth takes a hit (presumably owing to server loading?). If I had my own dedicated VPS server would these issues go away? I've imagined that NordVPN will offer better performance than a cheap VPS, and that if I need a good VPS I'd need to pay a lot more?

All servers can get loaded, and no server owes us timely ICMP responses (or ICMP responses at all), so we can/should try to find suitable sets as best as we can, but keep in mind the remote side can always shut us off if they consider our use as abuse (you current default change to use more reflectors at a lower individual rate should help in that regard).

Mavbe first conform that your observation correlates with heightened load on your current server?

Likely yes, but that depends on the type of server you get (many are parts of a shared server and then the details start to matter) and how well the data center / VPS-provider is connected to your ISP. But it should be possible to find a VPS service that should work for you.

I have not looked into this, but VPS instances with sufficient traffic volume should start in the range of ~5EUR/month including 20TB (this is an example price for hetzner, which does not offer UK locations, but I assume that prices should be similar). Fun fact, if you take an IPv6-only instance you can save 69cent/month. I think one big selling point for VPN providers is ease-of-use (and ability to select one's "virtual" location), so not sure whether absolute performance for a single link is that much better than with a dedicated VPS.

@moeller0 and @patrakov I have committed the now tested ping prefix string code to main and have deleted the old 'testing' branch.

Now I have made a new 'testing' branch and committed the code to handle multiple instances of cake-autorate, the main commit being:

Would either of you be able to test to see if this works? Now the launcher 'cake-autorate_launcher.sh' is executed, and it will check for the existence of config files and launch one instance of cake-autorate per config file, the config file path sent as an argument to cake-autorate.sh, and this is then used by cake-autorate.sh to derive the run directory for that instance.

Here is the launcher:

#!/bin/bash

cake_instances=(/root/cake-autorate/cake-autorate_config*sh)

trap kill_cake_instances INT TERM EXIT

kill_cake_instances()
{
	trap - INT TERM EXIT
	echo "Killing all instances of cake now."
	kill ${cake_instance_pids[@]}
	wait
	exit
}

cake_instance_pids=()

for cake_instance in "${cake_instances[@]}"
do
	/root/cake-autorate/cake-autorate.sh $cake_instance&
	cake_instance_pids+=($!)
done

sleep inf&
cake_instance_pids+=($!)
wait

And here is the main portion of code inside cake-autorate.sh that handles the new behaviour:

# cake-autorate first argument is config file path
if [[ ! -z $1 ]]; then
	config_path=$1
else
	config_path=/root/cake-autorate/cake-autorate_config.sh
fi

if [[ "/root/cake-autorate/cake-autorate_config.sh" =~ cake-autorate_config\.(.*)\.sh ]]; then
	run_path=/var/run/cake-autorate/${BASH_REMATCH[1]}
else
	run_path=/var/run/cake-autorate
fi

[[ ! -f "$config_path" ]] && { log_msg_bypass_fifo "ERROR" "No config file found. Exiting now."; exit; }
. $config_path
[[ $config_file_check != "cake-autorate" ]] && { log_msg_bypass_fifo "ERROR" "Config file error. Please check config file entries."; exit; }
[[ ! -d $log_file_path ]] && { broken_log_file_path=$log_file_path; log_file_path=/var/log log_msg_bypass_fifo "ERROR" "Log file path: '$broken_log_file_path' does not exist. Exiting now."; exit; }

# $run_path/ is used to store temporary files
# it should not exist on startup so if it does exit, else create the directory
if [[ -d $run_path ]]; then
        log_msg_bypass_fifo "ERROR" "$run_path already exists. Is another instance running? Exiting script."
        trap - INT TERM EXIT
        exit
else
        mkdir $run_path
fi

OK, let me try it.

Two secs - need to fix log path..

OK, it's ready now as fixed with this commit:

Now the new log directory is /var/log/cake-autorate/

But if there are multiple instances it will be:

/var/log/cake-autorate/X/

to mirror the /var/run/cake-autorate/X/ behaviour as taken from cake-autorate_config.X.sh as suggested by @moeller0.

So where cake-autorate it to be run with multiple instances you just setup one cake-autorate_config.X.sh for each instance, e.g. X=LTE, X=Starlink, etc.

EDIT: sorry, I realise I also had to change the log file path in config and slightly edit the cake-autorate.sh log file path handling to create new directory. Fixed now.

The multiple instance handling created a fair few challenges. But I think it's pretty much done now.

Does not work.

I don't see any place that creates the /var/log/cake-autorate directory, and the regular expression logic does not seem to work - or I am misunderstanding.

if [[ "/root/cake-autorate/cake-autorate_config.sh" =~ cake-autorate_config\.(.*)\.sh ]]; then
	run_path=/var/run/cake-autorate/${BASH_REMATCH[1]}
	log_file_path=/var/log/cake-autorate/${BASH_REMATCH[1]}
else
	run_path=/var/run/cake-autorate
	log_file_path=/var/log/cake-autorate
fi

You likely meant the first argument to the script, and not the literal "/root/cake-autorate/cake-autorate_config.sh".

1 Like

Yes sorry that was from testing. Both fixes present here:

Really appreciate your testing and help since this wasn't easy.

Still doesn't work:

/root/cake-autorate/cake-autorate.sh: line 774: /var/run/cake-autorate/lte/sleep_fifo: No such file or directory
/root/cake-autorate/cake-autorate.sh: line 725: /var/run/cake-autorate/lte/dl_achieved_rate_kbps: No such file or directory
/root/cake-autorate/cake-autorate.sh: line 272: /var/run/cake-autorate/lte/dl_achieved_rate_kbps: No such file or directory
/root/cake-autorate/cake-autorate.sh: line 273: /var/run/cake-autorate/lte/ul_achieved_rate_kbps: No such file or directory/root/cak

I.e. nobody creates the correct subdirectory of /var/run.

Isn't that handled by:

# $run_path/ is used to store temporary files
# it should not exist on startup so if it does exit, else create the directory
if [[ -d $run_path ]]; then
        log_msg_bypass_fifo "ERROR" "$run_path already exists. Is another instance running? Exiting script."
        trap - INT TERM EXIT
        exit
else
        mkdir $run_path
fi

Maybe try
mkdir -p $run_path

1 Like

Yes @patrakov can you test with that fix?

mkdir without flags can only create one level of missing directries, and we need two (cake-autorate/lte). Therefore, mkdir -p (and it indeed works).

EDIT: no, the log is at the wrong place. Possibly because $1 is not what you mean? EDIT2: my bad, I was setting it explicitly in configs.

It's a good practice to save the script argument as variables at the beginning, and never reference them as $1, $2, ... again.

1 Like

So it works? @moeller0 see any other issues? Does my log file directory structure make sense?

@patrakov yes new log file has this commented out with explanation.

Both: in theory now user could create a problem by setting two instances with log file same path. Is that something we need to handle? Setting log file in config is meant as an override e.g. to cloud mount or usb.

@patrakov does it all clean up OK on exit?

I ran it with the following relevant changes:

--- a/cake-autorate.sh
+++ b/cake-autorate.sh
@@ -821,7 +821,7 @@ else
        log_file_path=/var/log/cake-autorate
 fi
 
-[[ ! -d $log_file_path ]] && mkdir $log_file_path
+[[ ! -d $log_file_path ]] && mkdir -p $log_file_path
 
 [[ ! -f "$config_path" ]] && { log_msg_bypass_fifo "ERROR" "No config file found. Exiting now."; exit; }
 . $config_path
@@ -835,7 +835,7 @@ if [[ -d $run_path ]]; then
         trap - INT TERM EXIT
         exit
 else
-        mkdir $run_path
+        mkdir -p $run_path
 fi
 
 mkfifo $run_path/sleep_fifo

It does clean up everything in /var/run/cake-autorate correctly on exit. Regarding the mixed up log file - user fault, no need to detect and fix.

1 Like

Just put in a # DANGER!!!! or similar label into the config_file.... if this is mainly meant as an over-ride.

Skip that, just let users configure n override for the log file base path, and just append ${InstanceID}/cake-autorate.log automatically for all ${InstanceID}s...

or maybe just do path_override

${path_override}/cake-autorate.${InstanceID}.log

1 Like

Sweet! Thanks guys.

1 Like

@patrakov and @moeller0, does this look OK to you:

The code regarding $log_file_path_override does not look OK. Namely, it is first checked for "not being a directory", and only then for "not being an empty string". This doesn't make sense.

Also for the case of it not being a directory - it is inconsistent that we make other directories ourselves, but blame the user here.

My opinion: drop the $log_file_path_override code. It is complicated and unnecessary.

[[ ! -d $log_file_path_override ]] && { broken_log_file_path_override=$log_file_path_override; log_file_path=/var/log log_msg_bypass_fifo "ERROR" "Log file path override: '$broken_log_file_path_override' does not exist. Exiting now."; exit; }

if [[ ! -z "$log_file_path_override" ]]; then 
	if [[ ! -z "instance_id ]]; then
		log_file_path=$log_file_path_override/$instance_id
		mkdir $log_file_path
	else
		log_file_path=$log_file_path_override
	fi
fi

My thinking is that the override path should already exist. So that's the first check. But then it depends whether the instance id is set or not what the path should look like. If there is an instance id we create the relevant directory.

But I agree the directory check should be below the empty check.

I take @moeller0's point on GitHub that having subdirectories is perhaps a bit messy?

No, it is not messy. Just use mkdir -p consistently, so that it can deal with multiple levels of missing directories. Any mkdir without the -p switch` is a bug, unless the directory is used as a lock (and we don't do it).