2010-12-06 23:30:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-24 01:02:07 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-2024 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
|
2021-03-22 20:16:35 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2024-06-09 18:54:40 +00:00
|
|
|
forceswap() {
|
|
|
|
perl -e '
|
|
|
|
my $sleep_after = shift;
|
|
|
|
|
|
|
|
# Only output if output is terminal
|
|
|
|
my $output = -t STDOUT;
|
|
|
|
|
|
|
|
sub freekb {
|
|
|
|
my $free = `free|grep buffers/cache`;
|
|
|
|
my @a=split / +/,$free;
|
|
|
|
if($a[3] > 0) {
|
|
|
|
return $a[3];
|
|
|
|
}
|
|
|
|
my $free = `free|grep Mem:`;
|
|
|
|
my @a=split / +/,$free;
|
|
|
|
if($a[6] > 0) {
|
|
|
|
return $a[6];
|
|
|
|
}
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub swapkb {
|
|
|
|
my $swap = `free|grep Swap:`;
|
|
|
|
my @a=split / +/,$swap;
|
|
|
|
return $a[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
my $swap = swapkb();
|
|
|
|
my $lastswap = $swap;
|
|
|
|
my $free = freekb();
|
|
|
|
my @children;
|
|
|
|
while($lastswap >= $swap) {
|
|
|
|
$output and print "Swap: $swap Free: $free";
|
|
|
|
$lastswap = $swap;
|
|
|
|
$swap = swapkb();
|
|
|
|
$free = freekb();
|
|
|
|
my $pct10 = $free * 1024 * 10/100;
|
|
|
|
my $use = ($pct10 > 2_000_000_000 ? 2_000_000_000 : $pct10);
|
|
|
|
my $used_mem_single = "x"x($use/1000);
|
|
|
|
# Faster for large values
|
|
|
|
my $used_mem = "$used_mem_single"x1000;
|
|
|
|
my $child = fork();
|
|
|
|
if($child) {
|
|
|
|
push @children, $child;
|
|
|
|
} else {
|
|
|
|
sleep 120;
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output and print "Swap increased $lastswap -> $swap\n";
|
|
|
|
if($sleep_after) {
|
|
|
|
$output and print "Sleep $sleep_after\n";
|
|
|
|
sleep $sleep_after;
|
|
|
|
}
|
|
|
|
kill "INT", @children;
|
|
|
|
' $@
|
|
|
|
}
|
|
|
|
|
2011-07-28 19:09:27 +00:00
|
|
|
echo '### Test niceload -q'
|
|
|
|
niceload -q perl -e '$a = "works";$b="This $a\n"; print($b);'
|
2018-09-20 22:15:14 +00:00
|
|
|
echo
|
2010-12-06 23:30:08 +00:00
|
|
|
|
2024-06-09 18:54:40 +00:00
|
|
|
# Force swapping
|
|
|
|
forceswap >/dev/null
|
|
|
|
forceswap >/dev/null &
|
2011-07-19 14:44:14 +00:00
|
|
|
|
2018-09-20 22:15:14 +00:00
|
|
|
cat <<'EOF' | sed -e 's/;$/; /;s/$SERVER1/'$SERVER1'/;s/$SERVER2/'$SERVER2'/' | stdout parallel -vj0 -k --joblog /tmp/jl-`basename $0` -L1 -r
|
2012-10-22 21:08:54 +00:00
|
|
|
echo '### --rm and --runmem'
|
2016-08-21 13:37:59 +00:00
|
|
|
niceload -H --rm 1g free -g | perl -ane '/Mem:/ and print $F[5],"\n"' | grep '[1-9]' >/dev/null && echo OK--rm
|
|
|
|
niceload -H --runmem 1g free -g | perl -ane '/Mem:/ and print $F[5],"\n"' | grep '[1-9]' >/dev/null && echo OK--runmem
|
2012-10-22 21:08:54 +00:00
|
|
|
|
|
|
|
echo '### -N and --noswap. Must give 0'
|
|
|
|
niceload -H -N vmstat 1 2 | tail -n1 | awk '{print "-N " $7*$8}'
|
|
|
|
niceload -H --noswap vmstat 1 2 | tail -n1 | awk '{print "--noswap " $7*$8}'
|
|
|
|
EOF
|
2011-07-19 14:44:14 +00:00
|
|
|
|
2011-07-22 08:47:14 +00:00
|
|
|
# force load > 10
|
2024-06-09 18:54:40 +00:00
|
|
|
while uptime | grep -Ev age:.[1-9][0-9]+.[0-9][0-9] >/dev/null ; do
|
2017-06-22 11:35:58 +00:00
|
|
|
(timeout 5 nice perl -e 'while(1){}' 2>/dev/null &)
|
|
|
|
done
|
2011-07-22 08:47:14 +00:00
|
|
|
|
2015-01-08 23:00:21 +00:00
|
|
|
cat <<'EOF' | sed -e 's/;$/; /;s/$SERVER1/'$SERVER1'/;s/$SERVER2/'$SERVER2'/' | stdout parallel -vj0 --joblog /tmp/jl-`basename $0` -L1
|
2011-07-19 14:44:14 +00:00
|
|
|
echo '### -H and --hard'
|
2015-01-08 23:00:21 +00:00
|
|
|
niceload -H -l 9.9 uptime | grep ':.[1-9][0-9].[0-9][0-9],' || echo OK-load below 9.9
|
|
|
|
niceload --hard -l 9 uptime | grep ':.[1-9][0-9].[0-9][0-9],' || echo OK-load below 10
|
2012-10-22 21:08:54 +00:00
|
|
|
EOF
|
2011-07-19 14:44:14 +00:00
|
|
|
|
2015-01-08 23:00:21 +00:00
|
|
|
cat <<'EOF' | sed -e 's/;$/; /;s/$SERVER1/'$SERVER1'/;s/$SERVER2/'$SERVER2'/' | stdout parallel -vj0 --joblog /tmp/jl-`basename $0` -L1
|
2011-07-20 23:58:23 +00:00
|
|
|
echo '### -f and --factor'
|
2020-10-12 23:17:14 +00:00
|
|
|
niceload -H --factor 30 -l6 echo factor 30 finish last
|
2012-10-22 21:08:54 +00:00
|
|
|
niceload -H -f 0.01 -l6 echo f 0.1 finish first
|
|
|
|
EOF
|
2011-07-19 14:44:14 +00:00
|
|
|
|
2010-12-06 23:30:08 +00:00
|
|
|
#echo '### Test niceload -p'
|
|
|
|
#sleep 3 &
|
|
|
|
#nice-load -v -p $!
|