谷歌App Engine任务队列如何工作?

2024-10-04 05:32:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我对使用队列执行任务感到困惑。我已经阅读了文档,我想我了解bucket_的大小和速率,但是当我将20个任务发送到一个设置为5/h、大小为5的队列时,所有20个任务都会以最快的速度逐个执行,在不到1分钟内完成。在

deferred.defer(spam.cookEggs, 
               egg_keys, 
               _queue="tortoise")  

- name: tortoise
  rate: 5/h  
  bucket_size: 5  

我想要的是无论我创建10个还是100个任务,我只希望每小时运行5个任务。所以要完成20个任务大约需要4个小时。我要把他们的死刑分散开来。在

更新

问题是,我假设在本地运行时,任务执行率规则是遵循的,但事实并非如此。不能在本地测试执行率。当我部署到生产环境中时,我设置的速率和bucket大小如我所预期的那样执行。在


Tags: name文档bucket队列queueegg速率keys
2条回答

app_devserver不考虑执行率。生产中不应出现此问题。在

[答案由Nick Johnson和/或问题作者发现;以社区wiki的形式发布在这里,以便我们可以标记为已接受的内容]

您希望将bucket_size设置为1,否则您将出现“突发”的排队活动,就像您在那里看到的那样。在

documentation

bucket_size

Limits the burstiness of the queue's processing, i.e. a higher bucket size allows bigger spikes in the queue's execution rate. For example, consider a queue with a rate of 5/s and a bucket size of 10. If that queue has been inactive for some time (allowing its "token bucket" to fill up), and 20 tasks are suddenly enqueued, it will be allowed to execute 10 tasks immediately. But in the following second, only 5 more tasks will be able to be executed because the token bucket has been depleted and is refilling at the specified rate of 5/s.

相关问题 更多 >