0
votes

So I am facing a situation when my project who is deployed on Azure cloud is getting high CPU most of the time it is 100% but after restarting the app, CPU usage goes to 10-15% for a few hours. I did try to use Kudu profiler but it did not help, most of the time it shows that some methods using 40% CPU when total CPU usage is 100%, but they are 2-3% when usage of CPU is low. What a strange thing I noticed is some API controller methods if they don't get correct request BODY throws CGI/502 error, even though it should be throw Null reference exception because the method get the wrong body, the more interesting - to return CGI exception takes about > 2 min instead of 2sec as usually on my web service on local computer. I went from S1 to S2 plan, same stuff, even though works a bit faster but azure insights show same 90-10% CPU usage.

1
Without any code, there's not a lot we can do. You need to figure out what part of your code is the culprit.DavidG
None of the code I looked can't cause 100 % CPU. For now, I am interested in why Null reference exception becomes a CGI exception and takes me > 2min to get a response of itAndrius
Without sharing any code, there might not be much the community can do other than to offer vague suggestions. One suggestion from me would be to see whether you can recreate the issue locally, or to take a look through the AppInsights logs (if you don't have that, I'd add it)Jamie Taylor
I have tried to recreate many times this week. But 100% happens randomly, sometimes on the idle when no request happening, the jump from 15% to 100% goes immediately. And 100% stays at 100%, it looks like some process are stuck, because how can I explain why it is 100% CPU usage even there is no request coming thereAndrius
Its hard to help you without any code. You will have to analyze (i.e. attach remote debugging to your azure application) and then come back with more details. There are millions of reasons why your code causes these peaks, like Memory Leaks and stuffTseng

1 Answers

0
votes

First of all i would suggest you to write a code to get a crash dump of your server, you can refer this link for setting up .

Something like below would help you to write it in powershell.

$dumpFolder = "C:\crash-dumps"

if (!(Test-Path $dumpFolder)) {
    mkdir $dumpFolder | Out-Null
}

$dumpKey = "HKLM:SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps"

if (!(Test-Path $dumpKey)) {
    New-Item -Path $dumpKey | Out-Null
}

$dumpKey = "HKLM:SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe"
New-Item -Path $dumpKey -Force | Out-Null
New-ItemProperty -Path $dumpKey -Name DumpFolder -Value $dumpFolder -PropertyType String -Force | Out-Null
New-ItemProperty -Path $dumpKey -Name DumpCount -Value 3 -PropertyType DWORD -Force | Out-Null
New-ItemProperty -Path $dumpKey -Name DumpType -Value 2 -PropertyType DWORD -Force | Out-Null

$dumpKey = "HKLM:SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\w3wp.exe"

New-Item -Path $dumpKey -Force | Out-Null
New-ItemProperty -Path $dumpKey -Name DumpFolder -Value $dumpFolder -PropertyType String -Force | Out-Null
New-ItemProperty -Path $dumpKey -Name DumpCount -Value 3 -PropertyType DWORD -Force | Out-Null
New-ItemProperty -Path $dumpKey -Name DumpType -Value 2 -PropertyType DWORD -Force | Out-Null

Based on the crash dumps we can easily understand what part is causing issue.

For the similar issue , you can track this request. Also try to degrade your application to V2.0.0 and see if it is still causing the CPU spikes. If yes then we need to look at your code as mentioned in the comments.