1

Hello I made a game server in c# for a big online game. The only problem is that I get sometimes out of no where 90% cpu usage.

It also got stuck on that 90% when the bug is there it stays on the 90% for ever..

So my question is how can I find the code failure on a simple way because the server is huge. Are there any .net profilers good foor or something like that?

Guus
  • 51
  • 6
  • Visual Studio itself contains a performance profiler *and* load testing project templates. First collect performance counters and events from the event log though. .NET applications provide a *lot* of performance counters that will tell you what is going on – Panagiotis Kanavos May 15 '15 at 12:35
  • 1
    A hint on using profiler with Visual Studio: you can attach to a running process when you see there is high CPU usage. But when you've gathered enough data, remember to NOT select "stop profiling", since that will kill the process. Select Detach from process and the process will continue to run. – Sami Kuhmonen May 15 '15 at 13:06
  • A better way would be to run a load test on a test server and collect metrics using the profiler. This would allow the profiler to collect IO, Database, call and memory metrics. Profiling a system that is close to collapse will bring it down a lot faster and generate flawed results – Panagiotis Kanavos May 15 '15 at 13:09
  • @PanagiotisKanavos Yeah but the cpu bug is so rare that I can't get it on a test server. Because it is called by a player of my game :$ – Guus May 15 '15 at 14:17
  • Troubleshooting this isn't easy. You can load process crash dumps to Visual Studio to see threads, callstacks etc. You can take a crash dump with a program like [Procdump](https://technet.microsoft.com/en-us/sysinternals/dd996900.aspx) then load it in VS as shown in [Use Dump Files to Debug App Crashes and Hangs in Visual Studio](https://msdn.microsoft.com/en-us/library/d5zhxt22.aspx). This won't show you timings though. A single infinite loop can take a core's 100% but won't be obvious in `Parallel Threads` or `Parallel Stacks` – Panagiotis Kanavos May 15 '15 at 14:28
  • The next step is to install Visual Studio's [standalone profiler](https://msdn.microsoft.com/en-us/library/bb385771.aspx) on production and use it to [profile the server from the command line](https://msdn.microsoft.com/en-us/library/ms182401.aspx). You can then load the profile report to VS to see what was going on. – Panagiotis Kanavos May 15 '15 at 14:34

1 Answers1

1

It also got stuck on that 90% when the bug is there it stays on the 90% for ever

That's awesome! You just got handed the holy grail right there my friend!

Simply attach a debugger when it gets in that state and break. Chances are you'll break in the buggy code, if not keep running and breaking. You should get there really quick if it's using 90% of your CPU.

Alternatively run it through VS's profiler and zoom the graph in only the zone with extremely high sustained CPU usage, you'll get a list of functions that use the most time (assuming it's a CPU bound issue, if it's I/O I don't think it will show).

Blindy
  • 65,249
  • 10
  • 91
  • 131
  • A debugger in production? 90% may be slow but at least it won't bring down everything – Panagiotis Kanavos May 15 '15 at 12:37
  • Only if the boss is willing to reimburse customers for the downtime. In the worst case I prefer to take a memory dump just before collapse and use that for debugging elsewhere. At all other times, I use a *lot* of performance monitoring and alerts – Panagiotis Kanavos May 15 '15 at 12:41
  • @PanagiotisKanavos 250 users and you're afraid of reimbursements to users? It's a short time that is needed and all games have downtime. But of course profiling first to see if it tells where the problem is. – Sami Kuhmonen May 15 '15 at 13:00