【发布时间】:2021-11-26 21:32:16
【问题描述】:
我在 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 * 单次运行。
我很确定这是一个配置问题,我错过了什么?
谢谢
阿米特
【问题讨论】:
-
大胆猜测,但尝试将
extensions.queues.batchSize设置为 10? -
@ErmiyaEskandary extensions.queues.batchSize 用于存储队列设置,并告诉函数一次从队列中检索那么多消息。它对http请求处理没有影响。请参阅文档。 docs.microsoft.com/en-us/azure/azure-functions/…
标签: .net azure parallel-processing azure-functions