I would like to ask how to debug high load with simple script.
Situation - I have IMAP shared folder, where can users move messages using their mail clients. When such situation occurs, this file should be cated through pipe to another script and then removed. Let say this occurs once a week. I wrote simple script using sysutils/wait_on which waits on file write in given directory and process all found files as described above. Generally, most of time this script does nothing.
but this script, which does almost nothing generate high load on machine with four cores
which is getting even worse when script is started from /etc/rc.local as following
Questions
Situation - I have IMAP shared folder, where can users move messages using their mail clients. When such situation occurs, this file should be cated through pipe to another script and then removed. Let say this occurs once a week. I wrote simple script using sysutils/wait_on which waits on file write in given directory and process all found files as described above. Generally, most of time this script does nothing.
Code:
# cat /usr/local/bin/otrspipe.sh
#!/bin/sh
while :; do
for FILE in `find /path_to_directory -type f`
do
cat $FILE | /path_to_script
rm $FILE
done
wait_on -w /path_to_directory
done
but this script, which does almost nothing generate high load on machine with four cores
Code:
# top -P
last pid: 23427; load averages: 1.00, 1.00, 1.00
188 processes: 2 running, 186 sleeping
CPU 0: 0.4% user, 0.0% nice, 48.3% system, 0.0% interrupt, 51.3% idle
CPU 1: 0.4% user, 0.0% nice, 33.2% system, 0.0% interrupt, 66.4% idle
CPU 2: 0.0% user, 0.0% nice, 23.6% system, 0.0% interrupt, 76.4% idle
CPU 3: 1.8% user, 0.0% nice, 4.8% system, 0.0% interrupt, 93.4% idle
Mem: 2552M Active, 7797M Inact, 973M Wired, 196M Cache, 1236M Buf, 370M Free
Swap: 4174M Total, 68K Used, 4174M Free
PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND
1555 root 1 76 0 1482M 1467M piperd 2 61.2H 51.17% sh
which is getting even worse when script is started from /etc/rc.local as following
Code:
# cat /etc/rc.local
/usr/sbin/daemon /usr/local/bin/otrspipe.sh > /var/log/otrspipe.log 2>&1
### Following line isn't interesting for this case
/usr/local/bin/java -jar /usr/local/unifi/lib/ace.jar start &
Questions
- How to debug high load?
- Can anybody suggest better way to immediate processing of message which appears in IMAP folder (Dovecot 2) from time to time?