azure - 如何限制并发 Azure Function 执行
问题描述
我已经看到这个问题表达了很多,但我还没有找到一个可行的解决方案。
简而言之,我定期有大量的处理操作要做。每个操作都由 Azure 函数处理。每个操作都会调用数据库。如果我有太多的并发函数同时运行,这会使数据库过载并且我得到超时错误。因此,我希望能够限制一次运行的并发 Azure 函数调用的数量。
我已将函数切换为队列触发,并根据我在网上看到的内容以多种方式调整了 batchSize / newBatchThreshold / maxDequeueCount host.json 设置。我还在函数应用程序设置中将 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT 应用程序设置设置为 1,以防止生成多个 VM。
然而,每次我填满那个队列时,都会不分青红皂白地产生多个函数,我的数据库就会崩溃。
如何限制并发操作的数量?
解决方案
The problem ended up being a difference in formatting of host.json in V1 and V2 Functions. Below is the correct configuration (using Microsoft.Azure.WebJobs.Extensions.Storage
at least 3.0.1). The following host.json configures a single function app to process queue messages sequentially.
{
"version":"2.0",
"extensions": {
"queues": {
"batchSize": 1,
"newBatchThreshold": 0
}
}
}
Setting App Setting WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT = 1
restricts a function app from dynamically scaling out beyond one instance.
推荐阅读
- python - Python 库、包、模块
- node.js - 使用 sudo 权限通过 pm2 启动 NodeJS 以访问 SSL 密钥
- python - Selenium driver.get 提供的页面源与浏览器中的实际源不同
- python - 如何获得句子文本中二元组的概率?
- javascript - React 超过最大更新深度 - 为什么只在子组件中?
- node.js - Node.js 执行 js 文件时不返回任何内容
- python - 使用关键字作为函数参数的烧瓶 sqlalchemy 查询
- vue.js - Vue 无法绑定总线事件数据和组件数据
- java - 是否有任何已知的习惯来高效加载 Android ListViews?
- c# - 如何使用 Libre Hardware Monitor 库读取 GPU 传感器