开发者

Google App Engine populating datastore entries

开发者 https://www.devze.com 2023-02-07 12:22 出处:网络
I wa开发者_开发百科nt to populate my datastore with some values. What is the best way to do this ?

I wa开发者_开发百科nt to populate my datastore with some values. What is the best way to do this ? This is my code -

for n in range(seqlen):
  for m in range(n+1):
    for l in range(m+1):
      temp = [-BIGINT for k in range(m-l+1)]
      obj = DbEntity4D(key_name=str(n)+','+str(m) +','+ str(l))
      obj.value = temp
      obj.put()

or is this one better ?

for n in range(seqlen):
  for m in range(n+1):
    for l in range(m+1):
      temp = [-BIGINT for k in range(m-l+1)]
      obj[i] = DbEntity4D(key_name=str(n)+','+str(m) +','+ str(l))
      obj[i].value = temp
      i = i+1

    db.put(obj)

Or is there any other better way ?

seqlen can be 1 to 1000. It may not be able to finish this whole process in 10 mins but I can continue from where I left previously in my next task.


Batching datastore puts will save a significant amount of time by eliminating round-trips to the datastore.

It looks like you're trying to do this with your latter block of code (saving m entities at a time). In the case where seqlen is 1000, you'll write up to 1000 entities at a time. However, the number entities written at once varies since your innermost for loop varies in how many entities it produces. It might be faster still if you wait to save to the database until you've collected n (some large number) of DbEntity4D entities, and then save them (rather than always saving them immediately after your innermost loop). Of course, this might complicate the logic which allows the next task to resume adding creating these entities where a previous task left off.

0

精彩评论

暂无评论...
验证码 换一张
取 消