سؤال

My Application spend too many time on Wait method

Environment:

  • .Net 4.0
  • App Platform x86
  • Console app
  • win server 2008 (x64)

I've checked performance by dottrace

Wait is marked by SecuritySafeCriticalAttribute

Please note on Win7 (x64) all works fine. I found nothing, any suggestions are welcome.

Task Processing

private readonly BlockingCollection<TTask> _queue = new BlockingCollection<TTask>();
private Thread _workThread;

public void ProcessTask(TTask task)
{
    _queue.Add(task);
}

private void ProcessTask()
{
    while (_isRun)
    {
        try
        {
            TTask task = _queue.Take();
            if (task.IsNull())
            {
                continue;
            }
            _log.DebugFormat("Sending task: {0}", task);
            DoProcessMessage(task);
        }
        catch (Exception ex)
        {
            _log.Error(ex);
        }
    }
}
هل كانت مفيدة؟

المحلول 2

Solved

Looks like dottrace show the weather. I've checked performance by ANTS Performance Profiler and fixed the issue. Problem was in sql request thru NHibernate

نصائح أخرى

I don't think security attribute affects the speed. Long time on Wait here takes lots of time probably because you access the guarded object (some collection) from multiple threads concurrently and keep the object locked for long time (eg. while your code processes each item in the collection). This is not a proper way to use collection and definitely a bottleneck in your code.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top