views:

122

answers:

2

Is there a way I can figure out the time the current request reached the app engine?

For example a user might make a request to my app, but due to app engine latencies my code might not start handling the request until one second later, is there a way I can figure out that the user has already had to wait one second?

The reason I want to know how to do this is because I want to do different things based on if the user already had to wait. If the user already had to wait a significant amount of time I will just serve them a page out of the cache, if the user hasn't had to wait yet then I will serve them a page which takes a while to render.

A: 

You can send a timestamp param with the request and measure the difference, but to be sure for the result you have to send timestamp from the server, increment it in the client, send it back, calculate the difference between the timestamp and the current time on the server, divide it in 2 (cause you have 2 request, one setting the timestamp, and one retrieving it back). But this will be only rough calculation.

Ilian Iliev
+1  A: 

The short and unsatisfying answer to your question is no, you cannot figure out how long the user has waited.

There are no guarantees in the app engine on the consistency of the server clocks. You could attempt to calculate a drift from the client clock to the server clock and submit that drift as a parameter along with the client timestamp. However, since there is no guarantee of intra-server time consistency, that drift is only applicable for the server you calculated it from. The closest I believe you can get is a calculated drift time from the server based on several samples of latency and returned timestamps, but as soon as the server changes your calculation will no longer be accurate.

Simply sampling the time when the request arrives will not help you either, especially since cold starts on the app engine will result in increased latency that cannot be measure by your code.

Michael