Merge lp://staging/~vorlon/pollinate/micro-optimize into lp://staging/~pollinate/pollinate/trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
pollinate | Pending | ||
Review via email:
|
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-
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.
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 "\${Version} " cloud-init 2>/dev/null); done' -- $args
out=$(dpkg-query -W --showformat=
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