Merge lp://staging/~vorlon/pollinate/micro-optimize into lp://staging/~pollinate/pollinate/trunk

Proposed by Steve Langasek
Status: Merged
Approved by: Dustin Kirkland 
Approved revision: 352
Merged at revision: 356
Proposed branch: lp://staging/~vorlon/pollinate/micro-optimize
Merge into: lp://staging/~pollinate/pollinate/trunk
Diff against target: 44 lines (+11/-7)
2 files modified
debian/changelog (+6/-2)
pollinate (+5/-5)
To merge this branch: bzr merge lp://staging/~vorlon/pollinate/micro-optimize
Reviewer Review Type Date Requested Status
pollinate Pending
Review via email: mp+329858@code.staging.launchpad.net

Description of the change

On a VM with no network whatsoever, systemd-analyze shows pollinate in the #5 position for most time-consuming unit at startup (598ms-654ms out of 4.632s-4.783s total). Not a huge amount of time, but a unit with nothing to do should fail fast.

The dependency on network-online.target doesn't help any here, because since there is *no* network configured, nothing blocks this target from being reached, and pollinate is still attempted.

So, here are a couple of minor optimizations to the pollinate script to improve performance. Unfortunately the gains aren't as great as I'd like; on this same VM they account for ~200ms of savings (338ms-475ms total). So I might look at other ways to figure out how to keep pollinate from running at all in this situation; but I guess a .2s boot savings is still worth doing, and will be applicable on all VMs with or without network.

Using versioned dependencies on bsdutils instead of checking versions at runtime may shave a little more off, though over 5 reboots I can't detect any clear savings.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Steve,
+1 on the dpkg-query changes.
they dont seem to produce much speed difference in my tests, but readability for sure. It is possible they have a bigger affect on single cpu system.

I just tested something like:

$ args=$(seq 1 100)
$ time sh -c 'for i in "$@"; do
    out=$(dpkg -l cloud-init 2>/dev/null| awk "{exit(0);}"); done' -- $args
real 0m5.995s
user 0m5.423s
sys 0m0.712s

$ time sh -c 'for i in "$@"; do
   out=$(dpkg-query -W --showformat="\${Version}" cloud-init 2>/dev/null); done' -- $args
real 0m6.100s
user 0m5.433s
sys 0m0.663s

For 'logger' though, I think its easiest just to check for presense of '--id':
This should be sufficient:
  logger --version | grep --quiet -- --id

Then, timing looks like:

$ time sh -c 'for i in "$@"; do :; done' -- $args
real 0m0.004s
user 0m0.002s
sys 0m0.001s

$ time sh -c 'for i in "$@"; do logger --help |
              grep --quiet -- --id; done' -- $args
real 0m0.150s
user 0m0.179s
sys 0m0.061s

$ time sh -c 'for i in "$@"; do out=$(logger --version | awk "{print \$4}"); dpkg --compare-versions $out ge 2.26.2 ; done' -- $(seq 1 100)

real 0m0.341s
user 0m0.375s
sys 0m0.104s

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes: