gpt4 book ai didi

.net - Azure 函数未并行运行

转载 作者:行者123 更新时间:2023-12-03 03:45:14 30 4
gpt4 key购买 nike

我在 python 中创建了一个 azure 函数。我通过 C# 调用它,预计会同时发出大约 1000 个请求。我需要这个函数来并行处理这些请求,而不是一个接一个地处理这些请求,但我无法实现这一点。

这是我的测试代码,它并行发送 10 个请求。

static void Main(string[] args)
{
List<string> symbols = new List<string> { "MSFT", "AAPL", "NFLX", "JNJ", "INTC", "GOOG", "AMZN", "FB", "TSLA", "TSM" };
List<string> results = new List<string>();
List<string> urls = new List<string>();
Parallel.ForEach(symbols, (symbol) =>
{
Trace.WriteLine("Getting - " + symbol);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("MY FUNCTION URL");
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
Trace.WriteLine(reader.ReadToEnd());
}
Trace.WriteLine("Finished - " + symbol);
});
Console.ReadKey();

}

我可以看到请求都是一起发送的。但处理是一个接着一个。这是我的 host.json 文件:

{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
},
"extensions": {
"queues": {
"batchSize": 1
},
"http": {
"routePrefix": "api",
"maxOutstandingRequests": 200,
"maxConcurrentRequests": 1
}

}}

据我了解,将“maxConcurrentRequests”设置为 1 会强制函数应用横向扩展并创建多个实例。我尝试将此值设置为 10 和 100,但没有任何作用。

我还尝试将以下配置值添加到函数应用:

FUNCTIONS_WORKER_PROCESS_COUNT = 10。

PYTHON_THREADPOOL_THREAD_COUNT = 32。

这也没有任何区别。

我可以在 azure 分析中看到,这些函数是根据它们的时间戳依次处理的。并且累计时间约为 10 * 单次运行。

我很确定这是一个配置问题,我错过了什么?

谢谢

阿米特

最佳答案

看看这个 documentation其中说

The maximum number of HTTP functions that are executed in parallel.This value allows you to control concurrency, which can help manageresource utilization. For example, you might have an HTTP functionthat uses a large number of system resources (memory/cpu/sockets) suchthat it causes issues when concurrency is too high. Or you might havea function that makes outbound requests to a third-party service, andthose calls need to be rate limited. In these cases, applying athrottle here can help.*The default for a Consumption plan is 100. The default for a Dedicated plan is unbounded (-1).

将其设置为 1,基本上是告诉它不要并行处理请求。如果将其设置为 100,它将尝试一次处理 100 个。如果所需的内存或 CPU 更多,并且队列中仍有更多请求,函数将开始自动扩展(假设您有消耗计划)。

关于.net - Azure 函数未并行运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69470182/

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