Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Time synchronization
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 516

PostPosted: Sat Jul 27, 2024 9:54 am    Post subject: Time synchronization Reply with quote

Hi folks

This is only tangentially a Gentoo question.

I just switched the Gentoo systems I recently installed, from using chrony to sntpd. I think chrony is just too much time-sync for a minimal system. The RHEL/Fedora systems I use all get chrony by default. Just out of curiosity, I looked at my Ubuntu installations, and saw they had systemd_timesyncd instead, which is something I had never even noticed before.

The source for Gentoo's version of sntpd say that:

"sntpd is a fork of Larry Doolittle's ntpclient with added daemon, syslog, and IPv6 support"

So it has some history, and there's a bit of documentation. systemd_timesyncd appears to be completely undocumented, with no indication where it came from.

Since sntpd and systemd_timesyncd do essentially the same thing and, so far as I can tell, in the same way, does anybody know where the are different? The systemd versions seems to do stuff with DBus, but I don't really understand what.

Does anybody know why, on a systemd system, I should prefer one implementation to the other? And, just out of idle curiosity, why the systemd folks wanted their own time sync daemon, when there are plenty of others around?

BR, Lars.
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1235
Location: Richmond Hill, Canada

PostPosted: Sat Jul 27, 2024 10:10 am    Post subject: Reply with quote

I think you answered your own question. may be because systemd_timesyncd talk over dbus. as far as I know no other time sync daemon talk over dbus.

out of topic, I am under impression you prefer no systemd from the udev alternative thread, so why now you consider systemd_timesyncd?

Personally I use openntpd, which is simple time sync daemon from bsd folks.
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 516

PostPosted: Sat Jul 27, 2024 11:10 am    Post subject: Reply with quote

pingtoo wrote:

out of topic, I am under impression you prefer no systemd from the udev alternative thread, so why now you consider systemd_timesyncd?


Purely idle curiosity. I prefer to avoid systemd, but I still have to use Ubuntu on some machines, which doesn't give me that option. It never occurred to me until today to wonder what time sync program it used, and then I discovered there was a systemd 'own brand' application.

Incidentally, I discovered one difference:

sntpd doesn't seem to cope with huge errors in the system clock. It will try to fix the error by adjusting the clock skew, which will take a very long time. I think systemd_timesyncd will step the system time if it's wrong by more than a certain threshold, as chrony does by default (I think).

None of this is relevant or important -- I'm on call this weekend, so I'm sitting here by my computers with bugger all else to do :)

BR, Lars.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3418

PostPosted: Sat Jul 27, 2024 11:37 am    Post subject: Reply with quote

All ntp daemons attempt to synchronize the local clock with the network.
Which is an impossible task, so they're doing their best to approximate the ideal. That's the keyword: approximate. The correct solution does not exist, so we just do _something_ and call it good enough.

And this is where different implementations differ. They track different things and fail in different ways.
E.g. ntpd follows mean time from multiple sources and crashes if the drift becomes too big for it to compensate (but keeps working even without authoritative source), chrony follows the time from whtever source it considers to be the best but adjust times faster and can recover from failures, while systemd-timesyncd exists because systemd-folks must put their finger into every single dish :roll:
Never used sntpd

Anyway, in vast majority of cases any npt daemon is good enough, but they all cut some corners somewhere (out of necessity), so in your particular case one might be more reliable than the other, depending on the environment and your priorities.
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
pa4wdh
l33t
l33t


Joined: 16 Dec 2005
Posts: 881

PostPosted: Sat Jul 27, 2024 12:21 pm    Post subject: Reply with quote

There are quite some NTP implementations which differ quite a lot.

Main differences:
1) How they sync and cope with latency/failures
2) Support for hardware clocks to sync to

2 is of course only relevant if you want to build a time server using a reference clock (for example GPS), 1 depends on how accurate you need to be. From what i found in the documentation sntpd and systemd-timesync both just query a server and set the local clock to whatever the server is telling them, that might be good enough for you. (x)ntpd and chrony do their best to do a better job by keeping track of latency/jitter/drift and compensate for that.

