[rrd-users] Can this script be optimised ?

Simon Hobson linux at thehobsons.co.uk
Wed Nov 28 17:27:32 CET 2012


Pablo Sanchez wrote:

>When I do any optimization, I always instrument and prioritize the
>slowest area of code.
>
>Looking at the shell script below, there appear to be two areas of
>optimization that you can change:
>
>1) The while conditional check, and/or
>2) The setting of UpdateVal
>
>I'll assume the `rrdtool' can't be changed (e.g. the disk the .rrd is
>on isn't the bottleneck.
>
>Given the above, where's the slowness?  Is it 1) or 2)?

I assume the main bottleneck is forking processes - as you hint, 
there's a fork for the while check, and then several forks to 
get/update the values (I'd expect all the code/external programs to 
remain in cache as there's spare RAM). The code runs OK, and I 
estimate that it takes about 2.5% of the CPU - based on using 'time' 
to get the system and user times for a complete run and dividing by 
60s.
The runtimes for those two bits are :

To get the value :
real	0m0.074s
user	0m0.020s
sys	0m0.016s
 
To run the update (which goes to a remote system, it's not a local RRD file) :
real	0m0.102s
user	0m0.020s
sys	0m0.020s
 
It's not so much optimising individual bits, it was more a question 
of "does a fresh set of eyes see something that shouts out "that's an 
inefficient way of doing it'". I'd already spotted several areas 
where I was able to improve the code when I came back (after a year 
or two since I first wrote it) and took another look.

-- 
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.



More information about the rrd-users mailing list