title: Async urlfetch on App Engine
body: <p>My app needs to do many datastore operations on each request.  I'd like to run them in parallel to get better response times.</p>
  
  <p>For datastore updates I'm doing batch puts so they all happen asynchronously which saves many milliseconds.  App Engine allows <a href="http://code.google.com/appengine/docs/python/datastore/overview.html#Quotas_and_Limits" rel="nofollow noreferrer">up to 500 entities</a> to be updated in parallel.</p>
  
  <p>But I haven't found a built-in function that allows datastore fetches of different kinds to execute in parallel.</p>
  
  <p>Since App Engine does allow urlfetch calls <a href="http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html" rel="nofollow noreferrer">to run asynchronously</a>, I created a getter URL for each kind which returns the query results as JSON-formatted text.  Now my app can do async urlfetch calls to these URLs which could parallelize the datastore fetches.</p>
  
  <p>This technique works well with small numbers of parallel requests, but App Engine throws errors when attempting to run more than 5 or 10 of these urlfetch calls at the same time.</p>
  
  <p>I'm only testing now, so each urlfetch is the identical query; since they work fine in small volumes but start failing with more than a handful of simultaneous requests, I'm thinking it must have something to do with the async urlfetch calls.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Is there a limit to the number of urlfetch.create_rpc() calls that can run asynchronously?</li>
  <li>The synchronous urlfecth.fetch() function has a 'deadline' parameter that will allow the function to wait up to 10 seconds for a response before failing.  Is there any way to tell urlfetch.create_rpc() how long to wait for a response?</li>
  <li>What do the errors shown below mean?</li>
  <li><p>Is there a better server-side technique to run datastore fetches of different kinds in parallel?</p>
  
  <p>File "/base/python_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 501, in get_result
      return self.__get_result_hook(self)
    File "/base/python_lib/versions/1/google/appengine/api/urlfetch.py", line 331, in _get_fetch_result
      raise DownloadError(str(err))
  InterruptedError: ('The Wait() request was interrupted by an exception from another callback:', DownloadError('ApplicationError: 5 ',))</p></li>
  </ol>