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

Is it possible to only use time-sync when needed? #13

Closed elie222 closed 9 years ago

elie222 commented 10 years ago

I only need time-sync on one page on my site, but time-sync is always running, trying to sync the time on the client and server. Is there a way for me to stop this and only use time-sync when I need it?

I know time-sync is doing its thing becauseI get the following error quite often. Even when I thought I wasn't using time-sync: Clock discrepancy detected. Attempting re-sync.

mizzao commented 10 years ago

It only does that if you are using a lot of CPU and the clock check isn't called for a while because the browser thread is busy. Otherwise it only syncs once every 10 minutes by default.

Are you concerned about bandwidth here? Generally it should be very lightweight.

elie222 commented 10 years ago

Ah. Ok. I just see it as my number one error on kadira. It's not really a problem if it's only once per ten minutes On 11 Oct 2014 22:28, "Andrew Mao" notifications@github.com wrote:

It only does that if you are using a lot of CPU and the clock check isn't called for a while because the browser thread is busy. Otherwise it only syncs once every 10 minutes by default.

Are you concerned about bandwidth here? Generally it should be very lightweight.

— Reply to this email directly or view it on GitHub https://github.com/mizzao/meteor-timesync/issues/13#issuecomment-58761497 .

mizzao commented 10 years ago

I think it's suggestive of a slow user interface client-side. Does Kadira tell you if it's happening for all users, or just some subset of users?

Ethaan commented 9 years ago

@mizzao its there a way to just run 1 time, the sync? i have this code

 Tracker.autorun(function(){
    var server = TimeSync.serverTime()
    if(server !== undefined){
       Session.set("serverTime",server)
    }
 })

And this helper

var primerDia = function(){ 
    var searchMenu;
     searchMenu = Session.get("valueMenu");   
      var hora = Session.get("serverTime")
      var diaDeHoy = moment(hora).locale("es").add(0,'days').format('dddd');
  console.log(diaDeHoy)
    return Promociones.find( {$and:[{'metadata.tipoMenu' : { $in: [searchMenu] } },{'metadata.diaOferta' : { $in: [diaDeHoy] }}]}); 
}

it seems like the server and client are getting sync every 1 sec, and my helper its rendering each sec , its there a way to stop this? or maybe im doing something wrong

mizzao commented 9 years ago

The helper will invalidate every 1 second, but the sync only happens every 10 minutes in normal usage. Maybe you can help implement the idea in #10 to improve things.

mizzao commented 9 years ago

@elie222 you can now use TimeSync.loggingEnabled = false if you'd like to suppress those error messages in Kadira.

elie222 commented 9 years ago

Thanks On 11 Feb 2015 06:14, "Andrew Mao" notifications@github.com wrote:

@elie222 https://github.com/elie222 you can now use TimeSync.loggingEnabled = false if you'd like to suppress those error messages in Kadira.

— Reply to this email directly or view it on GitHub https://github.com/mizzao/meteor-timesync/issues/13#issuecomment-73831773 .