Azure 中的 ASP.NET WebApp 使用大量 CPU

Chr*_*_WR 7 azure-app-service-plans azure-web-app-service azure-webapps

We have a long running ASP.NET WebApp in Azure which has no real endpoints exposed – it serves a single functional purpose primarily reading and manipulating database data, effectively a batched, scheduled task, triggered by a timer every 30 seconds. The app runs fine most of the time but we are seeing occasional issues where the CPU load for the app goes close to the maximum for the AppServicePlan, instantaneously rather than gradually, and stops executing any more timer triggers and we cannot find anything explicitly in the executing code to account for it (no signs of deadlocks etc. and all code paths have try/catch so there should be no unhandled exceptions). More often than not we see errors getting a connection to a database but it’s not clear if those are cause or symptoms.

Note, this is the only resource within the AppService Plan. The Azure SQL database is in the same region and whilst utilised by other apps is very lightly used by them and they also exhibit none of the issues seen by the problem app.

It feels like this is infrastructure related but we have been unable to find anything to explain what is happening so if anyone has any suggestions for where we should be looking they would be gratefully received. We have enabled basic Application Insights (not SDK) but other than seeing CPU load spike prior to loss of app response there is little information of interest given our limited knowledge of how to best utilise Insights.

Jas*_*Pan 0

根据您的描述,我想到了两点来解决您的问题。首先,你可以通过代码跟踪你的程序的运行状态,并在你的批量定时任务的开头和结尾放一个日志来记录每次运行的状态。如果可能,记录请求和响应信息以及开始和结束信息。这样可以完整记录你的任务的时间和运行状态。

其次,可以在程序开始操作数据库之前记录日志,以及数据库连接是否成功。最好的情况是能够记录,哪些业务在运行时会触发CPU负载,并跟踪具体的运行情况,以便具体分析是什么原因导致数据库连接失败。

因为您无法重现您的问题,所以您只能猜测问题的原因。如果通过以上两点还是找不到问题出在哪里,那就适当修改一下你的定时器,让程序每5分钟触发一次,而不是30s。