1

The Traces graph showed /images.GetUrlBase calls for my search function. I tried to make it call get_serving_url () in parallel but still the Traces graph shows the calls as sequential.
How do I make it parallel ?

enter image description here

My Attempt

class Gets 
    @staticmethod 
    @ndb.tasklet 
    def get_img_url_parallel ( image_key ): 
        url     = yield images.get_serving_url_async (image_key) 
        raise ndb.Return ( url ) 


@toplevel 
def search (..): 
    :: 
    for record in record_list: 
        :: 
        for photo in record.photo_list: 
            if (photo != ""): 
                yielded_photo   = yield Gets.get_img_url_parallel ( photo ) 
                photo_list.append ( yielded_photo  ) 
::

I am new to yield, tasklet.

gsinha
  • 1,165
  • 2
  • 18
  • 43
  • I wonder why you have two yields? – Tim Hoffman Dec 06 '15 at 12:03
  • @TimHoffman Since decorator `@ndb.tasklet` causes sub `get_img_url_parallel` to return a `Future`, I thought I either need to call `get_result()` or `yield` to get the actual value. What is the right way to do it ? – gsinha Dec 06 '15 at 12:12
  • 1
    You certainly don't call yield twice - though it's probably not the issue. Have a look at https://cloud.google.com/appengine/docs/python/ndb/async – Tim Hoffman Dec 06 '15 at 12:26
  • @TimHoffman I went through it and was not able to understand how to use it in my scenario mentioned above. I would again try and get back. – gsinha Dec 10 '15 at 16:30
  • I don't understand what you don't understand. The docs are pretty clear, in addition this article covers using urlfetch asynchronously https://cloud.google.com/appengine/docs/python/urlfetch/asynchronousrequests – Tim Hoffman Dec 11 '15 at 10:47
  • @TimHoffman Thanks for the tip. I was able to figure it out ( finally ). The documentation was confusing to me since it tells about NDB but I later understood it after repeated iterations. I would post the solution later with proper explanation. – gsinha Dec 15 '15 at 12:43
  • I wonder why is this related to ndb? We dont do any datastore related stuff – glmvrml Jul 05 '16 at 13:41

0 Answers0