There is a comparison page in the chrony project: https://chrony-project.org/comparison.html
I expect it to be biased towards "chrony is better", i also spotted some misinformation about ntpd (which i expect they didn't do on purpose), but i think it still might help you to make a choice.
_________________
The gentoo way of bringing peace to the world:
USE="-war" emerge --newuse @world

My shared code repository: https://code.pa4wdh.nl.eu.org
Music, Free as in Freedom: https://www.jamendo.com
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2398

PostPosted: Sat Jul 27, 2024 2:41 pm    Post subject: Reply with quote

lars_the_bear wrote:

Purely idle curiosity. I prefer to avoid systemd, but I still have to use Ubuntu on some machines, which doesn't give me that option. It never occurred to me until today to wonder what time sync program it used, and then I discovered there was a systemd 'own brand' application.


Systemd has its own dhcp client too.

Best Regards,
Georgi
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 516

PostPosted: Sat Jul 27, 2024 6:40 pm    Post subject: Reply with quote

logrusx wrote:

Systemd has its own dhcp client too.


Yeah. I wonder why? I would guess that many (most?) distributions using systemd would be running NetworkManager, which also has a DHCP server.

Just in a spirit of idle inquiry, I wonder why there needs to be such a thing. I mean, it's isn't as if there's a shortage of perfectly adequate DHCP clients in the world. Does the systemd version do something that the others don't?

Not trying to provoke a systemd fight -- I'm just killing time during a boring on-call weekend :)

BR, Lars.
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1235
Location: Richmond Hill, Canada

PostPosted: Sat Jul 27, 2024 6:52 pm    Post subject: Reply with quote

lars_the_bear wrote:
Yeah. I wonder why? I would guess that many (most?) distributions using systemd would be running NetworkManager, which also has a DHCP server.
I think you mean dhcp client?

I would like to clarify for future reader, because this topic come up often. and a lots of time the word "dhcp" were used without clear understand.

Because Gentoo have multiple way to setup network it is easy to let someone think they need dhcp but not truly understand it mean dhcp client.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2398

PostPosted: Sat Jul 27, 2024 7:00 pm    Post subject: Reply with quote

lars_the_bear wrote:
logrusx wrote:

Systemd has its own dhcp client too.


Yeah. I wonder why? I would guess that many (most?) distributions using systemd would be running NetworkManager, which also has a DHCP server.


You meant DHCP client, right :-)

I used to run the systemd's dhcp client on my desktop which only had a fixed Internet connection. It's just easy. I could as well had configure the network interface but I was lazy. Now I use Network Manager as my current computer is a laptop and it's more practical to do so.

However I must clarify, systemd is system software and NetowrkManager is user software. It depend on the user if they'll bring in NM or not, not on the distribution.

Best Regards,
Georgi
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20484

PostPosted: Sun Jul 28, 2024 3:17 am    Post subject: Re: Time synchronization Reply with quote

lars_the_bear wrote:
And, just out of idle curiosity, why the systemd folks wanted their own time sync daemon, when there are plenty of others around?
I don't know if this is something I've read from an authoritative source, or if it's something I came up with to explain it, but it seems that systemd tries to integrate anything that needs a startup daemon into the systemd ecosystem so that it is a "first class citizen" rather than something that is hacked into working with varying degrees of success and definitions of working. Another way to look at this point of view would be the "old way" was "do one thing well" vs. "the one thing isn't hundreds of separate utilities, but one utility that does system initialization well." If that's reasonably accurate, I don't disagree with it conceptually. For example, I think ZFS is orders of magnitude better than older ways of disk / filesystem management (I have mixed feelings on ZFS since it fractured).

As an aside, I thought chrony came was from systemd folks. Maybe that was only because it was on a RHEL system with systemd instead of ntpd.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 516

PostPosted: Sun Jul 28, 2024 7:41 am    Post subject: Re: Time synchronization Reply with quote

pjp wrote:
As an aside, I thought chrony came was from systemd folks. Maybe that was only because it was on a RHEL system with systemd instead of ntpd.


I think Chrony started life at Red Hat, but it's connection to systemd -- if any -- is unclear to me. Chrony supports RFC 8915, which I suspect is a big deal in the kinds of environments where RHEL is used. Perhaps it was easier to create Chrony than implement RFC 8915 in any of the alternatives? I'm just guessing.

I suspect that "Do one thing and do it will" implies a notion that the "one thing" should be of reasonable scale, and suitable for integration with other "one things". I'm not sure that "system management" is a suitable candidate for "one thing".

But a service manager is, I think. It's actually possible to run the systemd service manager (PID=1) part without any of the rest of systemd. The only distribution that I know of that makes this a standard option is DietPi for the Raspberry Pi. Actually, this also uses systemd_timesyncd but, by default, only as a one-shot at boot time.

This method works surprisingly well, if you only need time accuracy to within a second or two. I have a Pi 3 running DietPi on my desk, and it's been up for 27 days, and the clock has only drifted by a couple of seconds.

Sorry, I'm rambling again.

BR, Lars.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3686
Location: Rasi, Finland

PostPosted: Sun Jul 28, 2024 8:43 am    Post subject: Reply with quote

Chrony is what you would want if you want all the features you could possibly need... or almost.
I've gone trough testing some ntp client-daemons.
I think the most simple one is the one that OpenBSD folks keep up to date. Clockspeed is one that is also interesting.

Relevant topic.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2175

PostPosted: Sun Jul 28, 2024 9:42 am    Post subject: Reply with quote

