python - 如何在我的 Azure Function App 中实现负载均衡器?

标签 python azure azure-functions

我创建了 Azure 函数,它接受 http 请求并将 json 文件返回到 blob 中。我想知道如何在我的 azure 函数中实现负载均衡器,以防在我的应用程序中,如果有太多请求,它不应该失败或花费太多时间,因为我正在处理 5-10gb 数据。

示例代码:

app = func.FunctionApp()
@app.function_name(name="HttpTrigger1")
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS)
def test_function(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
            "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
            status_code=200
        ) 

最佳答案

感谢@PeterBons的评论。

正如 @PeterBons 提到的,您可以使用 Azure 函数的内置缩放功能。

  • 默认情况下,Azure Functions 会监视应用程序的负载并根据需要自动创建主机实例。
  • 此扩展功能对于处理请求负载非常有用。
  • 如果您的函数应用使用消耗计划,则将根据收到的请求数量动态添加和删除 Functions 主机的实例。

如果是高级或应用服务计划,您可以根据要求扩展资源。

enter image description here

enter image description here

引用文献:

Overview of Hosting Plans

关于python - 如何在我的 Azure Function App 中实现负载均衡器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76554365/

相关文章:

azure - 添加新分片 - Azure Elastics Scale

函数参数列表中未定义 Python "self"

python - NetBeans 6.9 Python 中的 TODO 注释

Python 变长泛型类型

python - Azure Api 和 ChatGPT 的问题 (python)

reactjs - 通过 Azure Function 和 auth0 进行存储帐户应用程序身份验证

python - 生成器表达式和。列表推导

python - 如何安装requirements.txt pip错误->由于OSError : [Errno 2] No such file or directory而无法安装软件包

JavaScript 循环以容纳从 Webhook 接收的已过滤对象数组

Azure 逻辑应用程序需要数小时/数天才能运行 Azure Functions