Parallel calls to a same function on Google App Engine (Concurrency)

41 views
Skip to first unread message

Amruth Kiran

unread,
Jan 29, 2019, 2:43:38 PM1/29/19
to Google App Engine

I am trying to build a web app on Google App Engine (GAE) using python and Flask. I want to know how to call a function within the app multiple times simultaneously. For example, I have a function which returns the square of an element. Now, I wrap this function under a URL like this:

@app.route('/single_number',methods = ['GET','POST'])
def square():
    x
= request.form.get('input_number')
   
return x*x

Now, I want to do this on a list of numbers but concurrently on 'http://localhost:8080/list_of_numbers'. Say, I have a list of 'n' numbers and I want to calculate the square of each number simultaneously (if not all 'n' together but at least what Google App Engine allows). I have used multiprocessing library of Python but got no performance improvement because of the single core used in Google App Engine instance and apparently, multithreading is equally futile. So, upon reading some more I was led to Cloud Tasks of GAE. But I am not able to wrap my head around executing this on Cloud Tasks. Any sample/tutorial related to this will be greatly appreciated. If you think that Cloud Tasks is not the right way for this problem, is it possible to create a function under handler '/list_of_numbers', which will send multiple numbers of the list to the '/single_number' handler simultaneously? Or do you suggest any other method?

I am new to web-app building and GAE. So, any help would be greatly appreciated.

Thanks in advance

George (Cloud Platform Support)

unread,
Jan 29, 2019, 4:22:04 PM1/29/19
to Google App Engine
Hello Amruth, 

You could pass the whole list as an array in a call to your function, as described in the "Passing arrays via HTTP GET?" posting in Groups. You'll be able then to process your list at once. 

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching the app engine. For coding and programming architecture, as well as parallel processing in Cloud Functions, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help.
Reply all
Reply to author
Forward
0 new messages