我在消费计划上运行 azure queue 功能;我的函数启动了一个 FFMpeg 进程,因此非常占用 CPU。当我一次运行队列中少于 100 个项目的函数时,它可以完美运行,azure 可以扩展并为我提供大量服务器,并且所有任务都很快完成。我的问题是,一旦我开始一次执行 300 或 400 多个项目,它开始正常,但一段时间后 CPU 的利用率从 80% 慢慢下降到只有 10% 左右 - 我的功能无法在只有 10% 的 CPU 的情况下及时完成。这可以在下图中看到。有谁知道为什么我的函数创建的实例越多,CPU 使用率就会越低?提前谢谢粑粑
编辑:该函数设置为每个实例一次只运行一个,但是当在host.json中设置为每个实例2或3个并发进程时存在问题
编辑:CPU 下降在 15-20 台服务器上变得明显,并在 60 台左右开始导致故障。之后 CPU 平均下降 8-10%,个人达到 0-3%,服务器数量似乎增加没有限制(如果我在服务器上获得一些 CPU 会更有帮助)
再次感谢,川。
我还在这篇文章的底部添加了功能代码以防万一。
using System.Net;
using System;
using System.Diagnostics;
using System.ComponentModel;
public static void Run(string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed a request: {myQueueItem}");
//Basic Parameters
string ffmpegFile = @"D:\home\site\wwwroot\CommonResources\ffmpeg.exe";
string outputpath = @"D:\home\site\wwwroot\queue-ffmpeg-test\output\";
string reloutputpath = "output/";
string relinputpath = "input/";
string outputfile = "video2.mp4";
string dir = @"D:\home\site\wwwroot\queue-ffmpeg-test\";
//Special Parameters
string videoFile = "1 minute basic.mp4";
string sub = "1 minute sub.ass";
//guid tmp files
// Guid g1=Guid.NewGuid();
// Guid g2=Guid.NewGuid();
// string f1 = g1 + ".mp4";
// string f2 = g2 + ".ass";
string f1 = videoFile;
string f2 = sub;
//guid output - we will now do this at the caller level
string g3 = myQueueItem;
string outputGuid = g3+".mp4";
//get input files
//argument
string tmp = subArg(f1, f2, outputGuid );
//String.Format("-i \"" + @"input/tmp.mp4" + "\" -vf \"ass = '" + sub + "'\" \"" + reloutputpath +outputfile + "\" -y");
log.Info("ffmpeg argument is: "+tmp);
//startprocess parameters
Process process = new Process();
process.StartInfo.FileName = ffmpegFile;
process.StartInfo.Arguments = tmp;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WorkingDirectory = dir;
//output handler
process.OutputDataReceived += new DataReceivedEventHandler(
(s, e) =>
{
log.Info("O: "+e.Data);
}
);
process.ErrorDataReceived += new DataReceivedEventHandler(
(s, e) =>
{
log.Info("E: "+e.Data);
}
);
//start process
process.Start();
log.Info("process started");
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
public static void getFile(string link, string fileName, string dir, string relInputPath){
using (var client = new WebClient()){
client.DownloadFile(link, dir + relInputPath+ fileName);
}
}
public static string subArg(string input1, string input2, string output1){
return String.Format("-i \"" + @"input/" +input1+ "\" -vf \"ass = '" + @"input/"+input2 + "'\" \"" + @"output/" +output1 + "\" -y");
}