Meteor-Community-Packages / meteor-timesync

NTP-style time synchronization between server and client, and facilities to use server time reactively in Meteor applications.
https://packosphere.com/mizzao/timesync
MIT License
118 stars 36 forks source link

Re-sync message in console #24

Open steph643 opened 9 years ago

steph643 commented 9 years ago

Each time my app uses the CPU intensively for a few seconds, I get the following message in the console:

Clock discrepancy detected. Attempting re-sync.

This brings me two questions:

  1. How does CPU activity relate to sync lost?
  2. My understanding was that TimeSync.watchClockChanges was false by default, preventing re-sync to occur. I tried to force it to false anyway, but it has no effect. How can I prevent re-sync?
mizzao commented 9 years ago

TimeSync uses a setInterval to check if there are unexpected differences in time each tick, such as the user waking their computer up from sleep, changing system time, etc.

https://github.com/mizzao/meteor-timesync/blob/master/timesync-client.js#L23

CPU busyness causes a setInterval to fire after longer than expected, which makes it look like there was an unexpected time change. I'm not sure if there is an easy way around this, but I'm all ears if you have suggestions.

If you don't like the log messages, you can set TimeSync.loggingEnabled = false, but there's no way to prevent re-syncing at the moment.

steph643 commented 9 years ago

Thanks for pointing me to loggingEnabled.

crsssl commented 9 years ago

Hi Andrew. Where do you think is the best place to put the TimeSync.loggingEnabled = false statement? Anywhere, or client Meteor.startup() ?

mizzao commented 9 years ago

It only logs on the client, but you can put it anywhere in a client folder, preferably in lib so it runs immediately. No Meteor.startup() needed.

v3rron commented 9 years ago
// client/init.js
Meteor.startup(function () {
  TimeSync.loggingEnabled = false;
});

Error: ReferenceError: Can't find variable: TimeSync

mizzao commented 9 years ago

meteor add mizzao:timesync to make it explicitly available in the top level of your app.

BeSports commented 8 years ago

but there's no way to prevent re-syncing at the moment.

Any updates on this? I'm using it for that chat part of my app, and just want to use the server time once (in my add-chat stub, to prevent jumping of chatlines). And I'm just afraid that this will put extra strain on my server, no?

mizzao commented 8 years ago

No I don't think it materially puts extra strain on your server.