views:

44

answers:

1

I'm currently in the process of rewriting my java code to run it on Google App Engine. Since I cannot use Timer for programming timeouts (no thread creation allowed), I need to rely on system clock to mark the time of the timeout start so that I could compare it later in order to find out if the timeout has occurred.

Now, several people (even on Google payroll) have advised developers not to rely on system time due to the distributed nature of Google app servers and not being able to keep their clocks in sync. Some say the deviance of system clocks can be up to 10s or even more.

1s deviance would be very good for my app, 2 seconds can be tolerable, anything higher than that would cause a lot of grief for me and my app users, but 10 second difference would turn my app effectively unusable.

I don't know if anything has changed for the better since then (I hope yes), but if not, then what are my options other than shooting up a new separate request so that its handler would sleep the duration of the timeout (which cannot exceed 30 seconds due to request timeout limitation) in order to keep the timeout duration consistent.

Thanks!

More Specifically:

I'm trying to develop a poker game server, but for those who are not familiar how online poker works: I have a set of players attached to 1 game instance. Evey player has a certain amount of time to act before the timeout will occur so the next player can act. There is a countdown on each actor and every client has to see it. Only one player can act at a time. The timeout durations I need are 10s and 20s for now.

+1  A: 

You should never be making your request handlers sleep or wait. App Engine will only automatically scale your app if request handlers complete in an average of 1000ms or less; deliberately waiting will ruin that. There's invariably a better option than sleeping/waiting - let us know what you're doing, and perhaps we can suggest one.

Nick Johnson
Hello Nick, I was hoping you would reply. I'm coding a poker game in flex. In case you haven't played online poker before, I also replied to Jason explaining what the app should do using more general terms. (maybe I should update the question with more relevant information?). If there is anything else you need to know, please don't hesitate to ask for more specifics. Thanks.
jaz
Ah. From your question, I thought you were attempting to wait or sleep. While we can't provide a hard guarantee on the time sync of different machines on App Engine, it'll be in the usual bounds provided by NTP - fractions of a second. I do play online poker, so I'd love to see what you're working on when it's ready. :)
Nick Johnson
Thank you for your encouraging words, Nick :) The other idea I had was to rely on the acting client to let the server know it's turn (say 10 second duration) has ended, but at the same time keeping a guarantee of say 15 seconds on the server side using system clock in which case +/- 5 seconds would have very little impact. However based on what you said I think I will skip this step for now and see how it goes. App Engine sure makes things a bit difficult for me, but I hope it will all be worth it at the end. You'll be one of the first ones to see the app, when it's ready :)
jaz
@jaz I would suggest something along those lines anyway, because small variations and network latency will still be noticeable to a user. That is, I would have the client display the remaining time independently, and have the server track this separately, with a small grace period as you suggest.
Nick Johnson