get_result() 是 Google App Engine 中 put_async() 所需的调用吗
随着 GAE 1.5.0 的新版本,我们现在有了一种简单的方法来执行异步数据存储调用。调用后是否需要调用get_result()
“put_async”?
例如,如果我有一个名为 MyLogData
的模型,我可以
put_async(MyLogData(text="My Text"))
在处理程序返回之前调用:而不调用匹配的 get_result()
吗?
在将结果发送给客户端之前,GAE 是否会自动阻止任何待处理的调用?
请注意,我并不真正关心处理错误情况。也就是说,我不介意其中一些看跌期权是否失败。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为没有任何确定的方法可以知道是否需要
get_result()
,除非 GAE 团队中的某人验证了这一点,但我认为不需要。这是我测试的方法。我编写了一个简单的处理程序:
我在高复制应用程序上运行了很多次。
数据总是在那里,让我相信除非数据存储方面出现故障(不太可能),否则它会被写入。
这是有趣的部分。当使用
put_async()
(?a=2
) 写入数据时,(处理请求)的时间量平均大约快 2 到 3 倍如put()
(?a=1
) (不是一个非常科学的测试 - 只是目测它)。但
?a=1
和?a=2
的cpu_ms
和api_cpu_ms
是相同的。从日志中:
ms=440 cpu_ms=627 api_cpu_ms=580 cpm_usd=0.036244
与
ms=149 cpu_ms=627 api_cpu_ms=580 cpm_usd=0.036244
在客户端,查看请求的网络延迟,它显示了相同的结果,即“?a=2”请求至少快了 2 倍。绝对是客户端的胜利......但它似乎在服务器端没有任何增益。
GAE 团队中有人愿意发表评论吗?
I don't think there is any sure way to know if
get_result()
is required unless someone on the GAE team verifies this, but I think it's not needed. Here is how I tested it.I wrote a simple handler:
I ran it a bunch of times on a High Replication Application.
The data was always there, making me believe that unless there is a failure in the datastore side of things (unlikely), it's gonna be written.
Here's the interesting part. When the data is written with
put_async()
(?a=2
), the amount of time (to process the request) was on average about 2 to 3 times as fast asput()
(?a=1
) (not a very scientific test - just eyeballing it).But the
cpu_ms
andapi_cpu_ms
were the same for both?a=1
and?a=2
.From the logs:
ms=440 cpu_ms=627 api_cpu_ms=580 cpm_usd=0.036244
vs
ms=149 cpu_ms=627 api_cpu_ms=580 cpm_usd=0.036244
On the client side, looking at the network latency of the requests, it showed the same results, i.e. `?a=2' requests were at least 2 times faster. Definitely a win on the client side... but it seems to not have any gain on the server side.
Anyone on the GAE team care to comment?
db.put_async
在没有get_result
部署时(以“即发即弃”风格)的情况下工作正常,但在 本地,在调用 get_result 不会采取任何操作="https://stackoverflow.com/questions/7244081/appengine-put-async-doesnt-work-at-least-in-the-development-server/7250613#7250613">更多上下文db.put_async
works fine withoutget_result
when deployed (in fire-and-forget style) but in locally it won't take action untilget_result
gets called more context我不知道,但这可行:
远程 URL 休眠 3 秒,然后向我发送一封电子邮件。 App Engine 处理程序立即返回,并且远程 URL 按预期完成。由于这两种服务都抽象了相同的底层 RPC 框架,因此我猜测数据存储的行为类似。
不过,这是个好问题。也许尼克或另一位谷歌员工可以给出明确的答案。
I dunno, but this works:
The remote URL sleeps 3 seconds and then sends me an email. The App Engine handler returns immediately, and the remote URL completes as expected. Since both services abstract the same underlying RPC framework, I would guess the datastore behaves similarly.
Good question, though. Perhaps Nick or another Googler can answer definitively.