mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Fix stats collector spinning CPU if no stats are collected
Commitfd0e24b718changed the stats collection loop to use a `sleep()` instead of `time.Tick()` in the for-loop. This change caused a regression in situations where no stats are being collected, or an error is hit in the loop (in which case the loop would `continue`, and the `sleep()` is not hit). This patch puts the sleep at the start of the loop to guarantee it's always hit. This will delay the sampling, which is similar to the behavior beforefd0e24b718. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
		
							parent
							
								
									3d14173a29
								
							
						
					
					
						commit
						481b8e54b4
					
				
					 1 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -91,6 +91,10 @@ func (s *Collector) Run() {
 | 
			
		|||
	var pairs []publishersPair
 | 
			
		||||
 | 
			
		||||
	for {
 | 
			
		||||
		// Put sleep at the start so that it will always be hit,
 | 
			
		||||
		// preventing a tight loop if no stats are collected.
 | 
			
		||||
		time.Sleep(s.interval)
 | 
			
		||||
 | 
			
		||||
		// it does not make sense in the first iteration,
 | 
			
		||||
		// but saves allocations in further iterations
 | 
			
		||||
		pairs = pairs[:0]
 | 
			
		||||
| 
						 | 
				
			
			@ -141,8 +145,6 @@ func (s *Collector) Run() {
 | 
			
		|||
				logrus.Errorf("collecting stats for %s: %v", pair.container.ID, err)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		time.Sleep(s.interval)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue