Mixing cpuset.cpus and cpuset.mems cgroups with cpu.shares with memory.limit_in_bytes - cgroups

I have some confusion over how cgroups work. Here's my understanding of these cgroup limits...
cpuset.cpus binds to a specific core
cpuset.mems binds to a specific NUMA node
cpu.shares tells the scheduler to give a certain percentage of CPU processing power
memory.limit_in_bytes limits the amount of memory available to the process
So what happens when you bind a process to a specific cpuset, cpu, and memory? Some examples...
If the NUMA nodes I bind to total 8GB but I set my memory limit to 12GB, what happens?
If I bind to cores 0 and 1 but set the cpu shares to 2 out of 1024, what happens?
Also, how do I know the details/specs of the cores/NUMA nodes that I'm referencing in cpuset?

have the same confusion.
But based on my test, if cpuset.cpu_exclusive=0(cores are shared), both cpu.shares and cpuset.cpus work. Test is as following.
create two cgroups: cputest1 and cputest2(same hierarchy under root)
for both cputest1 and cputest2, do:
echo 0,2 > cpuset.cpus
echo 0 > cpuset.mems
new terminal a
cd /sys/fs/cgroup/cpuset/cputest1
echo $$ >> cgroup.proc
while :; do echo test > /dev/null; done
new terminal b
cd /sys/fs/cgroup/cpuset/cputest1
echo $$ >> cgroup.proc
while :; do echo test > /dev/null; done
new terminal c
cd /sys/fs/cgroup/cpuset/cputest2
echo $$ >> cgroup.proc
while :; do echo test > /dev/null; done
run top, there are three bash tasks, and cpu usage of each task is almost same about(60%-70%), total is 200%
4.
terminal a
echo $$ >> /sys/fs/cgroup/cpu/cputest1/cgroup.proc
while :; do echo test > /dev/null; done
terminal b
echo $$ >> /sys/fs/cgroup/cpu/cputest1/cgroup.proc
while :; do echo test > /dev/null; done
terminal c
echo $$ >> /sys/fs/cgroup/cpu/cputest2/cgroup.proc
while :; do echo test > /dev/null; done
echo 2/2048/1024 > /sys/fs/cgroup/cpu/cputest1/cpu.shares
echo 2048/2/1024 > /sys/fs/cgroup/cpu/cputest2/cpu.shares
run top to watch the cpu usage among three bash task

Related

Refillable lists in batch

So. Currently I am working on a game where you create your own nation in Batch. There are bills passed by congress that you can either sign or veto. Once you do so, the bill disappears. After some time a new bill will pop up. The thing is there is a bill limit of 5, meaning that there can only be 5 bills waiting your approval at a time.
Here is the code so far.
:leg
title Borderlines BETA - Legislation
cls
echo =====
echo 1-Legislation (%notify_leg%) ===== 2-Disputes (%notify_disputes%) ===== 3-Mailbox (%notify_mailbox%)
echo =====
echo Legislation
if %notify_leg% GTR 0 (
echo You have new bills from Congress awating your approval!
) else (
echo Its been a slow day in %nation%...
)
echo ---
echo Select a bill...
echo %leg_01%
echo %leg_02%
echo %leg_03%
echo %leg_04%
echo %leg_05%
echo.
echo ---
echo A - Home
echo.
echo ---
set /p leg_choice=""
if %leg_choice%==A goto home
if %leg_choice%==1 goto leg
if %leg_choice%==2 goto disputes
if %leg_choice%==3 goto mail
if %leg_choice% GTR 3 goto bill_%leg_choice%
goto home
Basically %leg_01%, %leg_02%, and so on are the slots. When you create your nation, the bills are assigned. When you pass or veto a bill it removes the notification.
However lets say over time another bill gets added to the list. How can I have it so that once you sign or veto the bill it will remove it from the list, tell the program that a slot is available, and move up the remaining items all the way to the top. This would be essential because there could be, eventually, multiple bills in the game that will show up on that list.
Hope that makes sense ~
Does this suit your needs?
:newleg
if "%~1"=="" exit /b
for /l %%# in (4 -1 1) do (
set /a n=%%#+1
call set leg_0%%n%%=%%leg_0%%#%%
)
set leg_01=%~1
Call with call :newleg This_is_a_new_leg. All values will be shifted downwards, i.e. leg_05 is lost, the value of leg_04 is assigned to leg_05. leg_01 will be redefined as the specified parameter.
If you'd like to avoid quoting values with spaces while calling the function, you can use %* instead.
You can also keep the values of leg_06 and so on by increasing the limit in the for-loop (n-1, in this case "4").
You can delete an item from the list and then shift upwards with this function:
:delleg
if "%~1"=="" exit /b
set leg_0%1=
for /l %%# in (1 1 5) do if not defined leg_0%%# call :dl %%#
exit /b
:dl
set /a n=%1+1
for /l %%# in (%n% 1 6) do (
set /a n=%%#-1
call set leg_0%%n%%=%%leg_0%%#%%
)
exit /b
Call with call :delleg 2 to delete leg_02.

Using rrdtool to monitor few servers

