gpt4 book ai didi

azure - 使用 Azure Functions Python 批量运行记录循环

转载 作者:行者123 更新时间:2023-12-04 09:44:29 25 4
gpt4 key购买 nike

我是 Azure 新手。我需要为每条记录触发一个 azure 函数。我可以循环执行此操作,但这变成了一个顺序过程,需要时间并导致超时。相反,我希望它以并行处理模式完成。

到目前为止我的方法。

  1. 创建一个队列并将每条记录从数据库推送到队列。
  2. 根据添加到队列的消息触发该函数。

这个设置工作正常,但我觉得将记录插入队列本身就是一个顺序过程。有没有不同的方法来做到这一点。请帮忙

最佳答案

当你想为每条记录触发该函数时,队列存储触发是一个不错的选择。您可以从两个方面改进您的方法。

Azure功能部分

您可以在host.json中进行配置来控制队列处理。 queues.batchSize 旋钮是一次获取多少队列消息。

"queues": {
// The maximum interval in milliseconds between
// queue polls. The default is 1 minute.
"maxPollingInterval": 2000,
// The visibility timeout that will be applied to messages that fail processing
// (i.e. the time interval between retries). The default is zero.
"visibilityTimeout" : "00:00:30",
// The number of queue messages to retrieve and process in
// parallel (per job function). The default is 16 and the maximum is 32.
"batchSize": 16,
// The number of times to try processing a message before
// moving it to the poison queue. The default is 5.
"maxDequeueCount": 5,
// The threshold at which a new batch of messages will be fetched.
// The default is batchSize/2. Increasing this value will increase the
// level of concurrency and therefore throughput. New batches of messages
// will be pulled until the number of messages being processed is greater
// than this threshold. When the number dips below this threshold, new
// batches will be fetched.
"newBatchThreshold": 8
}

引用:

host.json settings for queues

您的代码部分

您可以使用多线程代码将记录插入队列。

引用:

threading

How to use threading in Python

关于azure - 使用 Azure Functions Python 批量运行记录循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62192184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com