我有一个时间触发的 Azure 函数,每秒钟运行一次。该函数从 API 服务器读取数据并将其存储到 ADLS。如何优化函数的性能,使其可以进行超过 500 次 API 调用,并在 SECOND 中为每个调用存储每秒数据。
public static void Run([TimerTrigger("*/1 * * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
log.LogInformation($"Execution starts at: {DateTime.Now.ToString("hh.mm.ss.ffffff")}");
try
{
var IDs = GetIDs(); //makes 1 API call to fetch list of IDs
foreach(var i in IDs){
ReadAndWriteData(i); //reads data for each ID from API server and stores in ADLS
}
}
catch (Exception e)
{
log.LogError($"An exception has been raised : {e}");
}
log.LogInformation($"C# Timer trigger function execution ended at: {DateTime.Now}");
}
public static async Task<List<string>> GetIDs(){
//List<string> idList = await Task.Run(()=> ReadIDs()); //makes 1 API call to fetch list of IDs
//return idList;
}
public static async Task ReadAndWriteData(String id){
//var result = await Task.Run(()=> ReadData()); //reads data for each ID from API server
...
// uploads data to ADLS
}
每秒准确获取所有 ID 数据的最佳方法是什么?我尝试了一些并行编程/ TPL 方法,但如果我只使用一个 ID,它仍然可以提供预期的准确性,而不是全部。