App Engine:是否time.sleep()计入我的配额? [英] App Engine: Is time.sleep() counting towards my quotas?

查看:109
本文介绍了App Engine:是否time.sleep()计入我的配额?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿。我正在开发一个App Engine应用程序,其中涉及对Google地图API进行地理编码查询。 Google地图不喜欢太多的请求,所以我在每个请求之间用 time.sleep(1)放置1秒的延迟。



我注意到我的GAE仪表板中的配额不足,并决定进行一个简短的测试:

导入cProfile 
导入时间
$ b $ def foo():
time.sleep(3)

cProfile。 run('foo()')

这给了我以下输出:

  3.003 CPU秒中的4个函数调用
命令:标准名称

ncalls tottime percall cumtime percall filename:lineno (函数)
1 0.000 0.000 3.003 3.003 stdin> 1(foo)
1 0.000 0.000 3.003 3.003< string>:1(< module>)
1 0.000 0.000 0.000 0.000 {''''禁用'_lsprof.Profiler'对象的方法}
1 3.003 3.003 3.003 3.003 {time.sleep}

所以它表示它对于 time.sleep(3)消耗3个CPU秒。现在我想知道这样的电话是否被GAE提供的配额限制计算在内。如果是这样,那么在API调用地理编码的时候又有什么延迟?

谢谢。

解决方案

你当然不希望在一个完全从头开始设计的系统中尝试入睡,以尽可能最短的时间完成请求:D



您可以做的是为每个地理编码创建一个任务(请查看延期库)。您需要为此任务指定一个队列,然后将队列上的速率限制设置为您感觉地图地理编码器可能会感到满意的任何内容。



通过这种方式,每个地理编码都会运行,并且永远不会超过您设置的速率限制,而且您不需要进行任何管道设置。


Hey. I'm working on an App Engine app that involves queries to the Google Maps API for geocoding. Google Maps doesn't like too much requests so I put a 1 second delay between each request with time.sleep(1).

I noticed that my quotas are running low in my GAE dashboard and decided to run a short test:

import cProfile
import time

def foo():
    time.sleep(3)

cProfile.run('foo()')

Which gave me the following output:

   4 function calls in 3.003 CPU seconds
   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    3.003    3.003 <stdin>:1(foo)
        1    0.000    0.000    3.003    3.003 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
        1    3.003    3.003    3.003    3.003 {time.sleep}

So it says that it's consuming 3 CPU seconds for a time.sleep(3). Now I'm wondering if calls like these are counted towards the quota limits that GAE provides. And if it does, what is the other way of making delays between API calls for geocoding?

Thanks.

解决方案

You certainly don't want to be trying to sleep in a system that's designed completely from the ground up to finish requests in the absolute shortest time possible :D

What you could do instead, is create a task for each geocode, (check out the deferred library). You'd want to specify a queue for this task, then just set the rate limit on the queue to whatever you feel the maps geocoder might be comfortable with.

This way every geocode will run, and you'll never go faster than the rate limit you set, and you don't need to do any plumbing.

这篇关于App Engine:是否time.sleep()计入我的配额?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