google-app-engine - 通过 Google App Engine 后端批量下载

标签 google-app-engine google-cloud-datastore bulkloader

我想要下载 Google App Engine 应用程序中的 160 万个实体。我尝试使用内置的批量加载机制,但发现它非常慢。虽然我只能通过批量加载器每秒下载约 30 个实体,但通过后端查询数据存储,我可以每秒下载约 500 个实体。需要后端来规避 60 秒的请求限制。此外,数据存储查询最多只能存活 30 秒,因此您需要使用查询游标在多个查询中分解提取。

服务器端的代码获取 1000 个实体并返回查询游标:

cursor = request.get('cursor')
devices = Pushdev.all()

if (cursor and cursor!=''):
    devices.with_cursor(cursor)

next1000 = devices.fetch(1000)

for d in next1000:
    t = int(time.mktime(d.created.timetuple()))
    response.out.write('%s/%s/%d\n'%(d.name,d.alias,t))

response.out.write(devices.cursor())

在客户端,我有一个循环,它以空游标开始调用服务器上的处理程序,然后开始传递上一次调用收到的游标。当它得到空结果时它终止。

问题:我只能使用此方法获取一小部分 - ~20% 的实体。即使尚未遍历完整的实体集,我也会收到空数据的响应。为什么这个方法不能全面获取所有内容?

最佳答案

我在文档中找不到任何内容来确认或否认这一点,但我的猜测是 all() 具有不确定的顺序,因此最终您的 fetch( 1000) 将命中“最后一个元素”,并且 devices.cursor() 将不返回任何内容。

试试这个:

devices = Pushdev.all().order('__key__')

关于google-app-engine - 通过 Google App Engine 后端批量下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16362822/

相关文章:

node.js - 仅在特定时间运行一次 Google Cloud Function

google-app-engine - 如何在 Google App Engine for Go 中设置数据 fixture

python - 迁移 NDB 模型属性的正确方法

google-app-engine - Google 应用引擎批量加载程序在上传时打开空文件

google-app-engine - Google AppEngine Bulkloader 高复制数据延迟

java - Memcache服务过期

google-app-engine - 无法为 eclipse (indigo) 安装 google app engine 插件

google-app-engine - Google Datastore 中的索引号是否有最大大小

google-app-engine - 使用数据存储 (NDB)、搜索 API 或两者来查看数据?