[arch-projects] [netcfg] [PATCH 3/4] Lower latency in timeout_wait

Jouke Witteveen j.witteveen at gmail.com
Mon Jul 2 19:08:34 EDT 2012


On Mon, Jul 2, 2012 at 11:07 PM, Henrik Hallberg <henrik at k2h.se> wrote:
> ---
>  src/globals | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/globals b/src/globals
> index 436334a..62cce3e 100644
> --- a/src/globals
> +++ b/src/globals
> @@ -100,10 +100,11 @@ function checkyesno() {
>  # $2...: condition command
>  function timeout_wait() {
>      local timeout="$1"
> +    (( timeout *= 10 ))
>      shift
>      while ! eval "$*"; do
>          (( timeout-- > 0 )) || return 1
> -        sleep 1
> +        sleep 0.1
>      done
>      return 0
>  }
> --
> 1.7.11.1
>

I don't think this is such a good idea. This saves less than .45
seconds on average per timeout_wait (old expected waste: .5s, new
expected waste: .05s, added polling overhead). If you want to do it
this way, you should probably decouple (( timeout-- > 0 )) into ((
timeout -= .1 )) and (( timeout > 0 )). The gain is usually a lot less
than the wait (saving .45s on something that takes 3s isn't all too
exciting) and not seldom, netcfg is an interactive script so that half
a second doesn't really matter.

Why would we try to make a bash script super fast?

Note that even with the 1s sleeps, it can be beneficial to call
`timeout_wait 1 'whatever'`, as it might return in 0s. This means the
other patches still make some sense without this one.

That's just what I think. I appreciate your contributions!
- Jouke


More information about the arch-projects mailing list