Strange performance issue with grep -r -i as non-root user

Clifton Royston cliftonr at lava.net
Sun Mar 6 01:01:43 UTC 2011


On Sat, Mar 05, 2011 at 03:45:14PM -0800, Jeremy Chadwick wrote:
> This is a strange one, and the more I started debugging it (starting
> with truss, comparing fast vs. slow results, where all that appears
> different is read() operations are taking a lot longer -- I haven't had
> time to check with ktrace yet), the more strange it got: that's when I
> found out the behaviour changes depending on if you're a user or root.
> 
> Easy to reproduce:
> 
> - grep -r string /usr/src, as non-root, is fast
> - grep -r -i string /usr/src, as non-root, is 8x slower than without -i

  From your results below, I think you mean *80* x slower!

> - grep -r string /usr/src, as root, is fast
> - grep -r -i string /usr/src, as root, is fast

  I can not reproduce this on 7.3-RELEASE-p4; I get consistent results
between root and non-root, with -i being only marginally slower (about
15%) for each; results below.

  Just to satisfy my peace of mind, can you do 'which grep' and 'sudo sh
-c "which grep"' as jdc to make sure it's not path-related weirdness?
  -- Clifton

[cliftonr at oz ~]$ id
uid=1001(cliftonr) gid=1001(cliftonr)
groups=1001(cliftonr),0(wheel),1002(svn-user),1000(users)
[cliftonr at oz ~]$ for i in {0..9}; do /usr/bin/time -h /usr/bin/grep -r \
 PAE /usr/src/sys/dev > /dev/null; done
        12.10s real             0.16s user              0.21s sys
        0.20s real              0.12s user              0.08s sys
...
[cliftonr at oz ~]$ for i in {0..9}; do /usr/bin/time -h /usr/bin/grep -r \
 PAE /usr/src/sys/dev > /dev/null; done
        0.20s real              0.11s user              0.09s sys
        0.20s real              0.13s user              0.06s sys
        0.20s real              0.12s user              0.08s sys
        0.20s real              0.12s user              0.07s sys
        0.20s real              0.14s user              0.06s sys
        0.20s real              0.15s user              0.05s sys
        0.20s real              0.12s user              0.08s sys
        0.20s real              0.09s user              0.11s sys
        0.20s real              0.14s user              0.06s sys
        0.20s real              0.12s user              0.07s sys
[cliftonr at oz ~]$ for i in {0..9}; do /usr/bin/time -h /usr/bin/grep -r \
 -i PAE /usr/src/sys/dev > /dev/null; done
        0.23s real              0.14s user              0.08s sys
        0.23s real              0.15s user              0.07s sys
        0.23s real              0.18s user              0.05s sys
        0.23s real              0.14s user              0.08s sys
        0.23s real              0.19s user              0.03s sys
        0.23s real              0.18s user              0.04s sys
        0.23s real              0.14s user              0.08s sys
        0.23s real              0.13s user              0.09s sys
        0.23s real              0.16s user              0.06s sys
        0.22s real              0.17s user              0.05s sys
[cliftonr at oz ~]$ sudo -v
[cliftonr at oz ~]$ for i in {0..9}; do sudo /usr/bin/time -h \
 /usr/bin/grep -r PAE /usr/src/sys/dev > /dev/null; done
        0.20s real              0.18s user              0.02s sys
        0.20s real              0.10s user              0.10s sys
        0.20s real              0.14s user              0.06s sys
        0.20s real              0.13s user              0.06s sys
        0.20s real              0.12s user              0.08s sys
        0.20s real              0.12s user              0.07s sys
        0.20s real              0.12s user              0.08s sys
        0.20s real              0.12s user              0.08s sys
        0.20s real              0.16s user              0.03s sys
        0.20s real              0.15s user              0.05s sys
[cliftonr at oz ~]$ for i in {0..9}; do sudo /usr/bin/time -h \
 /usr/bin/grep -r -i PAE /usr/src/sys/dev > /dev/null; done
        0.23s real              0.17s user              0.05s sys
        0.23s real              0.16s user              0.06s sys
        0.23s real              0.17s user              0.05s sys
        0.23s real              0.17s user              0.06s sys
        0.23s real              0.17s user              0.06s sys
        0.23s real              0.18s user              0.05s sys
        0.23s real              0.17s user              0.05s sys
        0.23s real              0.14s user              0.08s sys
        0.23s real              0.15s user              0.08s sys
        0.22s real              0.13s user              0.09s sys
[cliftonr at oz ~]$ which grep
/usr/bin/grep
[cliftonr at oz ~]$ sudo sh -c "which grep"
/usr/bin/grep

-- 
    Clifton Royston  --  cliftonr at iandicomputing.com / cliftonr at lava.net
       President  - I and I Computing * http://www.iandicomputing.com/
 Custom programming, network design, systems and network consulting services


More information about the freebsd-stable mailing list