Please help to understand. I find the simple of script in off site about update RRDTool base.
But for me need to create one rrd base to all servers. Please help to understand what way the best and just give some point how to do this.
Send data from all servers to rrdtool base and update it? or try to get all data from server where rrdtool and update in local level?
#!/bin/sh
a=0
while [ "$a" == 0 ]; do
snmpwalk -c public 192.168.1.250 hrSWRunPerfMem > snmp_reply
total_mem=`awk 'BEGIN {tot_mem=0}
{ if ($NF == "KBytes")
{tot_mem=tot_mem+$(NF-1)}
}
END {print tot_mem}' snmp_reply`
# I can use N as a replacement for the current time
rrdtool update target.rrd N:$total_mem
# sleep until the next 300 seconds are full
perl -e 'sleep 300 - time % 300'
done # end of while loop

List workspaces of a user on a specific machine in Perforce

How can I get all Perfoce workspaces of a specific user on a specific machine?
This command let me all workspaces of a specific user on all machines:
P4 clients -u username
Here's a cmd one-liner that does more or less the same thing as pitseeker's:
for /f "tokens=2" %x in ('p4 clients -u username') do #(echo %x & p4 client -o %x | findstr /r /c:"^Host:")
A somewhat more robust batch file that seems to fit what you're looking for is:
#echo off
set USER=%1
set HOST=%2
REM Don't forget to double your for-loop percents in batch files,
REM unlike the one-liner above...
for /f "tokens=2" %%x in ('p4 clients -u %USER%') do call :CheckClient %%x
goto :EOF
:CheckClient
p4 client -o %1 | findstr /r /c:"^Host:" | findstr /i /r /c:"%HOST%$">nul && echo %1
goto :EOF
Save that and run it with the username as the first parameter and the desired host name as the second. That is, something like showclient elady elady_pc
Not exactly what you're asking for, but it's easy and perhaps sufficient:
p4 clients -u username | cut -f2 -d' ' | xargs -n 1 p4 client -o |egrep -e '^Client|^Host'
This lists all your clients and their host-restrictions (if any).
In the resulting list you can find the specific machines very easily.

Shell Programming - How do I loop through a list and process N at a time?

I am trying to read though a list and I want to read 25 at a time in the list then sleep for 5 seconds then keep reading 25 at a time until I exhaust the list.
This is what I'm doing right now, but I start too many ssh sessions at the same time. I want to be able to run 25, sleep for 5 seconds, run 25 more until the list has been exhausted.
cat ctrlnodes.txt |\
while read N
do
ssh -n $N "/var/opt/OV/bin/instrumentation/agent_health.sh" &
done
Answer
counter=0
while read N; do
((counter++))
ssh -n $N "/var/opt/OV/bin/instrumentation/agent_health.sh" &
[[ $(($counter % 25)) = 0 ]] && sleep 5
done <ctrlnodes.txt
Explanation
First, a counter needs to be initialized before the loop and incremented through each iteration; this allows the script to test whether it's on an iteration that's evenly divisible by 25.
Second, you need to change the cat pipe of your text file to while to a direct input redirection on done; when you use the former a subshell is created and $counter will be out of scope and won't increment properly.
Finally, what probably needs the most explanation is the evenly-divisible test itself:
[[ $(($counter % 25)) = 0 ]] && sleep 5
What this does is perform a test of whether modulus 25 of the counter is zero. (i.e., $counter is evenly divisible by 25) If it is then the test's exit value is true, so the 'and' (&&) can continue on to the sleep command; if the modulus value is non-zero then the && won't continue since the test will have a false exit value.
A one-liner test of the concept:
seq 1 100 >numbers.txt && counter=0 && while read N; do ((counter++)); echo $N; [[ $(($counter % 25)) = 0 ]] && echo -n sleeping... && sleep 5 && echo; done <numbers.txt
What you should see is blocks of 25 numbers, a "sleeping..." line with a 5 second pause, until it's gone through all 1..100.
for i in $(seq 1 100 )
do
for j in $(seq 1 25)
do
# suppose you have an array
echo ${your_list[i]}
done
sleep 5
done
Lets create a file with one integer/row, 100 rows:
$ seq 1 100 > data
Using the script below:
#!/bin/bash
n=1
while read N
do
# here you call your ssh
if [ $((n % 25)) -eq 0 ]
then
echo "Spawned 25 subprocesses, waiting..."
echo $n, $N
# wait for all subprocesses to finish before continuing
# Replace 'wait' with 'sleep 5' if that's desired
wait
fi
((n+=1))
done < data
output:
$ ./s.sh
Spawned 25 subprocesses, waiting...
25, 25
Spawned 25 subprocesses, waiting...
50, 50
Spawned 25 subprocesses, waiting...
75, 75
Spawned 25 subprocesses, waiting...
100, 100

cmd if script won't work

#echo off
pause
color 0a
mode 1000
set /p apps = where do you want to go to?
echo metrix = 1
echo nothing = 2
pause
if %apps% == 1 goto metrix
if %apps% == 2 goto nothing
:metrix
:start
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random% %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random% %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%
goto start
:nothing
echo nothing
pause
exit
why doesnt it woerk?
I copied it from a tutorial and I have no idea why doesnt it work.
Remove the space before and after "=", in following statement.
set /p apps = where do you want to go to?
Besides CuriousMind's suggestion you should also do the comparison this way:
if "%apps%"=="1" goto metrix
if "%apps%"=="2" goto nothing
Using quotes and removing redundant spaces is safer. You probably also want to write
echo metrix = 1
echo nothing = 2
set /p apps = where do you want to go to?
so that the echos are displayed before the question.