Asynchronous URLfetch Google Analytics. What happens when I don't call get_result()

142 views
Skip to first unread message

Albert

unread,
Aug 4, 2010, 6:33:34 AM8/4/10
to Google App Engine
Hi!

I'm using Google Analytics for Mobile Browsers wherein I connect with
Google Analytics servers via my appengine app to track users.

For performance reasons, I'm thinking of using asynchronous URLfetch
to call the google analytics tracking url near the "middle" of my
request handler code.

Well, I'm not really interested in the result of that urlfetch, so I'm
not interested in calling get_result(). So I don't want my app to wait
for the result, and just increase the time for the user to wait. I
just want it successfully called.

The documentation for Asynchronous URLfetch (http://code.google.com/
appengine/docs/python/urlfetch/asynchronousrequests.html) states "If
the app request timer expires while the app is waiting, the call is
canceled."

What does it mean by "the call is canceled"?

My current request handler usually returns within 40-70ms (without the
urlfetch), and I'd like to keep it that way.

I haven't tested this in production. Will this be an OK practice?

Thanks!

Pieter Coucke

unread,
Aug 4, 2010, 7:19:22 AM8/4/10
to google-appengine
If you just want to call an url and you don't need the result, you can perform the url fetch in a task and just add that task to a queue from your request handler.




--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Albert

unread,
Aug 4, 2010, 9:05:05 PM8/4/10
to Google App Engine
Thanks for the reply.

That's a good solution to return a response ASAP.

But, I'm guessing that adding the urlfetch to a task would consume
extra CPU ms time.

I want a solution that returns the response ASAP and, at the same
time, consumes the least CPU resources.

I'm assuming that the docs mean that making an asynchronous urlfetch
and not calling get_result() when the app handler returns, results in
the call being "cancelled". What does "cancel" mean?

Does it mean that it will never reach the analytics service?

Thanks!

Stephen

unread,
Aug 6, 2010, 4:34:07 PM8/6/10
to Google App Engine


On Aug 4, 11:33 am, Albert <albertpa...@gmail.com> wrote:
>
> For performance reasons, I'm thinking of usingasynchronousURLfetch
> to call the google analytics trackingurlnear the "middle" of my
> request handler code.
>
> Well, I'm not really interested in the result of that urlfetch, so I'm
> not interested in calling get_result(). So I don't want my app to wait
> for the result, and just increase the time for the user to wait. I
> just want it successfully called.


This trick may still work:

http://www.reddit.com/r/AppEngine/comments/adxb9/low_level_app_engine_includes_sneaky_way_to/

Albert

unread,
Aug 8, 2010, 7:46:02 AM8/8/10
to Google App Engine
Thanks for the vid link! I learned some other good stuff from there.
However, I don't think my question was clearly answered.

I hope I get a clear response from the AppEngine Team on this one.

When I start an asynchronous urlfetch, and return my application
response without calling get_result() or wait(), I'm assuming that
either of four things can happen.

1. The url will be successfully called.
2. The url will not be successfully called.
3. The url will be called, and then "cancelled" (I don't know if this
is actually a possibility)
4. No guarantees.

So which is it?

Thanks!
> http://www.reddit.com/r/AppEngine/comments/adxb9/low_level_app_engine...

Tim Hoffman

unread,
Aug 8, 2010, 11:24:32 AM8/8/10
to Google App Engine
Hi

On Aug 8, 7:46 pm, Albert <albertpa...@gmail.com> wrote:
> Thanks for the vid link! I learned some other good stuff from there.
> However, I don't think my question was clearly answered.
>
> I hope I get a clear response from the AppEngine Team on this one.
>
> When I start an asynchronous urlfetch, and return my application
> response without calling get_result() or wait(), I'm assuming that
> either of four things can happen.
>
> 1. The url will be successfully called.
> 2. The url will not be successfully called.
> 3. The url will be called, and then "cancelled" (I don't know if this
> is actually a possibility)
> 4. No guarantees.
>
> So which is it?
>

That will depend on how far the fetch from the target url got
processed. If all the of the data has been retrieved from the other
end
then data in a buffer somewhere will be discarded. If the remote
server hasn't responded yet and the urlfetch is cancelled then you
don't
know how much has been executed on the far end. If it where a zope
server for instance whatever was requested would be processed in full
but no end point would exist to write the data back to (from the
servers point of view)

So you really can't tell if you don't check the async call with a
get_result or wait. You really have an indeterminate state.
Why not do some tests. The fact the multiple async urlfetchs can be
performed means that the requests can be made and will reach the
destination
if you don't get hit with a DeadlineExceeded before the connections
are dispatched.

Rgds

T

Albert

unread,
Aug 8, 2010, 6:39:02 PM8/8/10
to Google App Engine
Thanks!

I will do some tests. I'll posts my results here.

Enjoy!



Albert

Nick Johnson (Google)

unread,
Aug 9, 2010, 11:05:15 AM8/9/10
to google-a...@googlegroups.com
Hi Albert,

On Sun, Aug 8, 2010 at 12:46 PM, Albert <alber...@gmail.com> wrote:
Thanks for the vid link! I learned some other good stuff from there.
However, I don't think my question was clearly answered.

I hope I get a clear response from the AppEngine Team on this one.

When I start an asynchronous urlfetch, and return my application
response without calling get_result() or wait(), I'm assuming that
either of four things can happen.

1. The url will be successfully called.
2. The url will not be successfully called.
3. The url will be called, and then "cancelled" (I don't know if this
is actually a possibility)
4. No guarantees.

As the talk Stephen linked to describes, if you start an asynchronous URLFetch, and return from your handler before it completes, the URLFetch will complete and call your callback function (if any) after the response is returned to the user.

-Nick Johnson
 

So which is it?

Thanks!

On Aug 7, 4:34 am, Stephen <sdea...@gmail.com> wrote:
> On Aug 4, 11:33 am, Albert <albertpa...@gmail.com> wrote:
>
>
>
> > For performance reasons, I'm thinking of usingasynchronousURLfetch
> > to call the google analytics trackingurlnear the "middle" of my
> > request handler code.
>
> > Well, I'm not really interested in the result of that urlfetch, so I'm
> > not interested in calling get_result(). So I don't want my app to wait
> > for the result, and just increase the time for the user to wait. I
> > just want it successfully called.
>
> This trick may still work:
>
> http://www.reddit.com/r/AppEngine/comments/adxb9/low_level_app_engine...
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.




--
Nick Johnson, Developer Programs Engineer, App Engine Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: 368047
Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: 368047

Albert

unread,
Aug 9, 2010, 6:30:46 PM8/9/10
to Google App Engine
Thanks!


Albert

On Aug 9, 11:05 pm, "Nick Johnson (Google)" <nick.john...@google.com>
wrote:
> > google-appengi...@googlegroups.com<google-appengine%2Bunsubscrib e...@googlegroups.com>
> > .

Albert

unread,
Aug 11, 2010, 10:41:09 PM8/11/10
to Google App Engine
Hi!

I did some testing. I performed an asynchronous urlfetch without a
callback parameter nor did I call wait() or get_result() before I
returned the response to the user.

The analytics is being logged properly, so that's great. But I'm
getting the following warning in my logs.

"Found 1 RPC request(s) without matching response (presumably due to
timeouts or other errors)"

Is this something I should be worried about, or should I just write a
blank callback function to get rid of this warning?


Thanks!



Albert
Reply all
Reply to author
Forward
0 new messages