views:

109

answers:

2

I have a subscription system that allows users to subscribe to things or people they are interested in, and receive notifications when new posts or files or images are submitted. To determine whether something is new, I track their views by tstamp. The problem is that if the webserver and the MySQL database are out of sync, a user could miss content that is posted at around the same time they view an item. or be shown an item twice.

I can eliminate this problem by retrieving tstamp from the database, but that is a lot of connections to the database just to get a tstamp. If I could regularly sync the system clocks of the webservers to our db server (as well as possible, at least), I could at least significantly minimize the problem. Does anyone have any advice regarding the best way to do this?

I am reluctant to enter the view time into the database using NOW(). I record the views with a Gearman Process, which would mean that there is always a slight delay in entering the view. However, generally, this delay is minimal, and it might be smaller than the difference between the system clocks, assuming I can't get regular syncing going.

+5  A: 

Enable NTP.

chkconfig ntpd on
service ntpd start

You may want to setup time servers in /etc/ntp.conf, or use the default config that uses *.fedora.pool.ntp.org.

Juliano
A: 

For me I just added a script to my crontab. Quick and simple if you have multiple servers to configure.

30 6 * * * root /usr/sbin/ntpdate -u ntp.ubuntu.com
The Digital Ninja
The problem with this is that `ntpdate` doesn't preserve monotonicity of the clock, which can confuse system services.
daf