Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy C# threads goes idle during the execution?
    primarykey
    data
    text
    <p>I have a scheduler which runs as background thread on application start of an ASP.NET site. User can initiate various tasks (alert emails/file generation etc) which is inserted in a db table. The scheduler will pick the tasks from database and push the items into a stack. Also scheduler has a threadpool running 10 background threads, which will pop task items from the stack and execute it.</p> <p>This is running fine in one web server, but behaving strange in other web server. The threads goes idle for 6-12 seconds with no reason and do nothing even though there are items in the stack. </p> <ul> <li>Using lock() on stack object to make Push &amp; Pop thread safe</li> <li>Tried Thread.Yield() to give yield to cpu to execute other threads, but slowing down the execution and going idle still persists</li> <li>Tried Thread.Sleep(0) to give yield to cpu to execute other threads, but slowing down the execution and going idle still persists</li> <li>Logged entries and exit of all methods to check if something going wrong during the execution, but no luck</li> </ul> <p>My questions:</p> <ol> <li>Is execution of threads in .net in-deterministic?</li> <li>Is it necessary to specify Thread.Yield() or Thread.Sleep(0) to give breathing time to cpu?</li> <li>Why it is behaving differently on boxes with same configuration? Is there any machine/environment specific factors that affect the execution of thread?</li> </ol> <blockquote> <p>UPDATE on May.08.2013</p> </blockquote> <p>There are two boxes in the farm, both are identical in hardware configuration, setup with same software configuration as well Windows 2008 64bit / IIS7. Both webserver has only one site each with same build. Application pools of both site runs on Framework V4.0 on integrated mode. This is a legacy code and no chance since last two years.</p> <p>We tried several iterations, in all cases webserver1 executes without any issues and completes the background work quickly as it was earlier. <strong>BUT webserver2 has significant delay and performing very poor.</strong></p> <p>We tried extensive logging, capturing entries/exit of all methods. The scenario is like this, all threads works fine for 2 seconds and then goes idle for 6-12 seconds, again become live and execute for next 2 seconds and then goes idle again. This behavioral is consistent till the completion of the task. There is no exception, no application termination, no error in application pool/iis log.</p> <p>Any idea ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload