title: Why goroutine pause for several minutes
body: <p>I have a task written in GO to read .gz files from AWS S3, size of each .gz file will be <strong>20M</strong>.</p>
  
  <p>Each goroutine will download a .gz file from s3 to local disk, then read its content line by line via gzip.NewReader.</p>
  
  <p>When task(goroutine) count exceeds 70, 67 goroutine will finish their operations successfully. But the remain goroutine then will be <strong><em>paused</em></strong> for several minutes. </p>
  
  <p>At the moment it paused, I saw CPU is 100%, and then, CPU will low down to 0.2%(4CPU, 16G Memory) to stay for several minutes.</p>
  
  <p><strong><em>Question</em></strong>: I'm confused that, why goroutines doing nothing at that time with CPU quite low? What may cause this?</p>
  
  <pre><code>Test results:
  60 goroutines, it will finish successfully in 27 seconds;
  70 goroutines, it will finish successfully in 30s;
  80 goroutines, 77 of them will finish successfully in 30s, but the remaining 3 will **pause 4 minutes**, then restart and finish in 10s
  </code></pre>
  
  <p>Code as below:</p>
  
  <p>Main goroutine:</p>
  
  <pre><code>    func main() {
        runtime.GOMAXPROCS(runtime.NumCPU()*2)
        chs := make([]chan string, 70)
        for i:=min; i&lt;max; i++ {
            chs[i] = make(chan string, 1)
            go readobj.Reads3obj(i, chs[i])
        }
        for _, ch := range chs {
          fmt.Println(&lt;-ch)
        }
      }
  </code></pre>
  
  <p>ReadObject:</p>
  
  <pre><code>func Reads3obj(s3KeyName, ch chan string) {
      sess, err := session.NewSession(&amp;aws.Config{
                Region: aws.String("x"),
                Credentials: credentials.NewStaticCredentials("x", "x", "")},)
  
      downloader := s3manager.NewDownloader(sess)
  
      //create a zipFile to download from S3 to local
      zipFile, err := os.Create(zipname)
  
      //download .gz file from S3
      n, err := downloader.Download(zipFile, &amp;s3.GetObjectInput{
          Bucket: aws.String(bucket),
          Key:    aws.String(s3KeyName),
      })
      //create a file reader
      fileReader, err := os.Open(zipFile)
  
      //create a gzip reader      
      gzipReader, err := gzip.NewReader(fileReader)
  
      //create a buffered reader
      buf := bufio.NewReader(gzipReader)
  
      //read zip file line by line
      for line, isPrefix, err := []byte{0}, false, error(nil); len(line) &gt; 0 &amp;&amp; err == nil; {
          line, isPrefix, err = buf.ReadLine()
         //insert line to ES
      }
    }
  </code></pre>
  
  <p>EDITED:
  When it paused, opened file count is quite small, so I think the opened files didn't exceeds most and it won't matters. Because:</p>
  
  <p>The output of <code>ll /proc/PID/fd</code> is</p>
  
  <pre><code>zc@ip-xxx:/proc/18059/fd$ ll
  total 0
  dr-x------ 2 zc zc  0 Dec 26 06:50 ./
  dr-xr-xr-x 9 zc zc  0 Dec 26 06:50 ../
  lrwx------ 1 zc zc 64 Dec 26 06:50 0 -&gt; /dev/pts/0
  lrwx------ 1 zc zc 64 Dec 26 06:50 1 -&gt; /dev/pts/0
  lrwx------ 1 zc zc 64 Dec 26 06:50 12 -&gt; 
  /home/zc/75.gz
  lrwx------ 1 zc zc 64 Dec 26 06:50 2 -&gt; /dev/pts/0
  lrwx------ 1 zc zc 64 Dec 26 06:50 21 -&gt; 
  /home/zc/78.gz
  lrwx------ 1 zc zc 64 Dec 26 06:50 253 -&gt; socket:[76054]
  lrwx------ 1 zc zc 64 Dec 26 06:50 280 -&gt; socket:[77064]
  lrwx------ 1 zc zc 64 Dec 26 06:50 47 -&gt; 
  /home/zc/58.gz
  lrwx------ 1 zc zc 64 Dec 26 06:50 65 -&gt; anon_inode:[eventpoll]
  lrwx------ 1 zc zc 64 Dec 26 06:50 93 -&gt; socket:[75984]
  </code></pre>