문제

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