Webjob导致ASP.NET核心性能问题

问题描述:

我创建了一个.NET CORE控制台应用程序,并作为连续模式webjob上载到Azure应用程序(ASP.NET Core)。使用webjob运行时,webapp响应API请求的响应非常慢(请求时间上升到几秒)。Webjob导致ASP.NET核心性能问题

WebJob代码

static void Main(string[] args) 
     { 
queueClient.RegisterMessageHandler(
       async (message, token) => 
       { 

        // Process the message      
        // Complete the message so that it is not received again. 
        // This can be done only if the queueClient is opened in ReceiveMode.PeekLock mode. 
        await queueClient.CompleteAsync(message.SystemProperties.LockToken); 


       }, 
       new MessageHandlerOptions(exce => { 
        return Task.CompletedTask; 
       }) 
       { MaxConcurrentCalls = 1, AutoComplete = false }); 
      //Console.ReadKey(); 
      while (true) ; 
    } 

和消息操作花费几秒钟的处理。

从SCM控制台 enter image description here

请求时间 enter image description here

while(true) ;将针的CPU,所以我建议你不要做。

检查队列消息处理例如,对于如何实现信息处理的正确方法:https://github.com/Azure/azure-webjobs-sdk/wiki/Queues

你将不得不改变你的Main到:

static void Main(string[] args) 
{ 
    JobHost host = new JobHost(); 
    host.RunAndBlock(); 
} 

然后你就可以做出一个消息处理程序另一个文件:

public static void ProcessQueueMessage([QueueTrigger("logqueue")] string logMessage, TextWriter logger) 
{ 
    logger.WriteLine(logMessage); 
} 

的3.0.0的Microsoft.Azure.WebJobs库支持的预览版.NE T Standard 2.0,因此可以与.NET Core 2.0项目一起使用。

如果你想自己实现它,你可以检查Webjobs SDK源代码的例子,他们是如何做到这一点:https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.Host/JobHost.cs

+0

我想这个代码是有效的.Net完整的框架,.NET Core不还有WebJob SDK支持。看起来你的答案基于WebJob SDK。使用.NET Core,我们必须手动管理所有内容。 – tssutha

+0

3.0 beta版本与Net Standard 2.0兼容,所以它应该可以工作。 – juunas

+0

我会看看,我还没有将应用程序更新到.Net Core 2.0,但正如我们试验的那样,我们遇到了EF核心2.0的一些问题,等待修复错误。 – tssutha