Google Application Engine is slow in case of Python

I am reading a “table” in Python in GAE, which has 1000 rows, and the program stops because the deadline has been reached. (So ​​it takes at least 20 seconds.) (Is it possible that GAE is so slow? Is there a way to fix this? Is it because I use a free service and I don’t pay for it?

Thank.

Code itself:

 liststocks=[]
 userall=user.all() # this has three fields username... trying to optimise by this line
 stocknamesall=stocknames.all() # 1 field, name of the stocks trying to optimise by this line too
 for u in userall: # userall has 1000 users
        for stockname in stocknamesall: # 4 stocks
            astock= stocksowned() #it is also a "table", no relevance I think
            astock.quantity = random.randint(1,100)
            astock.nameid = u.key()
            astock.stockid = stockname.key()
            liststocks.append(astock);
+3
source share
1 answer

GAE is slower when used inefficiently. Like any infrastructure, sometimes you need to learn a little about how it works in order to use it effectively. Fortunately, I think there is a slight improvement that will help your code a lot.

fetch() . " " - " " , . fetch(), . , fetch(), , .

fetch() - users stocknames . !

( , 1000 , fetch(1000), , ; ):

userall=user.all().fetch(1000)
stocknamesall=stocknames.all().fetch(1000)
# rest of the code as-is

, , AppStats, . ( ) appstats .

+8

Source: https://habr.com/ru/post/1748732/


All Articles