Distribute CPU share among all the CPUs (#150)

This commit is contained in:
Chalith Desaman
2022-07-04 17:23:57 +05:30
committed by GitHub
parent 85b9cb7b66
commit f53b8a6584
6 changed files with 39 additions and 23 deletions

View File

@@ -35,9 +35,12 @@ if [ "$max_swap_kbytes" != "" ] && [ ! ${#max_swap_kbytes} -eq 0 ] && [ "$max_sw
! instance_swap_kbytes=$(expr $instance_mem_kbytes + $max_swap_kbytes / $max_instance_count) && echo "Max swap memory limit calculation error." && exit 1
fi
instance_cpu_us=0
instance_cpu_quota=0
# In the Sashimono configuration, CPU time is 1000000us Sashimono is given max_cpu_us out of it.
# Instance allocation is multiplied by number of cores to determined the number of cores per instance and devided by 10 since cfs_period_us is set to 100000us
if [ "$max_cpu_us" != "" ] && [ ! ${#max_cpu_us} -eq 0 ] && [ "$max_cpu_us" -gt 0 ]; then
! instance_cpu_us=$(expr $max_cpu_us / $max_instance_count) && echo "Max cpu limit calculation error." && exit 1
cores=$(grep -c ^processor /proc/cpuinfo)
! instance_cpu_quota=$(expr $(expr $cores \* $max_cpu_us) / $(expr $max_instance_count \* 10)) && echo "Max cpu limit calculation error." && exit 1
fi
prefix="sashi"
@@ -53,18 +56,18 @@ done
has_err=0
for user in "${validusers[@]}"; do
# Setup user cgroup.
if [ $instance_cpu_us -gt 0 ] &&
if [ $instance_cpu_quota -gt 0 ] &&
! (cgcreate -g cpu:$user$cgroupsuffix &&
echo "1000000" > /sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us &&
echo "$instance_cpu_us" > /sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us); then
echo "100000" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us &&
echo "$instance_cpu_quota" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us); then
echo "CPU cgroup creation for $user failed."
has_err=1
fi
if [ $instance_mem_kbytes -gt 0 ] &&
! (cgcreate -g memory:$user$cgroupsuffix &&
echo "${instance_mem_kbytes}K" > /sys/fs/cgroup/memory/$user$cgroupsuffix/memory.limit_in_bytes &&
echo "${instance_swap_kbytes}K" > /sys/fs/cgroup/memory/$user$cgroupsuffix/memory.memsw.limit_in_bytes); then
echo "${instance_mem_kbytes}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.limit_in_bytes &&
echo "${instance_swap_kbytes}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.memsw.limit_in_bytes); then
echo "Memory cgroup creation for $user failed."
has_err=1
fi

View File

@@ -209,10 +209,14 @@ WantedBy=default.target" >"$user_dir"/.config/systemd/user/ledger_fs.service
sudo -u "$user" XDG_RUNTIME_DIR="$user_runtime_dir" systemctl --user daemon-reload
# In the Sashimono configuration, CPU time is 1000000us Sashimono is given max_cpu_us out of it.
# Instance allocation is multiplied by number of cores to determined the number of cores per instance and devided by 10 since cfs_period_us is set to 100000us
cores=$(grep -c ^processor /proc/cpuinfo)
cpu_quota=$(expr $(expr $cores \* $cpu) / 10)
echo "Setting up user cgroup resources."
! (cgcreate -g cpu:$user$cgroupsuffix &&
echo "1000000" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us &&
echo "$cpu" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us) && rollback "CGROUP_CPU_CREAT"
echo "100000" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_period_us &&
echo "$cpu_quota" >/sys/fs/cgroup/cpu/$user$cgroupsuffix/cpu.cfs_quota_us) && rollback "CGROUP_CPU_CREAT"
! (cgcreate -g memory:$user$cgroupsuffix &&
echo "${memory}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.limit_in_bytes &&
echo "${swapmem}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.memsw.limit_in_bytes) && rollback "CGROUP_MEM_CREAT"

View File

@@ -48,11 +48,17 @@ else
fi
fi
# Install iptables
if ! command -v iptables &>/dev/null; then
stage "Installing iptables"
apt-get install -y iptables
fi
# Load br_netfilter kernel module on startup (if not loaded already).
if [[ -z "$(lsmod | grep br_netfilter)" ]]; then
echo "Adding br_netfilter"
modprobe br_netfilter
echo "br_netfilter" > /etc/modules-load.d/br_netfilter.conf
echo "br_netfilter" >/etc/modules-load.d/br_netfilter.conf
fi
# -------------------------------
@@ -92,10 +98,10 @@ if [ $updated -eq 1 ]; then
# Create a backup of original, if remount failed replace updated with backup.
cp $originalfstab $backup
mv "$tmpfstab" $originalfstab
if ! mount -o remount / 2>&1 ; then
if ! mount -o remount / 2>&1; then
mv $backup $originalfstab
echo "Re mounting error." && exit 1
fi
fi
echo "Updated fstab."
else
echo "fstab already configured."
@@ -134,7 +140,7 @@ if [ $res -eq 0 ]; then
res=$?
updated=1
elif [ $res -eq 0 ]; then
echo "user_allow_other" >> "$tmpconf"
echo "user_allow_other" >>"$tmpconf"
res=$?
updated=1
fi
@@ -236,7 +242,7 @@ if [ $res -eq 100 ]; then
fi
fi
elif [ $res -eq 0 ]; then
echo "GRUB_CMDLINE_LINUX=\"cgroup_enable=memory swapaccount=1\"" >> "$tmpgrub"
echo "GRUB_CMDLINE_LINUX=\"cgroup_enable=memory swapaccount=1\"" >>"$tmpgrub"
res=$?
updated=1
fi
@@ -251,7 +257,7 @@ if [ $updated -eq 1 ]; then
cp /etc/default/grub $grub_backup
mv "$tmpgrub" /etc/default/grub
rm -r "$tmp"
if ! update-grub >/dev/null 2>&1 ; then
if ! update-grub >/dev/null 2>&1; then
mv $grub_backup /etc/default/grub
echo "Grub update failed."
exit 1
@@ -268,4 +274,4 @@ else
echo "Grub already configured."
fi
exit 0
exit 0

View File

@@ -20,7 +20,7 @@ appenv = {
ACQUIRE_LEASE_TIMEOUT_THRESHOLD: 0.8,
ACQUIRE_LEASE_WAIT_TIMEOUT_THRESHOLD: 0.4,
SASHI_CLI_PATH: appenv.IS_DEV_MODE ? "../build/sashi" : "/usr/bin/sashi",
MB_VERSION: '0.5.2',
MB_VERSION: '0.5.3',
TOS_HASH: '757A0237B44D8B2BBB04AE2BAD5813858E0AECD2F0B217075E27E0630BA74314' // This is the sha256 hash of TOS text.
}
Object.freeze(appenv);

View File

@@ -107,14 +107,15 @@ class MessageBoard {
console.log(`Moments exceeded (current ledger:${e.ledger_index}, expiry ledger:${x.expiryLedger}). Destroying ${x.containerName}`);
// Expire the current lease agreement (Burn the instance NFT) and re-minting and creating sell offer for the same lease index.
const nft = (await (new evernode.XrplAccount(x.tenant)).getNfts())?.find(n => n.NFTokenID == x.containerName);
// If there's no nft for this record it should be already burned and instance is destroyed, So we only delete the record.
if (!nft)
throw `Cannot find a NFT for ${x.containerName}`;
console.log(`Cannot find a NFT for ${x.containerName}`);
else {
const uriInfo = evernode.UtilHelpers.decodeLeaseNftUri(nft.URI);
await this.destroyInstance(x.containerName, x.tenant, uriInfo.leaseIndex, true);
}
const uriInfo = evernode.UtilHelpers.decodeLeaseNftUri(nft.URI);
await this.destroyInstance(x.containerName, x.tenant, uriInfo.leaseIndex, true);
this.activeInstanceCount--;
await this.hostClient.updateRegInfo(this.activeInstanceCount);
/**
* Soft deletion for debugging purpose.
*/
@@ -122,6 +123,8 @@ class MessageBoard {
// Delete the lease record related to this instance (Permanent Delete).
await this.deleteLeaseRecord(x.txHash);
await this.hostClient.updateRegInfo(this.activeInstanceCount);
console.log(`Destroyed ${x.containerName}`);
}
catch (e) {

View File

@@ -6,7 +6,7 @@
namespace version
{
// Sashimono agent version. Written to new configs.
constexpr const char *AGENT_VERSION = "0.5.2";
constexpr const char *AGENT_VERSION = "0.5.3";
// Minimum compatible config version (this will be used to validate configs).
constexpr const char *MIN_CONFIG_VERSION = "0.5.0";