11

I need to set ntpd to sync time as often as possible, how to do that?

UPD I need to make ntpd adjust system clock more frequently, not poll servers. It's necessary because system clock of my virtual PC drifts too much
maxpoll doesn't seem to change anything, because I set minpoll/maxpoll to 4 and 5, and time adjustments seem to be made only once in several minutes

3
  • Why do you want to do this?
    – Kyle Smith
    Apr 10, 2012 at 14:52
  • Because I need precise time for my task. Any reasons not to do this?
    – user626528
    Apr 10, 2012 at 14:56
  • 9
    @user626528 define "precise time". Saying you need precision without quantifying the degree of precision you need is meaningless: Both a sniper rifle and a 51-inch mortar shell are "precise" munitions.
    – voretaq7
    Apr 10, 2012 at 15:05

3 Answers 3

12

The iburst option does several checks quickly as soon as the daemon is started and whenever the server is unreachable if you have that in your configuration. The burst option does several checks quickly whenever the server is reachable.

By default ntpd then follows an exponential backoff where the time between checks progressively increases, starting at 64 seconds and doubling each time, up to a maximum of 1024 seconds.

The maxpoll option allows you to set the maximum value higher or lower. This value is the power of 2 in seconds between checks, so for 1024 seconds, maxpoll is 10. There is also minpoll which is 6 by default and can be lowered to 4.

If you want anything more frequent than every 16 seconds you will probably need to use ntpdate instead of ntpd and run your own loop.

Please don't aim this at public time servers without contacting the maintainers first.

4
  • 4
    Probably best that he doesn't ever use NTPdate, as it doesn't obey KOD or ICMP messages.
    – Chris S
    Apr 10, 2012 at 14:59
  • Further reading on KoD and how to run a good NTP client in general: en.wikipedia.org/wiki/NTP_server_misuse_and_abuse
    – Ladadadada
    Apr 10, 2012 at 15:08
  • What @ChrisS said -- ntpdate is great for synchronizing the clock once, or for force-synchronizing against your own NTP server every second on machines where the local clock drift is atrocious. If you're in the latter situation, replace the machine (a clock that bad will be drifting by several seconds every minute -- you'll never have accurate time).
    – voretaq7
    Apr 10, 2012 at 15:12
  • 12
    Please, please, please DO NOT be that guy that changes the defaults on NTP. I have to look at my public-facing NTP server weekly and nuke the guys sending 1 packet every second. If your server doesn't listen to ICMP message saying "administratively prohibited," I will call your ISP's NOC and you will have a bad day. NTP will establish accurate to within milliseconds on its own and will adjust querying speed up and down as needed. Fiddling doesn't help. Apr 10, 2012 at 16:16
22

ntpd doesn't sync time periodically the way you think it does, see here for more information (read the whole thing, it's all important. Short version: ntpd syncs the time and tells the system how fast it's drifting away from "true" time, the system then adjusts its clock frequency to properly track "true" time. Within a day most systems are tracking to within 5ms of the reference).

Absent an EXCELLENT reason you should not be mucking about with the way ntpd adjusts and disciplines your clock - these algorithms have been thoroughly tested and debugged, and given an adequate time reference will produce very small error rates.
Frankly if you have such an EXCELLENT reason you already know what it is, and you have a substantial budget to hire an expert to make these modifications for you ("you wouldn't be asking this question if you really needed this").

If you require better time accuracy than what ntpd can get you on its own synchronizing against a machine over the network you need a specialized precision hardware reference clock attached locally to the machine. High-Frequency trading and picosecond-critical scientific experiments are about the only things I can think of that require this kind of precision.

14
  • @ChrisS that's a pretty wide band - you may have temperature control problems in your datacenter
    – voretaq7
    Apr 10, 2012 at 15:21
  • 3
    We use Precision Time Protocol when it's really critical... en.wikipedia.org/wiki/Precision_Time_Protocol
    – ewwhite
    Apr 10, 2012 at 15:26
  • 7
    -1 algorithm or program that requires high precision and accuracy != mega corp with super massive budget.
    – TheLQ
    Apr 16, 2012 at 17:30
  • 1
    One other use for having a local reference clock: high precision one-way network performance measurement. internet2.edu/performance/owamp
    – Dan Pritts
    Feb 15, 2013 at 22:17
  • 1
    @RomanGaufman You're asking ntpd to do something it's not designed to do (fix a clock that's wildly incorrect). You should run the ntpdate command (with the -b option) to set the clock initially, and then start the NTP daemon to maintain it (this can be part of your internet up/down scripts). If your connection or power are wildly unreliable you can also run ntpdate out of cron every 5 minutes, which may give "Good Enough" clock accuracy. (You may also consider investing in a hardware clock for your Raspberry Pi as an alternate solution. Google can help you find resources for that.)
    – voretaq7
    Jan 28, 2016 at 19:11
8

Get a GPS time receiver if you need highly accurate time. It'll check your clock every second. If you don't want to spend much, you can get a Garmin 18x LVC on eBay or Amazon for <$100 and wire it to a COM port. Directions around the Internet, but does require a minimum level of wiring skill. Complete solutions are available that cost more, if you're not into DIY projects.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .