question

Boolean Fiasco avatar image
Boolean Fiasco asked

Misleading CloudScript example function due to expected server clock drift

I'll start by saying that I've searched the forum previously and found a few threads that indicate that using Date.now() within a CloudScript function should expect the resulting time to vary by as much as 30 seconds due to clock drift between the various servers. My personal experimentation backs this up (though I've only seen results in the 20 seconds range at most so far).

However, in the CloudScript example, the processPlayerMove() function uses a 15 seconds cooldown and compares stored Date.now() timestamps in order to verify that moves aren't made too frequently. This is an extremely misleading example since, in practice, you can't possibly use a cooldown that short and expect that function to work correctly most of the time.

I think that example function should be replaced by something else or, at least, have a clearly stated warning that you can't actually use that pattern in a real game.

As a possible workaround, my experimental testing seems to show that the LastUpdated field has a drift of not much more than 5 seconds (given a hundred or so tests I did). Is it accurate to say that the database servers have tighter clock tolerances, or should I ultimately expect them to sometimes be off by as much as the CloudScript servers are?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Good news! As of our latest update, we've managed to get the clock drift down considerably. In fact, we're down to max of 1 second of drift between servers, so depending on your scenario, you should be able to tighten up the times you use in your logic checks. I'll also promote this to be the top answer, so that folks finding this thread for the first time have the latest info.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Thanks, that's a really good point. I've opened a bug with the tools team to sync with our operations team and make sure that the tolerances in the scripts are set to levels that are guaranteed based upon our current configuration.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Boolean Fiasco avatar image
Boolean Fiasco answered

Thanks! I think that'll be helpful to others in the future. I was having trouble with a similar function I'd made myself but assumed I was doing something wrong since one of the example functions used similar tolerances.

Do you have any information regarding my speculation at the end? It seems like the database timestamps might have a tighter tolerance window, and since I'm changing data anyway as part of the process I want to time it would be possible for me to use those values instead.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.