簡體   English   中英

Google AppEngine - 大數據存儲區讀取

[英]Google AppEngine - Big datastore reads

我需要閱讀Google AppEngine數據存儲區中的所有條目才能進行一些初始化工作。 有很多實體(目前為80k)並且這種情況繼續增長。 我開始達到30秒的數據存儲區查詢超時限制。

是否有關於如何在數據存儲區中對這些類型的大型讀取進行分片的最佳實踐? 任何例子?

您可以通過以下幾種方式解決這個問題:

  1. Task Queue上執行你的代碼,它有10分鍾超時而不是30秒(實際上更像是60秒)。 最簡單的方法是通過DeferredTask

    警告 :DeferredTask必須是可序列化的,因此很難傳遞復雜的數據。 也不要讓它成為一個內在的階級。

  2. 后端 后端實例提供的請求沒有時間限制。

  3. 最后,如果你需要分解一個大任務並且並行執行而不是看mapreduce

StackExchange上的這個答案很好地為我服務:

過期的查詢和appengine

我不得不稍微修改它以適合我:

def loop_over_objects_in_batches(batch_size, object_class, callback):

    num_els = object_class.count() 
    num_loops = num_els / batch_size
    remainder = num_els - num_loops * batch_size
    logging.info("Calling batched loop with batch_size: %d, num_els: %s, num_loops: %s, remainder: %s, object_class: %s, callback: %s," % (batch_size, num_els, num_loops, remainder, object_class, callback))    
    offset = 0
    while offset < num_loops * batch_size:
        logging.info("Processing batch (%d:%d)" % (offset, offset+batch_size))
        query = object_class[offset:offset + batch_size]
        for q in query:
            callback(q)

        offset = offset + batch_size

    if remainder:
        logging.info("Processing remainder batch (%d:%d)" % (offset, num_els))
        query = object_class[offset:num_els]
        for q in query:
            callback(q)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM