|laziness, impatience, and hubris|
The most precise second (timer)by tukusejssirs (Beadle)
|on Nov 26, 2019 at 14:53 UTC||Need Help??|
tukusejssirs has asked for the wisdom of the Perl Monks concerning the following question:
We have monitoring scripts that need to be run every second. The scripts execution takes longer than a second, but that is not a problem.
So we have need a function that would run the script every second. The interval must be as precise as possible. I know that the preciseness depends on CPU, RAM, CMOS etc. I donít care about these.
Currently, we use a script, letís call it negative_timer. It works quite precisely, but the Time::HiRes::sleep from time to time complains that negative time not invented yet. A second using this script is in average about 0.000000676723442 less than a real second.
The problem is that the negative_timer substracts a second from a $max value. Sometimes the NTP kicks in and it makes the trouble. We donít case if a second would be longer/shorter when the NTP updates the time.
Actually, we donít need any $max value, as we run the monitoring script indefinitely (i.e. until seldom reboot or maintaince).
Could anyone help me out in this?
Thank you in advance.
The negative_timer script: