Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fact for determining rsyslog version needlessly increases runtime by 1 second on RHEL #288

Open
nick-george opened this issue Oct 4, 2017 · 3 comments

Comments

@nick-george
Copy link

Please see this line:

https://github.com/saz/puppet-rsyslog/blob/master/lib/facter/rsyslog_version.rb#L22

Is there any need to run rpm -qa instead of rpm -q? See the difference in time for the two executions below. They both give the same result.

time /bin/rpm -qa --qf "%{VERSION}" "rsyslog"
7.4.7
real	0m0.914s
user	0m0.855s
sys	0m0.057s

time /bin/rpm -q --qf "%{VERSION}" "rsyslog"
7.4.7
real	0m0.070s
user	0m0.063s
sys	0m0.005s

@otheus
Copy link

otheus commented Oct 7, 2022

Bump. Trivial fix.

@otheus
Copy link

otheus commented Oct 7, 2022

Fixed (by someone else) in ed6609f . Please release new version/tag.

otheus referenced this issue Oct 7, 2022
Comparing the time for rpm -qa vs rpm -q

```
$ time rpm -qa --qf "%{VERSION}" "rsyslog"
7.4.7
real    0m1.638s
user    0m1.498s
sys     0m0.132s
```

vs

```
$ time rpm -q --qf "%{VERSION}" "rsyslog"
7.4.7
real    0m0.033s
user    0m0.026s
sys     0m0.005s
```

So that saves 1 second per puppet run.
@otheus
Copy link

otheus commented Oct 7, 2022

Further optimization can be made to line 19. Replace head|awk|sed with just sed.

rsyslogd -v | sed -n '2q; s/^[^ ]* \([0-9][^ ]*\).*/\1/; s/,//g;p'

Translation:

  • -n no output unless requested by p
  • quit at line 2
  • find the first instance of <digit>-<non-space>* after the first space; replace the line with it.
  • strip , characters
  • print the line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants