Subject: re: /etc/rc.d/ runs slowsly
To: None <port-mips@netbsd.org, port-pmax@netbsd.org,>
From: Greg A. Woods <woods@weird.com>
List: port-mips
Date: 04/08/2000 23:37:31
[[ note: redirected to current-users ]]
[ On Saturday, April 8, 2000 at 00:35:15 (+1000), matthew green wrote: ]
> Subject: re: /etc/rc.d/ runs slowsly
>
> i thought there was a backdoor hack in that boottime used to
> disable running ps to check if a daemon was already running..
> did luke not commit this???
It doesn't look like any fix has yet been committed.
The "ps -c" trick speeds up PS, but it's not the only problem with the
rc functions -- "while" loops in shell scripts are also somewhat slow,
especially if they have to fork 'test' twice on every iteration! ;-)
The patch below speeds things up by at least a factor of three to four,
if not an order of magnitude, on my little 486dx66. Even with an 8MB
machine rc.subr is painfully and unacceptably slow in its original form:
23:33 [993] # cp rc.subr.orig /etc
23:33 [994] # time /etc/rc.d/rwho restart
Stopping rwhod.
Starting rwhod.
17.54s real 2.15s user 16.05s system
23:34 [995] # time /etc/rc.d/rwho restart
Stopping rwhod.
Starting rwhod.
17.20s real 2.17s user 16.20s system
23:34 [996] # time /etc/rc.d/rwho restart
Stopping rwhod.
Starting rwhod.
16.77s real 2.05s user 15.91s system
23:34 [997] # cp rc.subr /etc
23:34 [998] # time /etc/rc.d/rwho restart
Stopping rwhod.
Starting rwhod.
5.95s real 1.17s user 4.19s system
23:35 [999] # time /etc/rc.d/rwho restart
Stopping rwhod.
Starting rwhod.
5.26s real 1.25s user 4.20s system
23:35 [1000] # time /etc/rc.d/rwho restart
Stopping rwhod.
Starting rwhod.
6.11s real 1.27s user 4.40s system
WARNING: this patch uses 'fgrep' even though it isn't in /usr/bin. I
can get away with this because I keep /usr on my root filesystem (where
it belongs! :-). If it's not appropriate to move 'grep' to /bin for the
sticks-in-the-mud who don't want to move /usr to the root FS, then
perhaps 'sed' or maybe a really simple stand-alone true fgrep clone
would be appropriate. Note that a static 'sed' is only ~87k on i386.
Personally if I were to keep /usr on a separate FS then I'd want 'awk'
in /bin too.
--- /most/var/sup/sup.NetBSD.ORG/src/etc/rc.subr Fri Mar 10 07:10:34 2000
+++ /usr/src/etc/rc.subr Sat Apr 8 23:14:52 2000
@@ -115,16 +115,10 @@
if [ -z "$_pid" ]; then
return
fi
- _procnamebn=`basename $_procname`
- ps -p $_pid -o 'pid,command' | while read _npid _arg0 _argv; do
- if [ "$_npid" = "PID" ]; then
- continue
- fi
- if [ "$_arg0" = "$_procname" -o "$_arg0" = "$_procnamebn" \
- -o "$_arg0" = "${_procnamebn}:" ]; then
- echo $_npid
- return
- fi
+ _procnamebn=$(basename $_procname)
+ ps -p $_pid -o 'pid,command' | fgrep $_procnamebn | while read _npid _arg0; do
+ echo $_npid
+ return
done
}
@@ -139,17 +133,11 @@
if [ -z "$_procname" ]; then
err 3 'USAGE: check_process procname'
fi
- _procnamebn=`basename $_procname`
+ _procnamebn=$(basename $_procname)
_pref=
- ps -ax -o 'pid,command' | while read _npid _arg0 _argv; do
- if [ "$_npid" = "PID" ]; then
- continue
- fi
- if [ "$_arg0" = "$_procname" -o "$_arg0" = "$_procnamebn" \
- -o "$_arg0" = "${_procnamebn}:" ]; then
- echo -n "$_pref$_npid"
- _pref=" "
- fi
+ ps -axc -o 'pid,command' | fgrep $_procnamebn | while read _npid _arg0; do
+ echo -n "$_pref$_npid"
+ _pref=" "
done
}
--
Greg A. Woods
+1 416 218-0098 VE3TCP <gwoods@acm.org> <robohack!woods>
Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>