get_result() 是 Google App Engine 中 put_async() 所需的调用吗

发布于 2024-11-08 15:28:08 字数 446 浏览 1 评论 0 原文

随着 GAE 1.5.0 的新版本,我们现在有了一种简单的方法来执行异步数据存储调用。调用后是否需要调用get_result()put_async”?

例如,如果我有一个名为 MyLogData 的模型,我可以

put_async(MyLogData(text="My Text"))

在处理程序返回之前调用:而不调用匹配的 get_result() 吗? 在将结果发送给客户端之前,GAE 是否会自动阻止任何待处理的调用?

请注意,我并不真正关心处理错误情况。也就是说,我不介意其中一些看跌期权是否失败。

With the new release of GAE 1.5.0, we now have an easy way to do async datastore calls. Are we required to call get_result() after calling
'put_async'?

For example, if I have an model called MyLogData, can I just call:

put_async(MyLogData(text="My Text"))

right before my handler returns without calling the matching get_result()?
Does GAE automatically block on any pending calls before sending the result to the client?

Note that I don't really care to handle error conditions. i.e. I don't mind if some of these puts fail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你没皮卡萌 2024-11-15 15:28:08

我认为没有任何确定的方法可以知道是否需要 get_result() ,除非 GAE 团队中的某人验证了这一点,但我认为不需要。这是我测试的方法。

我编写了一个简单的处理程序:

class DB_TempTestModel(db.Model):
    data = db.BlobProperty()

class MyHandler(webapp.RequestHandler):
    def get(self):
        starttime = datetime.datetime.now()
        lots_of_data = ' '*500000
        if self.request.get('a') == '1':
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
        if self.request.get('a') == '2':
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
        self.response.out.write(str(datetime.datetime.now()-starttime))

我在高复制应用程序上运行了很多次。

数据总是在那里,让我相信除非数据存储方面出现故障(不太可能),否则它会被写入。

这是有趣的部分。当使用 put_async() (?a=2) 写入数据时,(处理请求)的时间量平均大约快 2 到 3 倍如 put()(?a=1) (不是一个非常科学的测试 - 只是目测它)。

?a=1?a=2cpu_msapi_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:

class DB_TempTestModel(db.Model):
    data = db.BlobProperty()

class MyHandler(webapp.RequestHandler):
    def get(self):
        starttime = datetime.datetime.now()
        lots_of_data = ' '*500000
        if self.request.get('a') == '1':
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
            db.put(DB_TempTestModel(data=lots_of_data))
        if self.request.get('a') == '2':
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
            db.put_async(DB_TempTestModel(data=lots_of_data))
        self.response.out.write(str(datetime.datetime.now()-starttime))

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 as put()(?a=1) (not a very scientific test - just eyeballing it).

But the cpu_ms and api_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?

溺ぐ爱和你が 2024-11-15 15:28:08

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 without get_result when deployed (in fire-and-forget style) but in locally it won't take action until get_result gets called more context

佞臣 2024-11-15 15:28:08

我不知道,但这可行:

import datetime
from google.appengine.api import urlfetch

def main():
  rpc = urlfetch.create_rpc()
  urlfetch.make_fetch_call(rpc, "some://artificially/slow.url")
  print "Content-type: text/plain"
  print
  print str(datetime.datetime.now())

if __name__ == '__main__':
  main()

远程 URL 休眠 3 秒,然后向我发送一封电子邮件。 App Engine 处理程序立即返回,并且远程 URL 按预期完成。由于这两种服务都抽象了相同的底层 RPC 框架,因此我猜测数据存储的行为类似。

不过,这是个好问题。也许尼克或另一位谷歌员工可以给出明确的答案。

I dunno, but this works:

import datetime
from google.appengine.api import urlfetch

def main():
  rpc = urlfetch.create_rpc()
  urlfetch.make_fetch_call(rpc, "some://artificially/slow.url")
  print "Content-type: text/plain"
  print
  print str(datetime.datetime.now())

if __name__ == '__main__':
  main()

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文