FWIW I was using net-misc/openntpd until last week, when I gave up on it and switched to straight net-misc/ntp. The reason for changing was that at boot time openntpd timed out connecting to my local ntp daemon (running on a Raspberry Pi, itself using ntp to set its clock from the uk.pool.ntp.org). Result of this was that for some reason the clocks had drifted way out of sync (more than 10 seconds). openntpd then starts synchonizing in very small steps every so often, and as I don't use my machines long enough in one sitting, they never caught up. Now with normal ntp configured with
Code:
server myntpserver iburst prefer

they synchonize very quickly at boot and stay OK.

There's an informative discussion on the ntp support web site.
_________________
Greybeard
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 516

PostPosted: Sun Jul 28, 2024 10:17 am    Post subject: Reply with quote

Goverp wrote:
... that for some reason the clocks had drifted way out of sync (more than 10 seconds). openntpd then starts synchonizing in very small steps every so often, ...


I didn't think the Pi's had a battery-backed clock at all. Or perhaps the newer ones do? If there's no battery-backed clock, I'd expect the system clock to be set to time zero at boot time, so it's going to be way out of sync.

I've found that the Pi's have sufficiently good clock stability that a one-time (step) sync at boot (sntp -Ss pool...) is sufficient, unless they're running for days or more.

BR, Lars.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3686
Location: Rasi, Finland

PostPosted: Sun Jul 28, 2024 11:30 am    Post subject: Reply with quote

Goverp wrote:
openntpd then starts synchonizing in very small steps every so often, and as I don't use my machines long enough in one sitting, they never caught up.
Yeah. I remember something like this. And I think one cannot adjust how fast or often the time adjustment happens (hardcoded)... unless, of course, via patching.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Koyan
n00b
n00b


Joined: 07 Nov 2014
Posts: 32

PostPosted: Sun Jul 28, 2024 11:31 am    Post subject: Reply with quote

Goverp wrote:
FWIW I was using net-misc/openntpd until last week, when I gave up on it and switched to straight net-misc/ntp. The reason for changing was that at boot time openntpd timed out connecting to my local ntp daemon (running on a Raspberry Pi, itself using ntp to set its clock from the uk.pool.ntp.org). Result of this was that for some reason the clocks had drifted way out of sync (more than 10 seconds). openntpd then starts synchonizing in very small steps every so often, and as I don't use my machines long enough in one sitting, they never caught up. Now with normal ntp configured with
Code:
server myntpserver iburst prefer

they synchonize very quickly at boot and stay OK.

There's an informative discussion on the ntp support web site.


You can change this behaviour in openntpd as well. From the man page:
Code:
       -S          Do not set the time immediately at startup.  This is the default.

       -s          Try to set the time immediately at startup, as opposed to slowly adjusting
                   the clock.  ntpd will stay in the foreground for up to 15 seconds  waiting
                   for one of the configured NTP servers to reply.



So if you edit /etc/conf.d/ntpd to include
Code:
NTPD_OPTS="-s"

your clocks should be set correctly at boot every time.


Last edited by Koyan on Sun Jul 28, 2024 11:41 am; edited 1 time in total
Back to top
View user's profile Send private message
Koyan
n00b
n00b


Joined: 07 Nov 2014
Posts: 32

PostPosted: Sun Jul 28, 2024 11:34 am    Post subject: Reply with quote

lars_the_bear wrote:
I didn't think the Pi's had a battery-backed clock at all. Or perhaps the newer ones do? If there's no battery-backed clock, I'd expect the system clock to be set to time zero at boot time, so it's going to be way out of sync.


The Raspberry Pi 5 has an RTC, but all Pi's before didn't have one. Usually you would install a package like fake-hwclock (at least on debian that's what it's called) that saves the time to a file at poweroff and reads it back at boot. That way if you're rebooting the time shouldn't be that far out of sync. Without fake-hwclock I think the time would reset to 1970 at every boot.

Or you can buy a cheap DS1307 RTC for the Pi, battery included.
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2175

PostPosted: Mon Jul 29, 2024 8:12 am    Post subject: Reply with quote

Koyan wrote:
...
You can change this behaviour in openntpd as well. From the man page:
Code:
       -S          Do not set the time immediately at startup.  This is the default.

       -s          Try to set the time immediately at startup, as opposed to slowly adjusting
                   the clock.  ntpd will stay in the foreground for up to 15 seconds  waiting
                   for one of the configured NTP servers to reply.


...

AFAIR I had the "-s"; the problem was that ntpd timed out after 15 seconds without getting the time. (Not sure why; probably something related to my DNS setup and acquiring a new DHCP lease. Probably solveable but I ran out of enthusiasm.)
The old Pi's, of which this was one, indeed have no clock (unless you buy one and put it on the GPIO pins), which is why the Pi set its time from the uk ntp pool. The Pi runs 24/7 for months on end (at least, if I forget to update the system...).

The latest Pi 5 has a clock, provided you install a battery.
_________________
Greybeard
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum