运行 使用 Azure Functions 在批处理中遍历记录 Python
Running a loop through records in a batch with Azure Functions Python
我是 Azure 的新手。我需要为每条记录触发一个 azure 函数。我可以循环执行,但这变成了一个顺序过程,需要时间并导致超时。相反,我希望它以并行处理模式完成。
到目前为止我的方法。
- 创建一个队列并将每条记录从数据库推送到队列。
- 根据添加到队列中的消息触发函数。
这个设置工作正常,但我觉得将记录插入队列本身是一个顺序过程。有没有不同的方法来做到这一点。请帮助
如果你想为每条记录触发函数,队列存储触发器是一个不错的选择。您可以在两个方面改进您的方法。
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
}
参考:
你的代码部分
您可以使用多线程代码将记录插入队列。
参考:
How to use threading in Python
我是 Azure 的新手。我需要为每条记录触发一个 azure 函数。我可以循环执行,但这变成了一个顺序过程,需要时间并导致超时。相反,我希望它以并行处理模式完成。
到目前为止我的方法。
- 创建一个队列并将每条记录从数据库推送到队列。
- 根据添加到队列中的消息触发函数。
这个设置工作正常,但我觉得将记录插入队列本身是一个顺序过程。有没有不同的方法来做到这一点。请帮助
如果你想为每条记录触发函数,队列存储触发器是一个不错的选择。您可以在两个方面改进您的方法。
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
}
参考:
你的代码部分
您可以使用多线程代码将记录插入队列。
参考:
How to use threading in Python