Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal change to the way BACKUP_LA_LIMIT is calculated #4162

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

sahsanu
Copy link
Contributor

@sahsanu sahsanu commented Nov 15, 2023

The other day I saw that BACKUP_LA_LIMIT was showing 4 processors but I'm using 2 so the problem here is the name of the processor (Common KVM processor) and as the command is

BACKUP_LA_LIMIT=$(cat /proc/cpuinfo | grep processor | wc -l)

It counts 4 processors instead of 2:

$ cat /proc/cpuinfo | grep processor
processor       : 0
model name      : Common KVM processor
processor       : 1
model name      : Common KVM processor

So I changed it to avoid this issue:

BACKUP_LA_LIMIT=$(cat /proc/cpuinfo | grep '^processor' | wc -l)

@jaapmarcus jaapmarcus merged commit 77d4160 into hestiacp:main Nov 24, 2023
6 checks passed
@Skamasle
Copy link
Contributor

Skamasle commented Nov 25, 2023

Hi

I will recomend use more efficient way to this

Here we call cat, grep and wc to get a single CPU number, remember the unix way, keep it simple!

You can do it with one command

lscpu |awk ' $1 == "CPU(s):" { print $2 }'

or if you want check /proc/cpuinfo why not just grep

grep -c '^processor' /proc/cpuinfo
Same result but faster,

# time grep -c  '^processor' /proc/cpuinfo
1

real	0m0.002s
user	0m0.002s
sys	0m0.000s
# time cat /proc/cpuinfo | grep '^processor' | wc -l
1

real	0m0.038s
user	0m0.001s
sys	0m0.005s
time lscpu |awk ' $1 == "CPU(s):" { print $2 }'
1

real	0m0.006s
user	0m0.002s
sys	0m0.003s

@jaapmarcus
Copy link
Member

Made the change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants