How can a stream use less than 100% of the time on a wall?

While profiling the application (using dotTrace), I noticed a very strange thing. I used the “wall time” measurement, which theoretically means that all threads will work for the same time.

But this was not true: some streams (in fact, I was most interested in) displayed the total time about 2 times less than others. For example, profiling was performed for 230 seconds, most threads report 230 seconds spent in a thread, but 5 threads show only 100-110 seconds. These are not streaming threads, and they were definitely created and started before profiling began.

What's going on here?

Refresh . I will add additional information, which may or may not be relevant. In the application in question (this is a game server) there are about 20-30 constantly working threads. Most threads follow simple patterns: they check the incoming queue for work and work if there are any. The code for func fun looks something like this:

while(true){
    if(TryDequeueWork()){ // if queue is not empty
        DoWork();         // do whatever is was on top
    }else{
        m_WaitHandle.WaitOne(MaxTimeout); // m_WaitHandle gets signaled when work is added to queue
    }
}

Strings displaying strange times are similar to this, except that they serve several queues, for example:

while(true){
    bool hasAnyWork=false;
    foreach(var queue in m_Queues){
        if(queue.TryDequeueWork()){
            hasAnyWork=true;
            DoWork();
        }
    }
    if(!hasAnyWork){ 
        m_WaitHandle.WaitOne(MaxTimeout); 
    }
}

Strange threads do not do any I / O except maybe logging. Other, not strange streams are also recorded. The time spent waiting WaitHandle is reported in the profiler; in fact, some of the non-weird threads spend almost all of their waiting time (since they never had any work).

8- (VPS-). , .

+3
2

, ?

+1

100% ,

  • , .
  • , cpu (, ) -.

, . Amdahl .

+1

Source: https://habr.com/ru/post/1790978/


All Articles