google-app-engine - Google App Engine 超时 : The datastore operation timed out, 或数据暂时不可用

标签 google-app-engine timeout google-cloud-datastore deferred

这是一个常见的异常,我每天都会在我的应用程序日志中获取,通常一天 5/6 次,访问量为 1K 次/天:

db error trying to store stats
Traceback (most recent call last):
  File "/base/data/home/apps/stackprinter/1b.347728306076327132/app/utility/worker.py", line 36, in deferred_store_print_statistics
    dbcounter.increment()
  File "/base/data/home/apps/stackprinter/1b.347728306076327132/app/db/counter.py", line 28, in increment
    db.run_in_transaction(txn)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore.py", line 1981, in RunInTransaction
    DEFAULT_TRANSACTION_RETRIES, function, *args, **kwargs)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore.py", line 2067, in RunInTransactionCustomRetries
    ok, result = _DoOneTry(new_connection, function, args, kwargs)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore.py", line 2105, in _DoOneTry
    if new_connection.commit():
  File "/base/python_runtime/python_lib/versions/1/google/appengine/datastore/datastore_rpc.py", line 1585, in commit
    return rpc.get_result()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 530, in get_result
    return self.__get_result_hook(self)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/datastore/datastore_rpc.py", line 1613, in __commit_hook
    raise _ToDatastoreError(err)
Timeout: The datastore operation timed out, or the data was temporarily unavailable.

引发上述异常的函数如下:

def store_printed_question(question_id, service, title):
    def _store_TX():
        entity = Question.get_by_key_name(key_names = '%s_%s' % \
                                         (question_id, service ) )
        if entity:
            entity.counter = entity.counter + 1                
            entity.put()
        else:
            Question(key_name = '%s_%s' % (question_id, service ),\ 
                          question_id ,\
                          service,\ 
                          title,\ 
                          counter = 1).put()
    db.run_in_transaction(_store_TX)

基本上,store_printed_question 函数会检查给定的问题之前是否已打印,在这种情况下会在单个事务中递增相关计数器。
此函数由 WebHandler 添加到 deferred使用预定义 的工作人员 default 队列,如您所知,其吞吐量为每秒五次任务调用。

在具有六个属性(两个索引)的实体上,我认为使用 transactions由延迟任务速率限制调节可以让我避免数据存储超时,但是查看日志,这个错误仍然每天都出现。

我存储的这个计数器不是那么重要,所以我不担心这些超时;无论如何,我很好奇为什么 Google App Engine 即使以每秒 5 个任务的低速率也无法正确处理此任务,如果降低速率可能是一个可能的解决方案。
sharded counter在每个问题上避免超时对我来说都太过分了。

编辑:
我已将默认队列的速率限制设置为每秒 1 个任务;我仍然遇到同样的错误。

最佳答案

查询只能存在 30 秒。请参阅我对 this question 的回答一些使用游标分解查询的示例代码。

关于google-app-engine - Google App Engine 超时 : The datastore operation timed out, 或数据暂时不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4745538/

相关文章:

c# - 在 c# 中为 OdbcConnection (System.Data.Odbc) 设置 ConnectionTimeout 不起作用

google-app-engine - API 调用 datastore_v3.Put() 需要比可用配额更多的配额

google-app-engine - 为什么 Google 应用引擎将 URL、电话号码等识别为特殊数据类型?

java - Google App Engine 应用程序中静态文件的授权(不使用 Google 帐户)

eclipse - 在eclipse中更改jdk

php - innodb_lock_wait_timeout 增加超时

reactjs - 如何在 react 功能组件中进行超时然后清除超时?

java - 下载 Google App Engine 数据库

google-app-engine - 什么是 Google Cloud Endpoints 的 Web 应用程序客户端 ID?

java - 如何通过 Google Endpoints Api 注释声明 200 之后的其他响应?