Pergunta

I have written a WCF service which is hosted as a windows service in a machine running windows server 2008 R2. My problem is that within 24 hrs of operation the service starts consuming 100% cpu as seen in the task manager. Now, I am trying to get to the bottom of this problem.

I have tried in vain:

  1. Logging for errors in all loops(try,catch etc.) and service methods.
  2. Reading Resource monitor from task manager.
  3. Running performance monitor on my service.
  4. Running database activity monitor in the Microsoft SQL server(to see if any locks are causing issues)

Neither of the approach has yielded a clear understanding of what is causing 100% cpu utilization. Please show me a way in which I can debug this successfully.

Thanks in Advance !!!

Foi útil?

Solução

I ran into this problem a bit last year with the web service basically behaving like it had a memory leak, slowly working it's way to 100% in memory and CPU usage.

One problem we found was that I was that each instance of my ServiceHost obj (one for each request) was using a common shared variable (db connection, I think) it borrowed from the executable program running my web service, which we have running as a Windows service. That shared variable prevented some of the memory from being released. Once we eliminated the shared variable, some of the memory and CPU problems went away.

The other thing we did was make the class used for our ServiceHost iDisposable so that we could put it into a Using statement, which theoretically should unload the object entirely from memory when End Using is hit.

So the combination of those two things made the difference for us, so hopefully, maybe it will work for you.

Another thing you might try is making your ServiceHost a singleton class, or changing your concurrencymode.

<ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Multiple, 
InstanceContextMode:=InstanceContextMode.PerCall)>

In our case, we run multiple and instance our context percall, but you can change the settings and see if your problem goes away.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top