Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect current Process/Thread starvation in .NET

I'm working on a soft realtime application which is deployed to many servers that have differing amount of load due to other processes. We've determined that in at least one setup, the performance was hindered by a lack of enough cpu resource.

I understand that on Windows a thread/process can enter the Ready state and that if a cpu is not available it will remain in that state.

I was kind of hoping that there would be a call like Process.Current.ReadyTime that would allow me to inspect and monitor this occurring and raise warnings/errors within the application log. You could take delta's across a known time period and have a threshold for how much time you'd tolerate being in a Ready state for example.

I'm having trouble finding any direct or even indirect way of getting that though. Does anyone have any ideas how to achieve this or something similar?

TL;DR - We're looking for a way for a thread/process to inspect how long it has been in the Ready state (i.e. got work to do but no cpu available)

Thanks,

G-Man

like image 393
G-Man Avatar asked Nov 03 '22 22:11

G-Man


1 Answers

I don't think there's a property like Process.Current.ReadyTime (but maybe there's something that suits your needs in the Windows Performance Counters?), however for threads you can use the ThreadState enumeration.

Ready A state that indicates the thread is waiting to use a processor because no processor is free. The thread is prepared to run on the next available processor.

Running A state that indicates the thread is currently using a processor.

You could create a monitor thread whose job is just to loop over all the threads of your application and log their states or count the time they spend in the ready state.

like image 108
user703016 Avatar answered Nov 09 '22 09:11

user703016